Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

backbone.stickit

Package Overview
Dependencies
Maintainers
2
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

backbone.stickit - npm Package Compare versions

Comparing version 0.7.0 to 0.8.0

87

backbone.stickit.js

@@ -0,35 +1,38 @@

// Backbone.Stickit v0.8.0, MIT Licensed
// Copyright (c) 2012 The New York Times, CMS Group, Matthew DeLambo <delambo@gmail.com>
(function (factory) {
// Set up Stickit appropriately for the environment. Start with AMD.
if (typeof define === 'function' && define.amd)
define(['underscore', 'backbone'], factory);
if (typeof define === 'function' && define.amd) {
define(['underscore', 'backbone', 'exports'], factory);
}
// Next for Node.js or CommonJS.
else if (typeof exports === 'object')
factory(require('underscore'), require('backbone'));
else if (typeof exports === 'object') {
factory(require('underscore'), require('backbone'), exports);
}
// Finally, as a browser global.
else
factory(_, Backbone);
else {
factory(_, Backbone, {});
}
}(function (_, Backbone) {
}(function (_, Backbone, Stickit) {
// Backbone.Stickit Namespace
// Stickit Namespace
// --------------------------
Backbone.Stickit = {
Stickit._handlers = [];
_handlers: [],
addHandler: function(handlers) {
// Fill-in default values.
handlers = _.map(_.flatten([handlers]), function(handler) {
return _.extend({
updateModel: true,
updateView: true,
updateMethod: 'text'
}, handler);
});
this._handlers = this._handlers.concat(handlers);
}
Stickit.addHandler = function(handlers) {
// Fill-in default values.
handlers = _.map(_.flatten([handlers]), function(handler) {
return _.extend({
updateModel: true,
updateView: true,
updateMethod: 'text'
}, handler);
});
this._handlers = this._handlers.concat(handlers);
};

@@ -40,3 +43,3 @@

_.extend(Backbone.View.prototype, {
Stickit.ViewMixin = {

@@ -56,2 +59,3 @@ // Collection of model event bindings.

}, this);
return;
}

@@ -61,4 +65,4 @@

_.each(this._modelBindings, function(binding, i) {
if (model && binding.model !== model) return false;
if (bindingSelector && binding.config.selector != bindingSelector) return false;
if (model && binding.model !== model) { return; }
if (bindingSelector && binding.config.selector != bindingSelector) return;
destroyFns.push(binding.config._destroy);

@@ -77,3 +81,3 @@ binding.model.off(binding.event, binding.fn);

this.$el.off('.stickit' + (model ? '.' + model.cid : ''));
this.$el.off('.stickit' + (model ? '.' + model.cid : ''), bindingSelector);
},

@@ -95,3 +99,3 @@

var remove = this.remove;
if (!remove.stickitWrapped)
if (!remove.stickitWrapped) {
this.remove = function() {

@@ -103,2 +107,3 @@ var ret = this;

};
}
this.remove.stickitWrapped = true;

@@ -108,7 +113,7 @@ },

// Add a single model binding to the view
addBinding: function(optionalModel, second, binding) {
addBinding: function(optionalModel, second, _binding) {
var $el, options, modelAttr, config, selector,
model = optionalModel || this.model,
namespace = '.stickit.' + model.cid,
binding = binding || {},
binding = _binding || {},
bindId = _.uniqueId();

@@ -148,7 +153,7 @@

config.bindId = bindId;
// Add a reference to the view for handlers of stickitChange events
config.view = this;
options = _.extend({stickitChange:config}, config.setOptions);
// Add a `_destroy` callback to the configuration, in case `destroy`

@@ -195,4 +200,6 @@ // is a named function and we need a unique function when unsticking.

}
});
};
_.extend(Backbone.View.prototype, Stickit.ViewMixin);
// Helpers

@@ -274,3 +281,3 @@ // -------

// were found with the given `binding`.
var getConfiguration = Backbone.Stickit.getConfiguration = function($el, binding) {
var getConfiguration = Stickit.getConfiguration = function($el, binding) {
var handlers = [{

@@ -282,3 +289,3 @@ updateModel: false,

}];
handlers = handlers.concat(_.filter(Backbone.Stickit._handlers, function(handler) {
handlers = handlers.concat(_.filter(Stickit._handlers, function(handler) {
return $el.is(handler.selector);

@@ -375,3 +382,3 @@ }));

Backbone.Stickit.addHandler([{
Stickit.addHandler([{
selector: '[contenteditable="true"]',

@@ -411,3 +418,3 @@ updateMethod: 'html',

var checkbox = Backbone.$(el);
var checked = _.indexOf(val, checkbox.val()) > -1;
var checked = _.contains(val, checkbox.val());
checkbox.prop('checked', checked);

@@ -512,3 +519,3 @@ });

$el.html('');
$el.find('*').remove();

@@ -577,2 +584,8 @@ // The `list` configuration is a function that returns the options list or a string

// Export onto Backbone object
Backbone.Stickit = Stickit;
return Backbone.Stickit;
}));
{
"name": "backbone.stickit",
"description": "Model binding in Backbone style.",
"version": "0.7.0",
"version": "0.8.0",
"author": "Matthew DeLambo <delambo@gmail.com>",

@@ -11,4 +11,5 @@ "repository": {

"main": "backbone.stickit.js",
"dependencies": {
"backbone": "~0.9.0"
"peerDependencies": {
"underscore": ">=1.4.2",
"backbone": ">=0.9.0"
},

@@ -15,0 +16,0 @@ "devDependencies": {

@@ -1,2 +0,2 @@

[-> **Documentation for current/stable release: 0.7.0**](http://nytimes.github.com/backbone.stickit/)
[-> **Documentation for current/stable release: 0.8.0**](http://nytimes.github.com/backbone.stickit/)

@@ -13,3 +13,3 @@ **The following is documentation for the code in master/edge version...**

[download v0.7.0](http://nytimes.github.com/backbone.stickit/downloads/backbone.stickit_0.7.0.zip)
[download v0.8.0](http://nytimes.github.com/backbone.stickit/downloads/backbone.stickit_0.8.0.zip)

@@ -62,3 +62,3 @@ [download master/edge](https://raw.github.com/NYTimes/backbone.stickit/master/backbone.stickit.js)

Adds a single binding to the view, using the given model, or `view.model`, and the given `selector` and `configuration`. It's also possible to pass in a bindings hash as the second parameter.
Adds a single binding to the view, using the given model, or `view.model`, and the given `selector` and `configuration`. It's also possible to pass in a bindings hash as the second parameter. If you use a selector that was already used for a binding, then the old binding will be destroyed before initializing the new binding.

@@ -675,3 +675,3 @@ ```javascript

#### Master
#### 0.8.0

@@ -678,0 +678,0 @@ - **Breaking Change**: Calling `view#stickit` a second time with the same model, will no longer unbind all previously bound bindings associated with that model; instead, it will unbind any duplicate bindings (selectors) found in the given bindings hash (or whatever's in `view.bindings`) before initializing.

@@ -236,2 +236,4 @@ $(document).ready(function() {

equal(model2.get('candy'), 'butterfinger');
testView.remove();
});

@@ -316,11 +318,11 @@

events: function() {
var self = this;
return {
click: function() {
self.clickHandled = true;
}
click: self.clickHandled
};
},
clickHandled: function() {
this.clickHandled = true;
},

@@ -358,2 +360,3 @@

testView.remove();
});

@@ -1422,2 +1425,4 @@

equal(model.get('water'), 'dasina');
testView.remove();
});

@@ -1424,0 +1429,0 @@

@@ -25,11 +25,14 @@ $(document).ready(function() {

equal(_.keys(view.model._events).length, 3);
var events = $._data(view.$el[0], 'events');
ok(events.input.length && events.propertychange.length && events.change.length);
view.unstickit();
equal(_.keys(view.model._events).length, 0);
events = $._data(view.$el[0], 'events');
ok(!events);
});
test('unstickit with selector parameter', 3, function() {
test('unstickit with selector parameter', 4, function() {
model.set({'water':'fountain', 'candy':'skittles', 'album':'rival-dealer'});
model.set({'water':'fountain', 'candy':'skittles', 'album':'rival-dealer', 'state': 'liquid'});
view.model = model;

@@ -40,10 +43,14 @@ view.templateId = 'jst14';

'#test14-2': 'candy',
'#test14-3': 'album'
'#test14-3': 'album',
'#test14-6': 'state'
};
$('#qunit-fixture').html(view.render().el);
equal(_.keys(view.model._events).length, 3);
equal(_.keys(view.model._events).length, 4);
view.unstickit(null, '#test14-1');
equal(_.keys(view.model._events).length, 2);
equal(_.keys(view.model._events).length, 3);
view.$('#test14-6').val('solid').change();
equal(model.get('state'), 'solid');
view.unstickit(null, view.bindings);

@@ -108,2 +115,5 @@ equal(_.keys(view.model._events).length, 0);

var events = $._data(view.$el[0], 'events');
ok(events.input.length == 6 && events.propertychange.length == 6 && events.change.length == 6);
equal(_.keys(model1._events).length, 2);

@@ -116,2 +126,5 @@ equal(_.keys(model2._events).length, 2);

events = $._data(view.$el[0], 'events');
ok(events.input.length == 4 && events.propertychange.length == 4 && events.change.length == 4);
equal(_.keys(model1._events).length, 2);

@@ -124,2 +137,5 @@ equal(_.keys(model2._events).length, 2);

events = $._data(view.$el[0], 'events');
ok(!events);
equal(_.keys(model1._events).length, 0);

@@ -126,0 +142,0 @@ equal(_.keys(model2._events).length, 0);

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc