history.adapter.right.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /**
  2. * History.js RightJS 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. document = window.document,
  14. RightJS = window.RightJS,
  15. $ = RightJS.$;
  16. // Check Existence
  17. if ( typeof History.Adapter !== 'undefined' ) {
  18. throw new Error('History.js Adapter has already been loaded...');
  19. }
  20. // Add the Adapter
  21. History.Adapter = {
  22. /**
  23. * History.Adapter.bind(el,event,callback)
  24. * @param {Element|Selector} el
  25. * @param {String} event - custom and standard events
  26. * @param {Function} callback
  27. * @return
  28. */
  29. bind: function(el,event,callback){
  30. $(el).on(event,callback);
  31. },
  32. /**
  33. * History.Adapter.trigger(el,event)
  34. * @param {Element|Selector} el
  35. * @param {String} event - custom and standard events
  36. * @param {Object} extraEventData - a object of extra event data
  37. * @return
  38. */
  39. trigger: function(el,event,extraEventData){
  40. $(el).fire(event,extraEventData);
  41. },
  42. /**
  43. * History.Adapter.extractEventData(key,event,extra)
  44. * @param {String} key - key for the event data to extract
  45. * @param {String} event - custom and standard events
  46. * @return {mixed}
  47. */
  48. extractEventData: function(key,event){
  49. // Right.js Native
  50. // Right.js Custom
  51. var result = (event && event._ && event._[key]) || undefined;
  52. // Return
  53. return result;
  54. },
  55. /**
  56. * History.Adapter.onDomLoad(callback)
  57. * @param {Function} callback
  58. * @return
  59. */
  60. onDomLoad: function(callback) {
  61. $(document).onReady(callback);
  62. }
  63. };
  64. // Try and Initialise History
  65. if ( typeof History.init !== 'undefined' ) {
  66. History.init();
  67. }
  68. })(window);