Commit 92328d50 authored by Sindre Sorhus's avatar Sindre Sorhus

Merge pull request #644 from BorisKozo/bugfixes

Marionette - Changes for issue #642 
parents ae3b53c9 4fccfbf2
......@@ -2,9 +2,10 @@
"name": "todomvc-backbone-marionette",
"version": "0.0.0",
"dependencies": {
"todomvc-common": "~0.1.4",
"jquery": "~1.10.2",
"todomvc-common": "~0.1.7",
"underscore": "~1.4.4",
"backbone.localStorage": "~1.1.0",
"backbone.marionette": "~1.0.0-rc6"
"backbone.localStorage": "~1.1.6",
"backbone.marionette": "~1.0.4"
}
}
/**
* Backbone localStorage Adapter
* Version 1.1.0
* Version 1.1.6
*
* https://github.com/jeromegn/Backbone.localStorage
*/
(function (root, factory) {
if (typeof define === "function" && define.amd) {
if (typeof exports === 'object' && root.require) {
module.exports = factory(require("underscore"), require("backbone"));
} else if (typeof define === "function" && define.amd) {
// AMD. Register as an anonymous module.
define(["underscore","backbone"], function(_, Backbone) {
// Use global variables if the locals is undefined.
// Use global variables if the locals are undefined.
return factory(_ || root._, Backbone || root.Backbone);
});
} else {
// RequireJS isn't being used. Assume underscore and backbone is loaded in <script> tags
// RequireJS isn't being used. Assume underscore and backbone are loaded in <script> tags
factory(_, Backbone);
}
}(this, function(_, Backbone) {
......@@ -37,6 +39,9 @@ function guid() {
// with a meaningful name, like the name you'd give a table.
// window.Store is deprectated, use Backbone.LocalStorage instead
Backbone.LocalStorage = window.Store = function(name) {
if( !this.localStorage ) {
throw "Backbone.localStorage: Environment does not support localStorage."
}
this.name = name;
var store = this.localStorage().getItem(this.name);
this.records = (store && store.split(",")) || [];
......@@ -77,7 +82,8 @@ _.extend(Backbone.LocalStorage.prototype, {
// Return the array of all models currently in storage.
findAll: function() {
return _(this.records).chain()
// Lodash removed _#chain in v1.0.0-rc.1
return (_.chain || _)(this.records)
.map(function(id){
return this.jsonData(this.localStorage().getItem(this.name+"-"+id));
}, this)
......@@ -104,17 +110,39 @@ _.extend(Backbone.LocalStorage.prototype, {
// fix for "illegal access" error on Android when JSON.parse is passed null
jsonData: function (data) {
return data && JSON.parse(data);
},
// Clear localStorage for specific collection.
_clear: function() {
var local = this.localStorage(),
itemRe = new RegExp("^" + this.name + "-");
// Remove id-tracking item (e.g., "foo").
local.removeItem(this.name);
// Lodash removed _#chain in v1.0.0-rc.1
// Match all data items (e.g., "foo-ID") and remove.
(_.chain || _)(local).keys()
.filter(function (k) { return itemRe.test(k); })
.each(function (k) { local.removeItem(k); });
this.records.length = 0;
},
// Size of localStorage.
_storageSize: function() {
return this.localStorage().length;
}
});
// localSync delegate to the model or collection's
// *localStorage* property, which should be an instance of `Store`.
// window.Store.sync and Backbone.localSync is deprectated, use Backbone.LocalStorage.sync instead
// window.Store.sync and Backbone.localSync is deprecated, use Backbone.LocalStorage.sync instead
Backbone.LocalStorage.sync = window.Store.sync = Backbone.localSync = function(method, model, options) {
var store = model.localStorage || model.collection.localStorage;
var resp, errorMessage, syncDfd = $.Deferred && $.Deferred(); //If $ is having Deferred - use it.
var resp, errorMessage, syncDfd = Backbone.$.Deferred && Backbone.$.Deferred(); //If $ is having Deferred - use it.
try {
......@@ -134,21 +162,23 @@ Backbone.LocalStorage.sync = window.Store.sync = Backbone.localSync = function(m
}
} catch(error) {
if (error.code === DOMException.QUOTA_EXCEEDED_ERR && window.localStorage.length === 0)
if (error.code === 22 && store._storageSize() === 0)
errorMessage = "Private browsing is unsupported";
else
errorMessage = error.message;
}
if (resp) {
if (options && options.success)
if (options && options.success) {
if (Backbone.VERSION === "0.9.10") {
options.success(model, resp, options);
} else {
options.success(resp);
}
if (syncDfd)
}
if (syncDfd) {
syncDfd.resolve(resp);
}
} else {
errorMessage = errorMessage ? errorMessage
......
......@@ -136,10 +136,6 @@
}
function getFile(file, callback) {
if (!location.host) {
return console.info('Miss the info bar? Run TodoMVC from a server to avoid a cross-origin error.');
}
var xhr = new XMLHttpRequest();
xhr.open('GET', findRoot() + file, true);
......
......@@ -32,7 +32,7 @@ TodoMVC.module('Layout', function (Layout, App, Backbone) {
// Layout Footer View
// ------------------
Layout.Footer = Backbone.Marionette.Layout.extend({
Layout.Footer = Backbone.Marionette.ItemView.extend({
template: '#template-footer',
// UI bindings create cached attributes that
......
......@@ -70,6 +70,7 @@ TodoMVC.module('TodoList.Views', function (Views, App, Backbone, Marionette, $)
}
if (e.which === ESC_KEY) {
this.ui.edit.val(this.model.get('title'));
this.$el.removeClass('editing');
}
}
......
......@@ -53,7 +53,7 @@ TodoMVC.module('TodoList', function (TodoList, App, Backbone, Marionette, $, _)
// Set the filter to show complete or all items
filterItems: function (filter) {
App.vent.trigger('todoList:filter', filter.trim() || '');
App.vent.trigger('todoList:filter', (filter && filter.trim()) || '');
}
});
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment