SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 282 | Next

Jonathan Snook, Aaron Gustafson, Stuart Langridge, and Dan Webb

"Accelerated DOM Scripting with Ajax, APIs, and Libraries"

The application javascript file (public/javascripts/application.js)
Event.addBehavior({
'a[rel=help]:click' : function() {
Help.openWith(this.href);
return false;
},
'#close_help a:click' : function() {
Help.close();
return false;
},
'#header' : function() {
Loader.initialize(this);
}
});
CHAPTER 9 n A DYNAMIC HELP SYSTEM 211
Help = {
openWith : function(url) {
var urlParts = url.split('#');
var path = urlParts[0], anchor = urlParts[1];
this.request(url, function() {
if ($(document.body).hasClassName('with-help') == false) this.open();
if (anchor && (anchorEl = $(anchor))) {
anchorEl.scrollTo();
anchorEl.addClassName('highlighted');
}
});
},
open : function() {
Help.fx.openHelp.custom(0, 320);
Help.fx.slideBody.custom(30, 350);
},
close : function() {
Help.fx.closeHelp.custom(320, 0);
Help.fx.slideBody.custom(350, 30);
},
request : function(url, callback) {
new Ajax.Updater('help', url, {
method: 'get',
onComplete: callback.bind(this)
});
}
};
Event.onReady(function() {
Help.fx = {
openHelp: new fx.Style('help', 'width', {
onStart : function() {
$(document.body).addClassName('with-help');
}
}),
closeHelp: new fx.Style('help', 'width', {
onComplete : function() {
$(document.body).removeClassName('with-help');
}
}),
slideBody: new fx.Style(document.body, 'margin-right')
};
});
CHAPTER 9 n A DYNAMIC HELP SYSTEM 212
Loader = {
initialize: function(parent) {
this.


Pages:
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293