12345 |
- // -- Sammy.js -- /plugins/sammy.data_location_proxy.js
- // http://sammyjs.org
- // Version: 0.7.6
- // Built: 2014-08-26 10:45:30 +0300
- (function(factory){if(typeof define==="function"&&define.amd){define(["jquery","sammy"],factory)}else{(window.Sammy=window.Sammy||{}).DataLocationProxy=factory(window.jQuery,window.Sammy)}})(function($,Sammy){Sammy.DataLocationProxy=function(app,data_name,href_attribute){this.app=app;this.data_name=data_name||"sammy-location";this.href_attribute=href_attribute};$.extend(Sammy.DataLocationProxy.prototype,{bind:function(){var proxy=this;this.app.$element().bind("setData",function(e,key,value){if(key==proxy.data_name){proxy.app.$element().each(function(){$.data(this,proxy.data_name,value)});proxy.app.trigger("location-changed")}});if(this.href_attribute){this.app.$element().delegate("["+this.href_attribute+"]","click",function(e){e.preventDefault();proxy.setLocation($(this).attr(proxy.href_attribute))})}},unbind:function(){if(this.href_attribute){this.app.$element().undelegate("["+this.href_attribute+"]","click")}this.app.$element().unbind("setData")},getLocation:function(){return this.app.$element().data(this.data_name)||""},setLocation:function(new_location){return this.app.$element().data(this.data_name,new_location)}});return Sammy.DataLocationProxy});
|