├── README ├── scripts.coffee ├── scripts.js └── scripts.min.js /README: -------------------------------------------------------------------------------- 1 | JavaScript Application Boilerplate 2 | http://darcyclarke.me/development/javascript-applications-101/ 3 | 4 | Copyright 2011, Darcy Clarke 5 | Do what you want license 6 | -------------------------------------------------------------------------------- /scripts.coffee: -------------------------------------------------------------------------------- 1 | ### 2 | Application 3 | 4 | Inital Code by Darcy Clarke 5 | Converted to CofeeScript by Wes Bos 6 | 7 | Do what you want License! 8 | 9 | ### 10 | App = {} 11 | 12 | # stores array of queued ajax requests 13 | App.queue = [] 14 | 15 | # Store the URL of your application 16 | 17 | App.url = "" 18 | 19 | # stores array of cached objects, primarily DOM selectors 20 | App.cache = {} 21 | 22 | # subscriptions 23 | App.subscriptions = {} 24 | 25 | # pubsub 26 | App.publish = (topic,args) -> 27 | App.subscriptions[topic] and $.each App.subscriptions[topic], -> 28 | this.apply(App, args or []) 29 | return 30 | return 31 | 32 | App.subscribe = (topic, callback) -> 33 | App.subscriptions[topic] = [] unless App.subscriptions[topic] 34 | App.subscriptions[topic].push(callback) 35 | [topic, callback] 36 | 37 | App.unsubscribe = (handle) -> 38 | t = handle[0] 39 | App.subscriptions[t] and $.each App.subscriptions[t], (idx) -> 40 | if this is handle[1] 41 | App.subscriptions[t].splice(idx,1) 42 | return 43 | 44 | ### 45 | Subscriptions 46 | ### 47 | App.subscribe "init", -> 48 | # go nuts 49 | 50 | ### 51 | Events 52 | ### 53 | 54 | # DOM Ready 55 | jQuery ($) -> 56 | App.publish "init" 57 | return 58 | 59 | # Window unload 60 | jQuery(window).unload -> 61 | App.publish "destroy" 62 | return 63 | 64 | # Based on http://paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/ 65 | # Converted to coffeescript by Wes Bos - http://wesbos.com 66 | window.log = -> 67 | log.history = log.history or [] 68 | log.history.push arguments 69 | console.log( Array.prototype.slice.call(arguments) ) if @console 70 | return 71 | -------------------------------------------------------------------------------- /scripts.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * 3 | * JavaScript Application Boilerplate 4 | * http://darcyclarke.me/development/javascript-applications-101/ 5 | * 6 | * Copyright 2011, Darcy Clarke 7 | * Do what you want license 8 | * 9 | */ 10 | 11 | /*************************************************************************/ 12 | /* Application 13 | /*************************************************************************/ 14 | (function(window, undefined){ 15 | 16 | // application object 17 | var App = {}; 18 | 19 | // stores array of queued ajax requests 20 | App.queue = []; 21 | 22 | // stores array of cached objects, primarily DOM selectors 23 | App.cache = {}; 24 | 25 | // stores the url of your application 26 | App.url = ""; 27 | 28 | // subscriptions 29 | App.subscriptions = {}; 30 | 31 | // pubsub 32 | App.publish = function(topic, args){ 33 | App.subscriptions[topic] && $.each(App.subscriptions[topic], function(){ 34 | this.apply(App, args || []); 35 | }); 36 | }; 37 | 38 | App.subscribe = function(topic, callback){ 39 | if(!App.subscriptions[topic]){ 40 | App.subscriptions[topic] = []; 41 | } 42 | App.subscriptions[topic].push(callback); 43 | return [topic, callback]; 44 | }; 45 | 46 | App.unsubscribe = function(handle){ 47 | var t = handle[0]; 48 | App.subscriptions[t] && $.each(App.subscriptions[topic], function(idx){ 49 | if(this == handle[1]){ 50 | App.subscriptions[topic].splice(idx, 1); 51 | } 52 | }); 53 | }; 54 | 55 | /*************************************************************************/ 56 | /* Subscriptions 57 | /*************************************************************************/ 58 | App.subscribe("init", function(){ 59 | 60 | }); 61 | 62 | /*************************************************************************/ 63 | /* Events 64 | /*************************************************************************/ 65 | 66 | // DOM Ready 67 | jQuery(function($){ 68 | App.publish("init"); 69 | }); 70 | 71 | // Window unload 72 | jQuery(window).unload(function(){ 73 | App.publish("destroy"); 74 | }); 75 | 76 | })(window); -------------------------------------------------------------------------------- /scripts.min.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * 3 | * JavaScript APplication Boilerplate 4 | * http://darcyclarke.me/development/javascript-applications-101/ 5 | * 6 | * Copyright 2011, Darcy Clarke 7 | * Do what you want license 8 | * 9 | */ 10 | (function(window, undefined){ 11 | 12 | var App = {}; 13 | App.queue = []; 14 | App.cache = {}; 15 | App.url = ""; 16 | App.subscriptions = {}; 17 | App.publish = function(topic, args){ 18 | App.subscriptions[topic] && $.each(App.subscriptions[topic], function(){ 19 | this.apply(App, args || []); 20 | }); 21 | }; 22 | App.subscribe = function(topic, callback){ 23 | if(!App.subscriptions[topic]){ 24 | App.subscriptions[topic] = []; 25 | } 26 | App.subscriptions[topic].push(callback); 27 | return [topic, callback]; 28 | }; 29 | App.unsubscribe = function(handle){ 30 | var t = handle[0]; 31 | App.subscriptions[t] && $.each(App.subscriptions[t], function(idx){ 32 | if(this == handle[1]){ 33 | App.subscriptions[t].splice(idx, 1); 34 | } 35 | }); 36 | }; 37 | 38 | App.subscribe("init", function(){ 39 | 40 | }); 41 | 42 | jQuery(function($){ 43 | App.publish("init"); 44 | }); 45 | 46 | jQuery(window).unload(function(){ 47 | App.publish("destroy"); 48 | }); 49 | 50 | })(window); --------------------------------------------------------------------------------