silverstripe-framework/admin/thirdparty/history-js/scripts/uncompressed/history.adapter.zepto.js

75 lines
1.7 KiB
JavaScript
Raw Normal View History

2011-05-20 05:49:30 +02:00
/**
* History.js Zepto 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){
2011-12-13 10:34:25 +01:00
"use strict";
2011-05-20 05:49:30 +02:00
// Localise Globals
var
History = window.History = window.History||{},
Zepto = window.Zepto;
// 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)
2011-12-13 10:34:25 +01:00
* @param {Element|string} el
* @param {string} event - custom and standard events
* @param {function} callback
* @return {void}
2011-05-20 05:49:30 +02:00
*/
bind: function(el,event,callback){
2011-12-13 10:34:25 +01:00
new Zepto(el).bind(event,callback);
2011-05-20 05:49:30 +02:00
},
/**
* History.Adapter.trigger(el,event)
2011-12-13 10:34:25 +01:00
* @param {Element|string} el
* @param {string} event - custom and standard events
* @return {void}
2011-05-20 05:49:30 +02:00
*/
trigger: function(el,event){
2011-12-13 10:34:25 +01:00
new Zepto(el).trigger(event);
},
/**
* 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){
// Zepto Native
var result = (event && event[key]) || undefined;
// Return
return result;
2011-05-20 05:49:30 +02:00
},
/**
2011-12-13 10:34:25 +01:00
* History.Adapter.onDomLoad(callback)
* @param {function} callback
* @return {void}
2011-05-20 05:49:30 +02:00
*/
onDomLoad: function(callback) {
2011-12-13 10:34:25 +01:00
new Zepto(callback);
2011-05-20 05:49:30 +02:00
}
};
// Try and Initialise History
if ( typeof History.init !== 'undefined' ) {
History.init();
}
})(window);