Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moving our local jquery-related (but otherwise general) utils into a …
…file of their own
- Loading branch information
Showing
4 changed files
with
41 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// slashdot.jquery.js: jquery-related general utilities we wrote ourselves | ||
|
||
function $dom( id ) { | ||
return document.getElementById(id); | ||
} | ||
|
||
jQuery.fn.extend({ | ||
|
||
mapClass: function( map ) { | ||
map['?'] = map['?'] || []; | ||
return this.each(function() { | ||
var unique = {}; | ||
var cl = []; | ||
$.each($.map(this.className.split(/\s+/), function(k){ | ||
return k in map ? map[k] : ('*' in map ? map['*'] : k) | ||
}).concat(map['+']), function(i, k) { | ||
if ( k && !(k in unique) ) { | ||
unique[k] = true; | ||
cl.push(k); | ||
} | ||
}); | ||
this.className = (cl.length ? cl : map['?']).join(' '); | ||
}); | ||
}, | ||
|
||
setClass: function( c1 ) { | ||
return this.each(function() { | ||
this.className = c1 | ||
}); | ||
}, | ||
|
||
toggleClasses: function( c1, c2, force ) { | ||
var map = { '?': force }; | ||
map[c1]=c2; | ||
map[c2]=c1; | ||
return this.mapClass(map); | ||
} | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters