X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=js%2Fbehaviour.js;h=b225ca204f76609385c51aa0af0dc49f0e1213fa;hb=70840a5223cf5c9f31d360946225bbad6a2a1943;hp=d86df13b2c924e361f6088fb08432ece5bade5fb;hpb=73f7e2f83657966f999078917cf9404ec5d65fc3;p=fa-stable.git diff --git a/js/behaviour.js b/js/behaviour.js index d86df13b..b225ca20 100644 --- a/js/behaviour.js +++ b/js/behaviour.js @@ -1,7 +1,7 @@ /* Behaviour v1.1 by Ben Nolan, June 2005. Based largely on the work of Simon Willison (see comments by Simon below). - + Small fixes by J.Dobrowolski for Front Accounting May 2008 Description: Uses css selectors to apply javascript behaviours to enable @@ -53,14 +53,17 @@ var Behaviour = { apply : function(){ for (h=0;sheet=Behaviour.list[h];h++){ for (selector in sheet){ - list = document.getElementsBySelector(selector); + var sels = selector.split(','); + for (var n = 0; n < sels.length; n++) { + list = document.getElementsBySelector(sels[n]); - if (!list){ + if (!list){ continue; - } + } - for (i=0;element=list[i];i++){ + for (i=0;element=list[i];i++){ sheet[selector](element); + } } } } @@ -165,7 +168,9 @@ document.getElementsBySelector = function(selector) { continue; // Skip to next token } // Code to deal with attribute selectors - if (token.match(/^(\w*)\[(\w+)([=~\|\^\$\*]?)=?"?([^\]"]*)"?\]$/)) { +/* Original reg expression /^(\w*)\[(\w+)([=~\|\^\$\*]?)=?"?([^\]"]*)"?\]$/ + was replaced by new RegExp() cuz compressor fault */ + if (token.match(new RegExp('^(\\w*)\\[(\\w+)([=~\\|\\^\\$\\*]?)=?"?([^\\]"]*)"?\\]$'))) { var tagName = RegExp.$1; var attrName = RegExp.$2; var attrOperator = RegExp.$3; @@ -195,19 +200,19 @@ document.getElementsBySelector = function(selector) { checkFunction = function(e) { return (e.getAttribute(attrName) == attrValue); }; break; case '~': // Match one of space seperated words - checkFunction = function(e) { return (e.getAttribute(attrName).match(new RegExp('\\b'+attrValue+'\\b'))); }; + checkFunction = function(e) { var a=e.getAttribute(attrName); return (a && a.match(new RegExp('\\b'+attrValue+'\\b'))); }; break; case '|': // Match start with value followed by optional hyphen - checkFunction = function(e) { return (e.getAttribute(attrName).match(new RegExp('^'+attrValue+'-?'))); }; + checkFunction = function(e) { var a=e.getAttribute(attrName); return (a && a.match(new RegExp('^'+attrValue+'-?'))); }; break; case '^': // Match starts with value - checkFunction = function(e) { return (e.getAttribute(attrName).indexOf(attrValue) == 0); }; + checkFunction = function(e) { var a=e.getAttribute(attrName); return (a && a.indexOf(attrValue) == 0); }; break; case '$': // Match ends with value - fails with "Warning" in Opera 7 - checkFunction = function(e) { return (e.getAttribute(attrName).lastIndexOf(attrValue) == e.getAttribute(attrName).length - attrValue.length); }; + checkFunction = function(e) { var a=e.getAttribute(attrName); return (a && a.lastIndexOf(attrValue) == e.getAttribute(attrName).length - attrValue.length); }; break; - case '*': // Match ends with value - checkFunction = function(e) { return (e.getAttribute(attrName).indexOf(attrValue) > -1); }; + case '*': // Match contains value + checkFunction = function(e) { var a=e.getAttribute(attrName); return (a && a.indexOf(attrValue) > -1); }; break; default : // Just test for existence of attribute