Skip to content

Instantly share code, notes, and snippets.

// Backbone.Events
// ---------------
// A module that can be mixed in to *any object* in order to provide it with
// custom events. You may bind with `on` or remove with `off` callback
// functions to an event; `trigger`-ing an event fires all callbacks in
// succession.
//
// var object = {};
// _.extend(object, Backbone.Events);
@basketofsoftkittens
basketofsoftkittens / gist:6108257
Last active December 20, 2015 09:30
singleton for requirejs
_.mixin({
singleton:function(Constructor, scope) {
var instance;
return function(settings) {
var args = _.toArray(arguments);
var wrapper = function(f, params) {
var params = [f];
params = params.concat(args);
return f.bind.apply(f, params);
};
@basketofsoftkittens
basketofsoftkittens / gist:5439156
Last active December 16, 2015 13:08
Interface for storing data from the server and loading into the appropriate model when instantiated
App.Data = Backbone.Model.extend({
})
// on the server when the page loads
$(function(){
require('App',function(){
App.Data.set({
BroModel:{greeting:'BRAAAAHHHHH!!!'}
})
/*for this line in this file
https://github.com/sigurdga/django-jquery-file-upload/blob/master/fileupload/static/js/jquery.fileupload.js#L421
replace that ONE line with
*/
$.each(input.prop('files'),function(file){
if (file) {
@basketofsoftkittens
basketofsoftkittens / gist:3746983
Created September 19, 2012 00:48
use this on product detail page for optimizely.
mint.ui.onWidgetsRendered(function(){
$(".retail.pricing-label").css("text-decoration","line-through");
});
@basketofsoftkittens
basketofsoftkittens / gist:3233246
Created August 2, 2012 03:58
instantiate tabs for starz
<script type="text/javascript">
//<![CDATA[
jQuery(function(){
jQuery('#tabModule').tabs();
if (jQuery.browser.msie && parseInt(jQuery.browser.version, 10) === 7
|| jQuery.browser.msie && parseInt(jQuery.browser.version, 10) === 8) {
jQuery('#tabModule ul li:first-child').css('margin-left', '0');
}
});
//]]>
<!--
After talking to drew, we decided that we would need more precision in creating widgets. Making so many resources private poses the problem of interchangeability. I propose we allow variables in our dependency code to determine which level of resource use when we create the widget. for example -->
<script type="text/mint-customer-something">
{
dependencies:{
model:{
Base: "$mint/src/models/model.Base.js",
Address: "$global/src/model/model.Base.js",
CustomerSomething: "$module/model/model.CustomerSomething.js"
proposed module structure
1. widgets are modules
2. widgets have resources(models/views/controllers) that are owned by the widget (other modules cant access because they are declared privately)
3. widgets can share resources when they are declared and registered via a "manager" (mint.widget,mint.model). shared resources are declared outside of the scope of the module
4. dependency management can include modules which include their resources and their resources dependencies
5. at the mint level, each store has a directory which holds widget overrides for a widget, or a widget resource.
proposed structure:
<<<<<<< HEAD
// recurse through dependencies object
// to count total number objects
loading = _.reduce(deps, function(total, val) {
var count =
_.isFunction(val) ? 1 :
_.isArray(val) ? val.length :
_.isObject(val) ? _.keys(val).length : 0;
return count + total;
}, 0);