mirror of https://github.com/coolaj86/fizzbuzz.git
5 lines
11 KiB
JavaScript
5 lines
11 KiB
JavaScript
|
// -- Sammy -- /sammy.js
|
||
|
// http://code.quirkey.com/sammy
|
||
|
// Version: 0.4.1
|
||
|
// Built: Mon Jan 11 22:02:15 -0500 2010
|
||
|
(function(f){var c="([^/]+)",e=/:([\w\d]+)/g,b=/\?([^#]*)$/,a=decodeURIComponent,d=[];Sammy={};Sammy.VERSION="0.4.1";Sammy.addLogger=function(g){d.push(g)};Sammy.log=function(){var g=f.makeArray(arguments);g.unshift("["+Date()+"]");f.each(d,function(j,h){h.apply(Sammy,g)})};if(typeof window.console!="undefined"){if(f.isFunction(console.log.apply)){Sammy.addLogger(function(){window.console.log.apply(console,arguments)})}else{Sammy.addLogger(function(){window.console.log(arguments)})}}else{if(typeof console!="undefined"){Sammy.addLogger(function(){console.log.apply(console,arguments)})}}Sammy.Object=function(g){this.extend(g)};f.extend(Sammy.Object.prototype,{extend:function(g){f.extend(this,g)},clone:function(g){if(typeof g=="undefined"){g=this}return f.extend({},g)},toHash:function(){var g={};this.each(function(i,h){if(!f.isFunction(h)){g[i]=h}});return g},toHTML:function(){var g="";this.each(function(i,h){if(!f.isFunction(h)){g+="<strong>"+i+"</strong> "+h+"<br />"}});return g},uuid:function(){if(typeof this._uuid=="undefined"||!this._uuid){this._uuid=(new Date()).getTime()+"-"+parseInt(Math.random()*1000)}return this._uuid},each:function(){var i,h,j,g;i=this;if(typeof arguments[0]!="function"){h=arguments[0];j=arguments[1]}else{h=this;j=arguments[0]}g=function(){return j.apply(i,arguments)};f.each(h,g)},keys:function(g){var h=[];for(var i in this){if(!f.isFunction(this[i])||!g){h.push(i)}}return h},join:function(){var h=f.makeArray(arguments);var g=h.shift();return h.join(g)},log:function(){Sammy.log.apply(Sammy,arguments)},toString:function(g){var h=[];this.each(function(j,i){if(!f.isFunction(i)||g){h.push('"'+j+'": '+i.toString())}});return"Sammy.Object: {"+h.join(",")+"}"}});Sammy.HashLocationProxy=function(h,g){this.app=h;if("onhashchange" in window){Sammy.log("native hash change exists, using");this.is_native=true}else{Sammy.log("no native hash change, falling back to polling");this.is_native=false;this._startPolling(g)}};Sammy.HashLocationProxy.prototype={bind:function(){var g=this.app;f(window).bind("hashchange."+this.app.eventNamespace(),function(){g.trigger("location-changed")})},unbind:function(){f(window).die("hashchange."+this.app.eventNamespace())},getLocation:function(){var g=window.location.toString().match(/^[^#]*(#.+)$/);return g?g[1]:""},setLocation:function(g){return window.location=g},_startPolling:function(i){var h=this;if(!Sammy.HashLocationProxy._interval){if(!i){i=10}var g=function(){current_location=h.getLocation();if(!Sammy.HashLocationProxy._last_location||current_location!=Sammy.HashLocationProxy._last_location){setTimeout(function(){f(window).trigger("hashchange")},1)}Sammy.HashLocationProxy._last_location=current_location};g();Sammy.HashLocationProxy._interval=setInterval(g,i);f(window).bind("unload",function(){clearInterval(Sammy.HashLocationProxy._interval)})}}};Sammy.DataLocationProxy=function(h,g){this.app=h;this.data_name=g||"sammy-location"};Sammy.DataLocationProxy.prototype={bind:function(){var g=this;this.app.$element().bind("setData",function(i,h){if(h==g.data_name){g.app.trigger("location-changed")}})},unbind:function(){this.app.$element().die("setData")},getLocation:function(){return this.app.$element().data(this.data_name)},setLocation:function(g){return this.app.$element().data(this.data_name,g)}};Sammy.Application=function(g){var h=this;this.routes={};this.listeners=new Sammy.Object({});this.befores=[];this.namespace=this.uuid();this.context_prototype=function(){Sammy.EventContext.apply(this,arguments)};this.context_prototype.prototype=new Sammy.EventContext();this.each(this.ROUTE_VERBS,function(j,k){this._defineRouteShortcut(k)});if(f.isFunction(g)){g.apply(this,[this])}if(!this.location_proxy){this.location_proxy=new Sammy.HashLocationProxy(h,this.run_interval_every)}if(this.debug){this.bindToAllEvents(function(j,i){h.log(h.toString(),j.cleaned_type,i||{})})}};Sammy.Application.prototype=f.extend({},Sammy.Object.prototype,{ROUTE_VERBS:["get","post","put","delete"],APP_EVENTS:["run","unload","lookup-route","run-route","route-found","event-context-before","event-context-afte
|