Forum
November 2nd, 2014
A
A
A
The forums are currently locked and only available for read only access
Topic RSS
Related Topics
Cellattr and font-style
Tags: cellattr font-style
25/01/2013
13:57
13:57
OlegK
Germany
Member
Members
Forum Posts: 1255
Member Since:
10/08/2009
10/08/2009
Offline
I think that it would be better to rewrite the code which parse cellattr and use
/^\s*(\w+)\s*=\s*([\"|\'])(.*?)\2(.*)/.exec(...)
to parce the results returned from cellattr callback. If one use
var attrStr = cm.cellattr.call(...), matches, name, value, quote, tilteValue, classes = "";
if (attrStr && typeof attrStr === "string") {
// ??? probably one can create object with properties from the attrStr
// and then to use one common function with constructTr to combin the default
// properties with the properties used in cellattr and rowattr.
// Probably one could use $.extend with the most attributes. The exception are
// only class and style attributes which hold multi-values with " " or ";" as separator
while (true) {
// we have to use ? in the construction ([^\2]*?) to have non-greedy (lazy, minimal) matching
// so that we will find the FIRST closing quote instead of default the LAST matching.
matches = /^\s*(\w+)\s*=\s*([\"|\'])(.*?)\2(.*)/.exec(attrStr);
if (matches === null || matches.length < 5) {
... // need nothing to done one need use styleValue, classes and tilteValue
// to generate the results
}
name = matches[1].toLowerCase();
quote = matches[2]; // one should better use the character to quote the value matches[3]
value = matches[3];
attrStr = matches[4];
switch (name) {
case "class":
// if some spetial characters are inside of class value there MUST be escaped
// so we can use any quote characters (' or ") around the call value.
// So we don't need to save quote used in class attribute
if (classes) {
classes += " " + value;
} else {
classes = value;
}
break;
case "title":
tilteValue = value;
break;
case "style":
styleValue += value;
break;
default:
rest += " " + matches[1] + "=" + quote + value + quote;
break;
}
}
}
if (attrStr && typeof attrStr === "string") {
// ??? probably one can create object with properties from the attrStr
// and then to use one common function with constructTr to combin the default
// properties with the properties used in cellattr and rowattr.
// Probably one could use $.extend with the most attributes. The exception are
// only class and style attributes which hold multi-values with " " or ";" as separator
while (true) {
// we have to use ? in the construction ([^\2]*?) to have non-greedy (lazy, minimal) matching
// so that we will find the FIRST closing quote instead of default the LAST matching.
matches = /^\s*(\w+)\s*=\s*([\"|\'])(.*?)\2(.*)/.exec(attrStr);
if (matches === null || matches.length < 5) {
... // need nothing to done one need use styleValue, classes and tilteValue
// to generate the results
}
name = matches[1].toLowerCase();
quote = matches[2]; // one should better use the character to quote the value matches[3]
value = matches[3];
attrStr = matches[4];
switch (name) {
case "class":
// if some spetial characters are inside of class value there MUST be escaped
// so we can use any quote characters (' or ") around the call value.
// So we don't need to save quote used in class attribute
if (classes) {
classes += " " + value;
} else {
classes = value;
}
break;
case "title":
tilteValue = value;
break;
case "style":
styleValue += value;
break;
default:
rest += " " + matches[1] + "=" + quote + value + quote;
break;
}
}
}
It's just an example how the code looks like.
Regards
Oleg
Forum Timezone: Europe/Sofia
Most Users Ever Online: 715
Currently Online:
49 Guest(s)
Top Posters:
OlegK: 1255
markw65: 179
kobruleht: 144
phicarre: 132
YamilBracho: 124
Renso: 118
Member Stats:
Guest Posters: 447
Members: 11373
Moderators: 2
Admins: 1
Forum Stats:
Groups: 1
Forums: 8
Topics: 10592
Posts: 31289
Newest Members:
, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66