This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Using http://requirejs.org/ | |
// loading scripts/misc/person.js | |
require(["misc/person"], function(person) { | |
person.loaded(function(){ | |
alert('dependencies loaded!'); | |
// dependencies loaded, now do something with person | |
}); | |
}); | |
// Inside scripts/misc/person.js |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Our modules.js file | |
var MyApp = MyApp || {}; | |
MyApp.Modules = { | |
common: {}, | |
css: { | |
'farbtastic.css': { type: 'css', varName: 'farbtastic.css', path: 'vendor/farbtastic/farbtastic.css' }, | |
'jquery.gritters.css': { type: 'css', varName: 'jquery.gritters.css', path: 'vendor/jquery.gritter/jquery.gritter.css' }, | |
'jquery.uploadify.css': { type: 'css', varName: 'jquery.uploadify.css', path: 'vendor/uploadify/uploadify.css' }, | |
'jquery.daterangepicker.css': { type: 'css', varName: 'jquery.daterangepicker.css', path: 'vendor/jquery.daterangepicker/ui.daterangepicker.css'} | |
}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script id="person-tmpl-django" class="fix" type="text/x-jquery-tmpl"> | |
<div id="person-${user.id}" class="person"> | |
<strong>${user.name}</strong> | |
[[each(i, c) user.children]] | |
<div class="child">${c.child_name}</div> | |
[[/each]] | |
<span>${user.age}</span> | |
</div> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Object.prototype.attachClass = function(name, o){ | |
this[name] = function(){ | |
if(typeof(this.__init) == 'function'){ | |
this.__init.apply(this, arguments); | |
} | |
}; | |
var new_methods = {}; | |
for(var m in o){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | |
<title>Mustache JS - Template in script block instead of js variable</title> | |
<script type="text/javascript" src="http://github.com/janl/mustache.js/raw/master/mustache.js"></script> | |
</head> | |
<body> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is just an example of a quick way of setting up a new instance with an automatic call to "init" | |
// | |
// Create our attachClass method | |
Object.prototype.attachClass = function(name, o){ | |
this[name] = function(){ | |
if(typeof(this.__init) == 'function'){ | |
this.__init.apply(this, arguments); | |
} | |
} | |
this[name].prototype = o; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Have you ever used Graphael Pie chart (http://g.raphaeljs.com/) and found that when you use a really long legend label, it sometimes goes right off the screen and your chart doesn't align with it? This fixes that. | |
It calculates the graph x to center align the labels with the chart. This only works if you position the pie chart 'south' or 'north' in the 'legendpos' option. | |
*/ | |
var legend = ['Awesome', 'Legend', 'Labels whoa this is long']; | |
legend.sort(function(a, b){ return a.length < b.length; }); | |
var longest_word = legend[0].length; | |
var x_offset = 1.5; // This might be different in your case. Mess around with it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function($){ | |
window.App = { | |
// Site wide options | |
opts = { | |
rootURL: '/' | |
}; | |
// Pass in any options to 'o' and merge it with global defaults |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Template = { | |
// Keep track of used selector text to prevent re-quering the DOM | |
_cache: {}, | |
/** | |
* If you've already called this.draw() on a certain template and don't want to lose your data, you | |
* can append some more data by calling append() | |
* @param {String} tpl The template string that you created with draw(); | |
* @param {Object} data The data you're passing |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Allow for some super easy templating | |
* @param {Object} ctx The context when you pass in an object literal | |
* ------------------------------------------------------------------ | |
* Works like this: | |
* var People = { name: 'bob', age: 123 } | |
* var my_tpl = "Hi, my name is {{ name }} and I'm {{ age }} years old." | |
* my_tpl.template(People); // Outputs: "Hi, my name is bob and I'm 123 years old"; | |
*/ | |
String.prototype.template = function(data){ |