Skip to content

Commit

Permalink
jQuerify edit section highlighting
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianheine committed Aug 19, 2011
1 parent eea9121 commit 2c5ba7b
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions lib/scripts/page.js
Expand Up @@ -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');
});
},
Expand Down

0 comments on commit 2c5ba7b

Please sign in to comment.