- Apollo Astronaut Dr. Edgar Mitchell Talks About Life on Other Planets
- The Way We Work: Twitter del.icio.us Hack
- Video of Scalable Theming Session from Drupalcon Boston
- Google's Mapping User Experience; Where have you been?
- The Importance of Strategies, Operating Plans & Success Metrics for NGOs
- vi, Drupal Search, and Playa Del Carmen Retreat
- "Breadcrumb" Definition
- Support the Warrior, Not The War.
- Firefox Tip: Changing Default Browser URL Bar Behavior On Click
- DrupalCamp Seattle Wrap Up
jQuery hook, event message passing, callback function
Submitted by Jonathan Hendler on May 22, 2007 - 9:20pm.
Do you like Drupal's hook functionality?
Maybe this jQuery extension could serve as a way to replicate that that functionality. Currently I use the extension below to allow the extension of existing libraries I've written.
Let's say in your library you write :
One function in a new libarary could write
And a different developer
Here's the code:
Maybe this jQuery extension could serve as a way to replicate that that functionality. Currently I use the extension below to allow the extension of existing libraries I've written.
Let's say in your library you write :
if (confirmed){
$('#css-id').hide(
function(){
$.hookExecute('css_id_hidden');
}
);
}
One function in a new libarary could write
function css_id_hidden(){
alert('Hidden!');
}
And a different developer
function css_id_hidden(){
$('#other-css-id').html('The area is hidden.');
}
Here's the code:
/**
* a jquery hook function
*
* lets a current js function call alternate functions
*
* @todo mimic drupal hook system
*
* @author Jonathan Hendler (jonathan at civicactions dot com)
* @license AGPL http://www.affero.org/oagpl.html
* @version 0.1.0
*
* hookExecute:
*
*/
jQuery.extend({
hookExecute: function (function_name){
//potential security issue
if (eval ('typeof '+function_name+'=="function"')){
eval(function_name+'()');
}else{
//debug
}
}
});
- Jonathan Hendler's blog
- Login or register to post comments
- Delicious
- Digg
- Technorati






It would make more sense to name the function "executeHook". The following is a rewrite that shouldn't have any security issues.
jQuery.extend({executeHook: function(hookName) {
if (typeof window[hookName] == 'function') {
window[hookName]();
} else {
//debug
}
}
});
I've added your work to http://drupal.org/project/semantic_search