diff options
author | Adrian Lang <lang@cosmocode.de> | 2011-08-19 13:03:38 +0200 |
---|---|---|
committer | Adrian Lang <lang@cosmocode.de> | 2011-08-19 13:03:38 +0200 |
commit | 2c5ba7b2e80436af80001c436908217885ce4be3 (patch) | |
tree | e94af1e7fa1bdc716d20cd9d41170ba73a235a8f /lib/scripts | |
parent | eea912192ec9661fe82639db9442586954f6932e (diff) | |
download | rpg-2c5ba7b2e80436af80001c436908217885ce4be3.tar.gz rpg-2c5ba7b2e80436af80001c436908217885ce4be3.tar.bz2 |
jQuerify edit section highlighting
Diffstat (limited to 'lib/scripts')
-rw-r--r-- | lib/scripts/page.js | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/lib/scripts/page.js b/lib/scripts/page.js index f5d84e239..05c5ece20 100644 --- a/lib/scripts/page.js +++ b/lib/scripts/page.js @@ -19,24 +19,20 @@ dw_page = { */ sectionHighlight: function() { jQuery('form.btn_secedit') - .mouseover(function(e){ - var tgt = this.parentNode; - var nr = tgt.className.match(/(\s+|^)editbutton_(\d+)(\s+|$)/)[2]; - do { - tgt = tgt.previousSibling; - } while (tgt !== null && typeof tgt.tagName === 'undefined'); - if (tgt === null) return; - while(typeof tgt.className === 'undefined' || - tgt.className.match('(\\s+|^)sectionedit' + nr + '(\\s+|$)') === null) { - if (typeof tgt.className !== 'undefined') { - jQuery(tgt).addClass('section_highlight'); - } - tgt = (tgt.previousSibling !== null) ? tgt.previousSibling : tgt.parentNode; - } + .mouseover(function(){ + var $tgt = jQuery(this).parent(); + var nr = $tgt.attr('class').match(/(\s+|^)editbutton_(\d+)(\s+|$)/)[2]; - jQuery(tgt).addClass('section_highlight'); + // Walk the DOM tree up (first previous siblings, then parents) + // until boundary element + while($tgt.length > 0 && !$tgt.hasClass('sectionedit' + nr)) { + // $.last gives the DOM-ordered last element: + // prev if present, else parent. + $tgt = $tgt.prev().add($tgt.parent()).last(); + $tgt.addClass('section_highlight'); + } }) - .mouseout(function(e){ + .mouseout(function(){ jQuery('.section_highlight').removeClass('section_highlight'); }); }, |