silverstripe-framework/admin/thirdparty/history-js/scripts/uncompressed/history.adapter.right.js
2011-12-14 16:15:36 +01:00

79 lines
1.8 KiB
JavaScript

/**
* History.js RightJS Adapter
* @author Benjamin Arthur Lupton <contact@balupton.com>
* @copyright 2010-2011 Benjamin Arthur Lupton <contact@balupton.com>
* @license New BSD License <http://creativecommons.org/licenses/BSD/>
*/
// Closure
(function(window,undefined){
"use strict";
// Localise Globals
var
History = window.History = window.History||{},
document = window.document,
RightJS = window.RightJS,
$ = RightJS.$;
// Check Existence
if ( typeof History.Adapter !== 'undefined' ) {
throw new Error('History.js Adapter has already been loaded...');
}
// Add the Adapter
History.Adapter = {
/**
* History.Adapter.bind(el,event,callback)
* @param {Element|Selector} el
* @param {String} event - custom and standard events
* @param {Function} callback
* @return
*/
bind: function(el,event,callback){
$(el).on(event,callback);
},
/**
* History.Adapter.trigger(el,event)
* @param {Element|Selector} el
* @param {String} event - custom and standard events
* @param {Object} extraEventData - a object of extra event data
* @return
*/
trigger: function(el,event,extraEventData){
$(el).fire(event,extraEventData);
},
/**
* History.Adapter.extractEventData(key,event,extra)
* @param {String} key - key for the event data to extract
* @param {String} event - custom and standard events
* @return {mixed}
*/
extractEventData: function(key,event){
// Right.js Native
// Right.js Custom
var result = (event && event._ && event._[key]) || undefined;
// Return
return result;
},
/**
* History.Adapter.onDomLoad(callback)
* @param {Function} callback
* @return
*/
onDomLoad: function(callback) {
$(document).onReady(callback);
}
};
// Try and Initialise History
if ( typeof History.init !== 'undefined' ) {
History.init();
}
})(window);