history.adapter.zepto.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /**
  2. * History.js Zepto Adapter
  3. * @author Benjamin Arthur Lupton <contact@balupton.com>
  4. * @copyright 2010-2011 Benjamin Arthur Lupton <contact@balupton.com>
  5. * @license New BSD License <http://creativecommons.org/licenses/BSD/>
  6. */
  7. // Closure
  8. (function(window,undefined){
  9. "use strict";
  10. // Localise Globals
  11. var
  12. History = window.History = window.History||{},
  13. Zepto = window.Zepto;
  14. // Check Existence
  15. if ( typeof History.Adapter !== 'undefined' ) {
  16. throw new Error('History.js Adapter has already been loaded...');
  17. }
  18. // Add the Adapter
  19. History.Adapter = {
  20. /**
  21. * History.Adapter.bind(el,event,callback)
  22. * @param {Element|string} el
  23. * @param {string} event - custom and standard events
  24. * @param {function} callback
  25. * @return {void}
  26. */
  27. bind: function(el,event,callback){
  28. new Zepto(el).bind(event,callback);
  29. },
  30. /**
  31. * History.Adapter.trigger(el,event)
  32. * @param {Element|string} el
  33. * @param {string} event - custom and standard events
  34. * @return {void}
  35. */
  36. trigger: function(el,event){
  37. new Zepto(el).trigger(event);
  38. },
  39. /**
  40. * History.Adapter.extractEventData(key,event,extra)
  41. * @param {string} key - key for the event data to extract
  42. * @param {string} event - custom and standard events
  43. * @return {mixed}
  44. */
  45. extractEventData: function(key,event){
  46. // Zepto Native
  47. var result = (event && event[key]) || undefined;
  48. // Return
  49. return result;
  50. },
  51. /**
  52. * History.Adapter.onDomLoad(callback)
  53. * @param {function} callback
  54. * @return {void}
  55. */
  56. onDomLoad: function(callback) {
  57. new Zepto(callback);
  58. }
  59. };
  60. // Try and Initialise History
  61. if ( typeof History.init !== 'undefined' ) {
  62. History.init();
  63. }
  64. })(window);