Created
September 5, 2008 17:58
-
-
Save kastner/8998 to your computer and use it in GitHub Desktop.
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
function _parseHTML(html) { | |
var doc = context.focusedWindow.document; | |
var div = doc.createElement( "div" ); | |
div.innerHTML = html; | |
return div; | |
} | |
CmdUtils.CreateCommand({ | |
name:"toggle-these", | |
homepage: "http://metaatem.net/", | |
author: { name: "Erik Kastner", email: "kastner@gmail.com"}, | |
license: "MPL", | |
takes: {"selection": noun_arb_text }, | |
description: "Toggles check boxes in the selection", | |
execute: function(directObject) { | |
var boxes = jQuery(":checkbox", _parseHTML(directObject.html)).map(function() { return ({name: this.name, id: this.id}); }); | |
jQuery(boxes).each(function(box) { | |
var document = context.focusedWindow.document; | |
var b = boxes[box]; | |
var c; | |
if(b.id) { c = jQuery("#" + b.id, document); } | |
else if(b.name) { c = jQuery("input[name='" + b.name + "']", document); } | |
if (c) { c.click(); } | |
}); | |
}, | |
preview: function( pblock, directObject ) { | |
var num = jQuery(":checkbox", _parseHTML(directObject.html)).size(); | |
pblock.innerHTML = "Toggling " + num + " checkboxes"; | |
} | |
}); | |
CmdUtils.CreateCommand({ | |
name:"check-these", | |
homepage: "http://metaatem.net/", | |
author: { name: "Erik Kastner", email: "kastner@gmail.com"}, | |
license: "MPL", | |
takes: {"selection": noun_arb_text }, | |
description: "Checks all the check boxes in the selection", | |
execute: function(directObject) { | |
var boxes = jQuery(":checkbox", _parseHTML(directObject.html)).map(function() { return ({name: this.name, id: this.id}); }); | |
jQuery(boxes).each(function(box) { | |
var document = context.focusedWindow.document; | |
var b = boxes[box]; | |
var c; | |
if(b.id) { c = jQuery("#" + b.id, document); } | |
else if(b.name) { c = jQuery("input[name='" + b.name + "']", document); } | |
if (c) { jQuery(c).attr("checked", true); } | |
}); | |
}, | |
preview: function( pblock, directObject ) { | |
var num = jQuery(":checkbox", _parseHTML(directObject.html)).size(); | |
pblock.innerHTML = "Checking " + num + " checkboxes"; | |
} | |
}); | |
CmdUtils.CreateCommand({ | |
name:"uncheck-these", | |
homepage: "http://metaatem.net/", | |
author: { name: "Erik Kastner", email: "kastner@gmail.com"}, | |
license: "MPL", | |
takes: {"selection": noun_arb_text }, | |
description: "Unchecks all the check boxes in the selection", | |
execute: function(directObject) { | |
var boxes = jQuery(":checkbox", _parseHTML(directObject.html)).map(function() { return ({name: this.name, id: this.id}); }); | |
jQuery(boxes).each(function(box) { | |
var document = context.focusedWindow.document; | |
var b = boxes[box]; | |
var c; | |
if(b.id) { c = jQuery("#" + b.id, document); } | |
else if(b.name) { c = jQuery("input[name='" + b.name + "']", document); } | |
if (c) { jQuery(c).attr("checked", false); } | |
}); | |
}, | |
preview: function( pblock, directObject ) { | |
var num = jQuery(":checkbox", _parseHTML(directObject.html)).size(); | |
pblock.innerHTML = "Unchecking " + num + " checkboxes"; | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment