1
0
Fork 0
forked from 0x2620/oxjs

update css for classic theme

This commit is contained in:
Rolux 2010-07-05 09:09:34 +02:00
commit 9eb96ea54c
8 changed files with 417 additions and 47 deletions

View file

@ -1498,7 +1498,93 @@ Ox.trim = function(str) { // is in jQuery
"foo"
*/
return str.replace(/^\s+|\s+$/g, "");
}
};
Ox.truncate = function(str, len, pad, pos) {
/*
>>> Ox.truncate("anticonstitutionellement", 16, "...", "center")
anticon...lement
*/
var pad = pad || {},
pos = pos || "right",
strlen = str.length,
padlen = pad.length,
left, right;
if (strlen > len) {
if (pos == "left") {
str = pad + str.substr(padlen + strlen - len);
} else if (pos == "center") {
left = Math.ceil((len - padlen) / 2);
right = Math.floor((len - padlen) / 2);
str = str.substr(0, left) + pad + str.substr(-right);
} else if (pos == "right") {
str = str.substr(0, len - padlen) + pad;
}
}
return str;
};
Ox.wordwrap = function(str, len, sep, bal, spa) {
/*
>>> Ox.wordwrap("Anticonstitutionellement, Paris s'eveille", 25, "<br/>"")
Anticonstitutionellement, <br/>Paris s'eveille
>>> Ox.wordwrap("Anticonstitutionellement, Paris s'eveille", 16, "<br/>")
Anticonstitution<br />ellement, Paris <br/>s'eveille
>>> Ox.wordwrap("These are short words", 16, "<br/>", true)
These are <br/>short words
*/
var len = len || 80,
sep = sep || "<br/>",
bal = bal || false,
spa = spa || true,
words = str.split(" "),
lines;
if (bal) {
// balance lines: test if same number of lines
// can be achieved with a shorter line length
lines = Ox.wordwrap(str, len, sep, false).split(sep);
if (lines.length > 1) {
// test shorter line, unless
// that means cutting a word
var max = Ox.max($.map(words, function(word) {
return word.length;
}));
while (len > max) {
len--;
if (Ox.wordwrap(str, len, sep, false).split(sep).length > lines.length) {
len++;
break;
}
}
}
}
lines = [""];
$.each(words, function(i, word) {
if ((lines[lines.length - 1] + word + " ").length <= len + 1) {
// word fits in current line
lines[lines.length - 1] += word + " ";
} else {
if (word.length <= len) {
// word fits in next line
lines.push(word + " ");
} else {
// word is longer than line
var chr = len - lines[lines.length - 1].length;
lines[lines.length - 1] += word.substr(0, chr);
for (var pos = chr; pos < word.length; pos += len) {
lines.push(word.substr(pos, len));
}
lines[lines.length - 1] += " ";
}
}
});
if (!spa) {
lines = $.map(lines, function(line) {
return Ox.trim(line);
});
}
return Ox.trim(lines.join(sep));
};
/*
================================================================================