From 1d931b92398f31cf97610aa252cea12f5c3596ba Mon Sep 17 00:00:00 2001 From: John Martin Date: Tue, 2 Oct 2012 14:10:25 +0100 Subject: [PATCH 1/6] Renamed all methods called `delete` to `remove` This is because Internet Explorer <= 8 has `delete` as a reserved keyword that you cannot name your methods --- src/backend.couchdb.js | 6 +++--- src/backend.elasticsearch.js | 4 ++-- src/backend.memory.js | 4 ++-- test/backend.elasticsearch.test.js | 2 +- test/backend.memory.test.js | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/backend.couchdb.js b/src/backend.couchdb.js index 54f3f88a..1691f756 100755 --- a/src/backend.couchdb.js +++ b/src/backend.couchdb.js @@ -97,7 +97,7 @@ my.__type__ = 'couchdb'; // // @param {Object} id id of object to delete // @return deferred supporting promise API - this.delete = function(_id) { + this.remove = function(_id) { url = self.endpoint; url += '/' + _id; return self._makeRequest({ @@ -475,7 +475,7 @@ _deleteDocument = function (del_doc, dataset) { var cdb = new my.CouchDBWrapper(db_url, view_url); if (view_url.search('_all_docs') !== -1) - return cdb.delete(_id); + return cdb.remove(_id); else { _id = model.get('_id').split('__')[0]; var jqxhr = cdb.get(_id); @@ -484,7 +484,7 @@ _deleteDocument = function (del_doc, dataset) { if (dataset.record_delete) old_doc = dataset.record_delete(del_doc, old_doc); if (_.isNull(del_doc)) - dfd.resolve(cdb.delete(_id)); // XXX is this the right thing to do? + dfd.resolve(cdb.remove(_id)); // XXX is this the right thing to do? else { // couchdb uses _id to identify documents, Backbone models use id. // we should remove it before sending it to the server. diff --git a/src/backend.elasticsearch.js b/src/backend.elasticsearch.js index 1c01c534..dc2d8f06 100644 --- a/src/backend.elasticsearch.js +++ b/src/backend.elasticsearch.js @@ -79,7 +79,7 @@ this.recline.Backend.ElasticSearch = this.recline.Backend.ElasticSearch || {}; // // @param {Object} id id of object to delete // @return deferred supporting promise API - this.delete = function(id) { + this.remove = function(id) { url = this.endpoint; url += '/' + id; return makeRequest({ @@ -219,7 +219,7 @@ this.recline.Backend.ElasticSearch = this.recline.Backend.ElasticSearch || {}; else if (changes.updates.length >0) { return es.upsert(changes.updates[0]); } else if (changes.deletes.length > 0) { - return es.delete(changes.deletes[0].id); + return es.remove(changes.deletes[0].id); } }; diff --git a/src/backend.memory.js b/src/backend.memory.js index ece95bd2..539db80c 100644 --- a/src/backend.memory.js +++ b/src/backend.memory.js @@ -37,7 +37,7 @@ this.recline.Backend.Memory = this.recline.Backend.Memory || {}; }); }; - this.delete = function(doc) { + this.remove = function(doc) { var newdocs = _.reject(self.data, function(internalDoc) { return (doc.id === internalDoc.id); }); @@ -52,7 +52,7 @@ this.recline.Backend.Memory = this.recline.Backend.Memory || {}; self.update(record); }); _.each(changes.deletes, function(record) { - self.delete(record); + self.remove(record); }); dfd.resolve(); return dfd.promise(); diff --git a/test/backend.elasticsearch.test.js b/test/backend.elasticsearch.test.js index 518227ff..f2c35d92 100644 --- a/test/backend.elasticsearch.test.js +++ b/test/backend.elasticsearch.test.js @@ -220,7 +220,7 @@ test("write", function() { equal(data._version, 2); // delete - var jqxhr = backend.delete(rec.id); + var jqxhr = backend.remove(rec.id); jqxhr.done(function(data) { ok(data.ok); rec = null; diff --git a/test/backend.memory.test.js b/test/backend.memory.test.js index 3c858206..ee39a485 100644 --- a/test/backend.memory.test.js +++ b/test/backend.memory.test.js @@ -135,7 +135,7 @@ test('update and delete', function () { equal(data.data[0].x, newVal); // Test Delete - data.delete(doc1); + data.remove(doc1); equal(data.data.length, 5); equal(data.data[0].x, memoryData[1].x); }); From 1e4a2760f93eb3b57638164a34311066cc69840d Mon Sep 17 00:00:00 2001 From: John Martin Date: Tue, 2 Oct 2012 14:20:32 +0100 Subject: [PATCH 2/6] Added fix js file for adding support for ECMA262-5 Array methods for browsers that don\'t support them --- _includes/recline-deps.html | 1 + src/ecma-fixes.js | 67 +++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 src/ecma-fixes.js diff --git a/_includes/recline-deps.html b/_includes/recline-deps.html index 1a72adb7..604f0c58 100644 --- a/_includes/recline-deps.html +++ b/_includes/recline-deps.html @@ -42,6 +42,7 @@ --> + diff --git a/src/ecma-fixes.js b/src/ecma-fixes.js new file mode 100644 index 00000000..de8148be --- /dev/null +++ b/src/ecma-fixes.js @@ -0,0 +1,67 @@ +// This file adds in full array method support in browsers that don't support it +// see: http://stackoverflow.com/questions/2790001/fixing-javascript-array-functions-in-internet-explorer-indexof-foreach-etc + +// Add ECMA262-5 Array methods if not supported natively +if (!('indexOf' in Array.prototype)) { + Array.prototype.indexOf= function(find, i /*opt*/) { + if (i===undefined) i= 0; + if (i<0) i+= this.length; + if (i<0) i= 0; + for (var n= this.length; ithis.length-1) i= this.length-1; + for (i++; i-->0;) /* i++ because from-argument is sadly inclusive */ + if (i in this && this[i]===find) + return i; + return -1; + }; +} +if (!('forEach' in Array.prototype)) { + Array.prototype.forEach= function(action, that /*opt*/) { + for (var i= 0, n= this.length; i Date: Tue, 2 Oct 2012 14:24:49 +0100 Subject: [PATCH 3/6] Re-built dist libs --- dist/recline.dataset.js | 4 +-- dist/recline.js | 76 ++++++++++++++++++++++++++++++++++++++--- 2 files changed, 73 insertions(+), 7 deletions(-) diff --git a/dist/recline.dataset.js b/dist/recline.dataset.js index 05ae6add..86359d90 100644 --- a/dist/recline.dataset.js +++ b/dist/recline.dataset.js @@ -608,7 +608,7 @@ this.recline.Backend.Memory = this.recline.Backend.Memory || {}; }); }; - this.delete = function(doc) { + this.remove = function(doc) { var newdocs = _.reject(self.data, function(internalDoc) { return (doc.id === internalDoc.id); }); @@ -623,7 +623,7 @@ this.recline.Backend.Memory = this.recline.Backend.Memory || {}; self.update(record); }); _.each(changes.deletes, function(record) { - self.delete(record); + self.remove(record); }); dfd.resolve(); return dfd.promise(); diff --git a/dist/recline.js b/dist/recline.js index ed8a7054..7317b043 100644 --- a/dist/recline.js +++ b/dist/recline.js @@ -529,7 +529,7 @@ this.recline.Backend.ElasticSearch = this.recline.Backend.ElasticSearch || {}; // // @param {Object} id id of object to delete // @return deferred supporting promise API - this.delete = function(id) { + this.remove = function(id) { url = this.endpoint; url += '/' + id; return makeRequest({ @@ -669,7 +669,7 @@ this.recline.Backend.ElasticSearch = this.recline.Backend.ElasticSearch || {}; else if (changes.updates.length >0) { return es.upsert(changes.updates[0]); } else if (changes.deletes.length > 0) { - return es.delete(changes.deletes[0].id); + return es.remove(changes.deletes[0].id); } }; @@ -930,7 +930,7 @@ this.recline.Backend.Memory = this.recline.Backend.Memory || {}; }); }; - this.delete = function(doc) { + this.remove = function(doc) { var newdocs = _.reject(self.data, function(internalDoc) { return (doc.id === internalDoc.id); }); @@ -945,7 +945,7 @@ this.recline.Backend.Memory = this.recline.Backend.Memory || {}; self.update(record); }); _.each(changes.deletes, function(record) { - self.delete(record); + self.remove(record); }); dfd.resolve(); return dfd.promise(); @@ -1180,7 +1180,73 @@ my.Transform.mapDocs = function(docs, editFunc) { }; }(this.recline.Data)) -// # Recline Backbone Models +// This file adds in full array method support in browsers that don't support it +// see: http://stackoverflow.com/questions/2790001/fixing-javascript-array-functions-in-internet-explorer-indexof-foreach-etc + +// Add ECMA262-5 Array methods if not supported natively +if (!('indexOf' in Array.prototype)) { + Array.prototype.indexOf= function(find, i /*opt*/) { + if (i===undefined) i= 0; + if (i<0) i+= this.length; + if (i<0) i= 0; + for (var n= this.length; ithis.length-1) i= this.length-1; + for (i++; i-->0;) /* i++ because from-argument is sadly inclusive */ + if (i in this && this[i]===find) + return i; + return -1; + }; +} +if (!('forEach' in Array.prototype)) { + Array.prototype.forEach= function(action, that /*opt*/) { + for (var i= 0, n= this.length; i Date: Tue, 2 Oct 2012 14:36:46 +0100 Subject: [PATCH 4/6] Fixes for Internet Explorer 7 and its strict JSON object modelling --- demos/multiview/app.js | 6 +++--- src/backend.elasticsearch.js | 2 +- src/view.graph.js | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/demos/multiview/app.js b/demos/multiview/app.js index 3bfc12a1..ada770f3 100755 --- a/demos/multiview/app.js +++ b/demos/multiview/app.js @@ -74,21 +74,21 @@ var createExplorer = function(dataset, state) { label: 'Grid', view: new recline.View.SlickGrid({ model: dataset - }), + }) }, { id: 'graph', label: 'Graph', view: new recline.View.Graph({ model: dataset - }), + }) }, { id: 'map', label: 'Map', view: new recline.View.Map({ model: dataset - }), + }) }, { id: 'transform', diff --git a/src/backend.elasticsearch.js b/src/backend.elasticsearch.js index dc2d8f06..9037917f 100644 --- a/src/backend.elasticsearch.js +++ b/src/backend.elasticsearch.js @@ -230,7 +230,7 @@ this.recline.Backend.ElasticSearch = this.recline.Backend.ElasticSearch || {}; var jqxhr = es.query(queryObj); jqxhr.done(function(results) { var out = { - total: results.hits.total, + total: results.hits.total }; out.hits = _.map(results.hits.hits, function(hit) { if (!('id' in hit._source) && hit._id) { diff --git a/src/view.graph.js b/src/view.graph.js index 14d912df..c292a955 100644 --- a/src/view.graph.js +++ b/src/view.graph.js @@ -221,7 +221,7 @@ my.Graph = Backbone.View.extend({ horizontal: true, shadowSize: 0, barWidth: 0.8 - }, + } }, columns: { legend: legend, @@ -242,9 +242,9 @@ my.Graph = Backbone.View.extend({ horizontal: false, shadowSize: 0, barWidth: 0.8 - }, + } }, - grid: { hoverable: true, clickable: true }, + grid: { hoverable: true, clickable: true } }; return optionsPerGraphType[typeId]; }, @@ -424,7 +424,7 @@ my.GraphControls = Backbone.View.extend({ addSeries: function (idx) { var data = _.extend({ seriesIndex: idx, - seriesName: String.fromCharCode(idx + 64 + 1), + seriesName: String.fromCharCode(idx + 64 + 1) }, this.model.toTemplateJSON()); var htmls = Mustache.render(this.templateSeriesEditor, data); From a4e1b53c067a0ec4fa0c9c68fb5d53f9d3778493 Mon Sep 17 00:00:00 2001 From: John Martin Date: Tue, 2 Oct 2012 14:47:43 +0100 Subject: [PATCH 5/6] Fix to make clearfix work in Internet Explorer 7 --- src/view.multiview.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/view.multiview.js b/src/view.multiview.js index c9d462c3..28eb67e7 100644 --- a/src/view.multiview.js +++ b/src/view.multiview.js @@ -98,7 +98,7 @@ my.MultiView = Backbone.View.extend({
\
\ \ -
\ +
\ \
\ -
\
\
\
\ From 91100ca9e4c473c3c950a642a3490f05178842ea Mon Sep 17 00:00:00 2001 From: John Martin Date: Tue, 2 Oct 2012 14:49:20 +0100 Subject: [PATCH 6/6] Rebuilt dist --- dist/recline.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/dist/recline.js b/dist/recline.js index 7317b043..a0bbbd77 100644 --- a/dist/recline.js +++ b/dist/recline.js @@ -680,7 +680,7 @@ this.recline.Backend.ElasticSearch = this.recline.Backend.ElasticSearch || {}; var jqxhr = es.query(queryObj); jqxhr.done(function(results) { var out = { - total: results.hits.total, + total: results.hits.total }; out.hits = _.map(results.hits.hits, function(hit) { if (!('id' in hit._source) && hit._id) { @@ -2040,7 +2040,7 @@ my.Graph = Backbone.View.extend({ horizontal: true, shadowSize: 0, barWidth: 0.8 - }, + } }, columns: { legend: legend, @@ -2061,9 +2061,9 @@ my.Graph = Backbone.View.extend({ horizontal: false, shadowSize: 0, barWidth: 0.8 - }, + } }, - grid: { hoverable: true, clickable: true }, + grid: { hoverable: true, clickable: true } }; return optionsPerGraphType[typeId]; }, @@ -2243,7 +2243,7 @@ my.GraphControls = Backbone.View.extend({ addSeries: function (idx) { var data = _.extend({ seriesIndex: idx, - seriesName: String.fromCharCode(idx + 64 + 1), + seriesName: String.fromCharCode(idx + 64 + 1) }, this.model.toTemplateJSON()); var htmls = Mustache.render(this.templateSeriesEditor, data); @@ -3249,7 +3249,7 @@ my.MultiView = Backbone.View.extend({
\
\ \ -
\ +
\ \
\ -
\
\
\
\