From 3800336fe528a2f0cd5b4f3c90ed17fdca0bc0c8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Tue, 18 Feb 2014 12:05:59 +0100 Subject: [PATCH 01/16] smartxml: Refactoring Document.transform This should make handling single transformation transactions more explicit. --- src/smartxml/smartxml.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/smartxml/smartxml.js b/src/smartxml/smartxml.js index ab4d6fb..5cadcd7 100644 --- a/src/smartxml/smartxml.js +++ b/src/smartxml/smartxml.js @@ -476,6 +476,12 @@ $.extend(Document.prototype, Backbone.Events, { transform: function(Transformation, args) { var toret, transformation; + if(!this._currentTransaction) { + return this.transaction(function() { + return this.transform(Transformation, args); + }, this); + } + if(typeof Transformation === 'function') { transformation = new Transformation(this, this, args); } else { @@ -491,11 +497,7 @@ $.extend(Document.prototype, Backbone.Events, { }, function() { if(this._transformationLevel === 1 && !this._undoInProgress) { - if(this._currentTransaction) { - this._currentTransaction.pushTransformation(transformation); - } else { - this.undoStack.push(new Transaction([transformation])); - } + this._currentTransaction.pushTransformation(transformation); } if(!this._undoInProgress && this._transformationLevel === 1) { this.redoStack = []; -- 2.20.1 From 7427515e04e110e91793887b873f5853751c271a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Tue, 18 Feb 2014 12:26:15 +0100 Subject: [PATCH 02/16] smartxml: allow for adding metadata to transaction --- src/smartxml/smartxml.js | 11 ++++++----- src/smartxml/smartxml.test.js | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/smartxml/smartxml.js b/src/smartxml/smartxml.js index 5cadcd7..505ab85 100644 --- a/src/smartxml/smartxml.js +++ b/src/smartxml/smartxml.js @@ -558,11 +558,11 @@ $.extend(Document.prototype, Backbone.Events, { } }, - startTransaction: function() { + startTransaction: function(metadata) { if(this._currentTransaction) { throw new Error('Nested transactions not supported!'); } - this._currentTransaction = new Transaction([]); + this._currentTransaction = new Transaction([], metadata); }, endTransaction: function() { @@ -575,9 +575,9 @@ $.extend(Document.prototype, Backbone.Events, { this._currentTransaction = null; }, - transaction: function(callback, context) { + transaction: function(callback, context, metadata) { var toret; - this.startTransaction(); + this.startTransaction(metadata); toret = callback.call(context); this.endTransaction(); return toret; @@ -608,8 +608,9 @@ $.extend(Document.prototype, Backbone.Events, { } }); -var Transaction = function(transformations) { +var Transaction = function(transformations, metadata) { this.transformations = transformations || []; + this.metadata = metadata; }; $.extend(Transaction.prototype, { pushTransformation: function(transformation) { diff --git a/src/smartxml/smartxml.test.js b/src/smartxml/smartxml.test.js index 491c586..cc2b3cf 100644 --- a/src/smartxml/smartxml.test.js +++ b/src/smartxml/smartxml.test.js @@ -1632,6 +1632,24 @@ describe('smartxml', function() { expect(doc.root.getAttr('smart')).to.equal('1'); expect(doc.root.getAttr('unaware')).to.equal('1'); }); + + it('can have associated metadata', function() { + var doc = getDocumentFromXML('
'), + metadata = Object.create({}); + + doc.registerExtension({document: {transformations: { + test: function() { + this.trigger('change'); + } + }}}); + + doc.startTransaction(metadata); + doc.test(); + doc.endTransaction(); + + var transaction = doc.undoStack[0]; + expect(transaction.metadata).to.equal(metadata); + }); }); describe('Regression tests', function() { -- 2.20.1 From 432da106a4167b35113341fcb7d275ed53671480 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Mon, 24 Feb 2014 10:03:46 +0100 Subject: [PATCH 03/16] editor: Select the whole text of a triple clicked node --- .../modules/documentCanvas/canvas/canvas.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/editor/modules/documentCanvas/canvas/canvas.js b/src/editor/modules/documentCanvas/canvas/canvas.js index f8e9927..428cedc 100644 --- a/src/editor/modules/documentCanvas/canvas/canvas.js +++ b/src/editor/modules/documentCanvas/canvas/canvas.js @@ -91,7 +91,12 @@ $.extend(Canvas.prototype, { this.wrapper.on('click', '[document-node-element], [document-text-element]', function(e) { e.stopPropagation(); - canvas.setCurrentElement(canvas.getDocumentElement(e.currentTarget), {caretTo: false}); + if(e.originalEvent.detail === 3) { + e.preventDefault(); + canvas._moveCaretToTextElement(canvas.getDocumentElement(e.currentTarget), 'whole'); + } else { + canvas.setCurrentElement(canvas.getDocumentElement(e.currentTarget), {caretTo: false}); + } }); this.wrapper.on('paste', function(e) { @@ -289,12 +294,13 @@ $.extend(Canvas.prototype, { range.setStart(node, where); } - var collapseArg = true; - if(where === 'end') { - collapseArg = false; + if(where !== 'whole') { + var collapseArg = true; + if(where === 'end') { + collapseArg = false; + } + range.collapse(collapseArg); } - range.collapse(collapseArg); - var selection = document.getSelection(); selection.removeAllRanges(); -- 2.20.1 From c03ac991e61ce65ed7cb1d910fa19202bec5a088 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Fri, 28 Feb 2014 09:35:02 +0100 Subject: [PATCH 04/16] editor: Dialog improvements - close, cancel events - adding text content - handling empty fields list --- src/editor/modules/data/dialog.html | 2 +- src/editor/modules/data/dialog.js | 21 +++++++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/editor/modules/data/dialog.html b/src/editor/modules/data/dialog.html index 9ac7888..97adf56 100644 --- a/src/editor/modules/data/dialog.html +++ b/src/editor/modules/data/dialog.html @@ -7,6 +7,6 @@ \ No newline at end of file diff --git a/src/editor/modules/data/dialog.js b/src/editor/modules/data/dialog.js index a2c56e2..c32738a 100644 --- a/src/editor/modules/data/dialog.js +++ b/src/editor/modules/data/dialog.js @@ -1,5 +1,6 @@ define(function(require) { + /* globals gettext */ 'use strict'; var _ = require('libs/underscore'), @@ -17,7 +18,7 @@ define(function(require) { template: _.template(dialogTemplate), events: { 'click .save-btn': 'onSave', - 'click .cancel-btn': 'close', + 'click .cancel-btn': 'onCancel', 'click .close': 'close' }, initialize: function() { @@ -25,10 +26,13 @@ define(function(require) { this.actionsDisabled = false; }, show: function() { - this.setElement(this.template(this.options)); + this.setElement(this.template(_.extend({ + submitButtonText: gettext('Submit'), + cancelButtonText: gettext('Cancel') + }, this.options))); var body = this.$('.modal-body'); - this.options.fields.forEach(function(field) { + (this.options.fields || []).forEach(function(field) { var template = fieldTemplates[field.type]; if(!template) { throw new Error('Field type {type} not recognized.'.replace('{type}', field.type)); @@ -38,6 +42,10 @@ define(function(require) { ); }); + if(this.options.text) { + body.append('

' + this.options.text + '

'); + } + this.$el.modal({backdrop: 'static'}); this.$el.modal('show'); this.$('textarea').focus(); @@ -47,7 +55,7 @@ define(function(require) { var view = this, formData = {}; - this.options.fields.forEach(function(field) { + (this.options.fields || []).forEach(function(field) { var widget = view.$('[name=' + field.name +']'); formData[field.name] = widget.val(); }); @@ -58,6 +66,10 @@ define(function(require) { error: function() { view.actionsDisabled = false; view.close(); }, }); }, + onCancel: function() { + this.trigger('cancel'); + this.close(); + }, close: function(e) { if(e) { e.preventDefault(); @@ -66,6 +78,7 @@ define(function(require) { this.$el.modal('hide'); this.$el.remove(); } + this.trigger('close'); }, toggleButtons: function(toggle) { this.$('.btn, button').toggleClass('disabled', !toggle); -- 2.20.1 From 2981e2d70a5e01cea54e6204e5690285a28e2d91 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Fri, 28 Feb 2014 12:35:55 +0100 Subject: [PATCH 05/16] Saving and restoring local draft of a document --- src/editor/modules/data/data.js | 97 +++++++++++++++++++++++++++------ 1 file changed, 80 insertions(+), 17 deletions(-) diff --git a/src/editor/modules/data/data.js b/src/editor/modules/data/data.js index db17955..af8c053 100644 --- a/src/editor/modules/data/data.js +++ b/src/editor/modules/data/data.js @@ -7,7 +7,7 @@ define([ ], function($, Dialog, wlxml, listExtension, logging) { 'use strict'; -/* global gettext, alert */ +/* global gettext, alert, window */ var logger = logging.getLogger('editor.modules.data'), stubDocument = '
' + gettext('This is an empty document.') + '
'; @@ -18,23 +18,51 @@ return function(sandbox) { var document_id = sandbox.getBootstrappedData().document_id; var document_version = sandbox.getBootstrappedData().version; var history = sandbox.getBootstrappedData().history; + var documentDirty = false; + var draftDirty = false; - var wlxmlDocument; - try { - wlxmlDocument = wlxml.WLXMLDocumentFromXML(sandbox.getBootstrappedData().document); - } catch(e) { - logger.exception(e); - alert(gettext('This document contains errors and can\'t be loaded. :(')); // TODO - wlxmlDocument = wlxml.WLXMLDocumentFromXML(stubDocument); - } + var wlxmlDocument, text; - wlxmlDocument.registerExtension(listExtension); - sandbox.getPlugins().forEach(function(plugin) { - if(plugin.documentExtension) { - wlxmlDocument.registerExtension(plugin.documentExtension); + var loadDocument = function(text) { + logger.debug('loading document'); + try { + wlxmlDocument = wlxml.WLXMLDocumentFromXML(text); + } catch(e) { + logger.exception(e); + alert(gettext('This document contains errors and can\'t be loaded. :(')); // TODO + wlxmlDocument = wlxml.WLXMLDocumentFromXML(stubDocument); } - }); - + + wlxmlDocument.registerExtension(listExtension); + sandbox.getPlugins().forEach(function(plugin) { + if(plugin.documentExtension) { + wlxmlDocument.registerExtension(plugin.documentExtension); + } + }); + + var modificationFlag = true; + wlxmlDocument.on('change', function() { + documentDirty = true; + draftDirty = true; + modificationFlag = true; + }); + if(window.localStorage) { + window.setInterval(function() { + if(modificationFlag) { + modificationFlag = false; + return; + } + if(wlxmlDocument && documentDirty && draftDirty) { + logger.debug('Saving draft to local storage.'); + sandbox.publish('savingStarted'); + window.localStorage.setItem(getLocalStorageKey(), wlxmlDocument.toXML()); + sandbox.publish('savingEnded', 'success'); + draftDirty = false; + } + }, sandbox.getConfig().autoSaveInterval || 2500); + } + sandbox.publish('ready'); + }; function readCookie(name) { /* global escape, unescape, document */ @@ -71,10 +99,44 @@ return function(sandbox) { }, }); }; - + + var getLocalStorageKey = function() { + return 'draft-id:' + document_id + '-ver:' + document_version; + }; + + return { start: function() { - sandbox.publish('ready'); + + if(window.localStorage) { + text = window.localStorage.getItem(getLocalStorageKey()); + if(text) { + logger.debug('Local draft exists'); + var dialog = Dialog.create({ + title: gettext('Local draft of a document exists'), + text: gettext('Unsaved local draft of this version of the document exists in your browser. Do you want to load it instead?'), + submitButtonText: gettext('Yes, restore local draft'), + cancelButtonText: gettext('No, use version loaded from the server') + }); + dialog.on('cancel', function() { + logger.debug('Bootstrapped version chosen'); + text = sandbox.getBootstrappedData().document; + + }); + dialog.on('save', function(event) { + logger.debug('Local draft chosen'); + event.success(); + }); + dialog.show(); + dialog.on('close', function() { + loadDocument(text); + }); + } else { + loadDocument(sandbox.getBootstrappedData().document); + } + } else { + loadDocument(sandbox.getBootstrappedData().document); + } }, getDocument: function() { return wlxmlDocument; @@ -165,6 +227,7 @@ return function(sandbox) { document_version = data.version; reloadHistory(); wlxmlDocument.loadXML(data.document); + documentDirty = false; sandbox.publish('documentReverted', data.version); event.success(); }, -- 2.20.1 From 4bec9ecf52da4c7f83bc8bb8c1b7d5ee148e732e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Fri, 28 Feb 2014 13:18:50 +0100 Subject: [PATCH 06/16] Minor refactorization - better naming for options/event for a Dialog object --- src/editor/modules/data/data.js | 12 ++++++------ src/editor/modules/data/dialog.html | 2 +- src/editor/modules/data/dialog.js | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/editor/modules/data/data.js b/src/editor/modules/data/data.js index af8c053..dd81909 100644 --- a/src/editor/modules/data/data.js +++ b/src/editor/modules/data/data.js @@ -115,7 +115,7 @@ return function(sandbox) { var dialog = Dialog.create({ title: gettext('Local draft of a document exists'), text: gettext('Unsaved local draft of this version of the document exists in your browser. Do you want to load it instead?'), - submitButtonText: gettext('Yes, restore local draft'), + executeButtonText: gettext('Yes, restore local draft'), cancelButtonText: gettext('No, use version loaded from the server') }); dialog.on('cancel', function() { @@ -123,7 +123,7 @@ return function(sandbox) { text = sandbox.getBootstrappedData().document; }); - dialog.on('save', function(event) { + dialog.on('execute', function(event) { logger.debug('Local draft chosen'); event.success(); }); @@ -152,10 +152,10 @@ return function(sandbox) { dialog = Dialog.create({ fields: documentSaveForm.fields, title: gettext('Save Document'), - submitButtonText: gettext('Save') + executeButtonText: gettext('Save') }); - dialog.on('save', function(event) { + dialog.on('execute', function(event) { sandbox.publish('savingStarted'); var formData = event.formData; @@ -208,10 +208,10 @@ return function(sandbox) { dialog = Dialog.create({ fields: documentRestoreForm.fields, title: gettext('Restore Version'), - submitButtonText: gettext('Restore') + executeButtonText: gettext('Restore') }); - dialog.on('save', function(event) { + dialog.on('execute', function(event) { var formData = event.formData; formData[documentRestoreForm.version_field_name] = version; sandbox.publish('restoringStarted', {version: version}); diff --git a/src/editor/modules/data/dialog.html b/src/editor/modules/data/dialog.html index 97adf56..80c9fb2 100644 --- a/src/editor/modules/data/dialog.html +++ b/src/editor/modules/data/dialog.html @@ -6,7 +6,7 @@ \ No newline at end of file diff --git a/src/editor/modules/data/dialog.js b/src/editor/modules/data/dialog.js index c32738a..0d4bbd4 100644 --- a/src/editor/modules/data/dialog.js +++ b/src/editor/modules/data/dialog.js @@ -17,7 +17,7 @@ define(function(require) { var DialogView = Backbone.View.extend({ template: _.template(dialogTemplate), events: { - 'click .save-btn': 'onSave', + 'click .execute-btn': 'onExecute', 'click .cancel-btn': 'onCancel', 'click .close': 'close' }, @@ -27,7 +27,7 @@ define(function(require) { }, show: function() { this.setElement(this.template(_.extend({ - submitButtonText: gettext('Submit'), + executeButtonText: gettext('Submit'), cancelButtonText: gettext('Cancel') }, this.options))); @@ -50,7 +50,7 @@ define(function(require) { this.$el.modal('show'); this.$('textarea').focus(); }, - onSave: function(e) { + onExecute: function(e) { e.preventDefault(); var view = this, formData = {}; @@ -60,7 +60,7 @@ define(function(require) { formData[field.name] = widget.val(); }); - this.trigger('save', { + this.trigger('execute', { formData: formData, success: function() { view.actionsDisabled = false; view.close(); }, error: function() { view.actionsDisabled = false; view.close(); }, -- 2.20.1 From 4e455e9d5cb47e44f6428d179c8bd257b991791a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Fri, 28 Feb 2014 14:33:10 +0100 Subject: [PATCH 07/16] editor - differentiate document saved message depending on where the document got saved --- src/editor/modules/data/data.js | 10 +++++----- src/editor/modules/rng/rng.js | 16 ++++++++++++---- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/editor/modules/data/data.js b/src/editor/modules/data/data.js index dd81909..84f0af8 100644 --- a/src/editor/modules/data/data.js +++ b/src/editor/modules/data/data.js @@ -54,9 +54,9 @@ return function(sandbox) { } if(wlxmlDocument && documentDirty && draftDirty) { logger.debug('Saving draft to local storage.'); - sandbox.publish('savingStarted'); + sandbox.publish('savingStarted', 'local'); window.localStorage.setItem(getLocalStorageKey(), wlxmlDocument.toXML()); - sandbox.publish('savingEnded', 'success'); + sandbox.publish('savingEnded', 'success', 'local'); draftDirty = false; } }, sandbox.getConfig().autoSaveInterval || 2500); @@ -156,7 +156,7 @@ return function(sandbox) { }); dialog.on('execute', function(event) { - sandbox.publish('savingStarted'); + sandbox.publish('savingStarted', 'remote'); var formData = event.formData; formData[documentSaveForm.content_field_name] = wlxmlDocument.toXML(); @@ -172,11 +172,11 @@ return function(sandbox) { data: formData, success: function(data) { event.success(); - sandbox.publish('savingEnded', 'success', data.version); + sandbox.publish('savingEnded', 'success', 'remote', data.version); document_version = data.version; reloadHistory(); }, - error: function() {event.error(); sandbox.publish('savingEnded', 'error');} + error: function() {event.error(); sandbox.publish('savingEnded', 'error', 'remote');} }); }); dialog.on('cancel', function() { diff --git a/src/editor/modules/rng/rng.js b/src/editor/modules/rng/rng.js index 665d3a9..801473b 100644 --- a/src/editor/modules/rng/rng.js +++ b/src/editor/modules/rng/rng.js @@ -99,15 +99,23 @@ return function(sandbox) { documentIsDirty = true; }); }, - savingStarted: function() { + savingStarted: function(what) { + var msg = { + remote: gettext('Saving document'), + local: gettext('Saving local copy') + }; sandbox.getModule('mainBar').setCommandEnabled('save', false); - sandbox.getModule('indicator').showMessage(gettext('Saving...')); + sandbox.getModule('indicator').showMessage(msg[what] + '...'); }, - savingEnded: function(status, current_version) { + savingEnded: function(status, what, current_version) { void(status); + var msg = { + remote: gettext('Document saved'), + local: gettext('Local copy saved') + }; documentIsDirty = false; sandbox.getModule('mainBar').setCommandEnabled('save', true); - sandbox.getModule('indicator').clearMessage({message:'Dokument zapisany'}); + sandbox.getModule('indicator').clearMessage({message: msg[what]}); sandbox.getModule('mainBar').setVersion(current_version); }, restoringStarted: function(event) { -- 2.20.1 From 62785e07d962daae8e0a84283ac5da8e2a019595 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Wed, 5 Mar 2014 11:25:38 +0100 Subject: [PATCH 08/16] editor: fix - changes made via source editor now get correctly committed event if tab change didn't occur --- src/editor/modules/rng/rng.js | 4 ++++ src/editor/modules/sourceEditor/sourceEditor.js | 12 ++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/editor/modules/rng/rng.js b/src/editor/modules/rng/rng.js index 801473b..05e0620 100644 --- a/src/editor/modules/rng/rng.js +++ b/src/editor/modules/rng/rng.js @@ -142,6 +142,10 @@ return function(sandbox) { views.mainLayout.setView('topPanel', sandbox.getModule('mainBar').getView()); }, 'cmd.save': function() { + var sourceEditor = sandbox.getModule('sourceEditor'); + if(!sourceEditor.changesCommited()) { + sourceEditor.commitChanges(); + } sandbox.getModule('data').saveDocument(); } }; diff --git a/src/editor/modules/sourceEditor/sourceEditor.js b/src/editor/modules/sourceEditor/sourceEditor.js index 1930939..8f0c833 100644 --- a/src/editor/modules/sourceEditor/sourceEditor.js +++ b/src/editor/modules/sourceEditor/sourceEditor.js @@ -22,10 +22,14 @@ return function(sandbox) { view.onHide = function() { if(documentEditedHere) { - documentEditedHere = false; - wlxmlDocument.loadXML(editor.getValue()); + commitDocument(); } }; + + var commitDocument = function() { + documentEditedHere = false; + wlxmlDocument.loadXML(editor.getValue()); + }; /* globals ace */ var editor = ace.edit(view.find('#rng-sourceEditor-editor')[0]), @@ -53,6 +57,10 @@ return function(sandbox) { documentIsDirty = true; }); }, + changesCommited: function() { + return !documentEditedHere; + }, + commitChanges: commitDocument, getDocument: function() { return editor.getValue(); } -- 2.20.1 From 1cad60261451f283d49cff80d02b819ccd6902dd Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Wed, 5 Mar 2014 11:57:53 +0100 Subject: [PATCH 09/16] editor: Some addtional logging --- src/editor/modules/rng/rng.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/editor/modules/rng/rng.js b/src/editor/modules/rng/rng.js index 05e0620..469d0e4 100644 --- a/src/editor/modules/rng/rng.js +++ b/src/editor/modules/rng/rng.js @@ -2,17 +2,20 @@ define([ 'libs/underscore', 'fnpjs/layout', 'fnpjs/vbox', +'fnpjs/logging/logging', 'views/tabs/tabs', 'libs/text!./mainLayout.html', 'libs/text!./editingLayout.html', 'libs/text!./diffLayout.html', -], function(_, layout, vbox, tabs, mainLayoutTemplate, visualEditingLayoutTemplate, diffLayoutTemplate) { +], function(_, layout, vbox, logging, tabs, mainLayoutTemplate, visualEditingLayoutTemplate, diffLayoutTemplate) { 'use strict'; return function(sandbox) { /* globals gettext */ + + var logger = logging.getLogger('editor.modules.rng'); function addMainTab(title, slug, view) { views.mainTabs.addTab(title, slug, view); @@ -144,6 +147,7 @@ return function(sandbox) { 'cmd.save': function() { var sourceEditor = sandbox.getModule('sourceEditor'); if(!sourceEditor.changesCommited()) { + logger.debug('Source editor has uncommited changes, commiting...'); sourceEditor.commitChanges(); } sandbox.getModule('data').saveDocument(); @@ -280,9 +284,14 @@ return function(sandbox) { sandbox.getModule('data').start(); }, handleEvent: function(moduleName, eventName, args) { + var eventRepr = moduleName + '.' + eventName; if(eventHandlers[moduleName] && eventHandlers[moduleName][eventName]) { + logger.debug('Handling event ' + eventRepr); eventHandlers[moduleName][eventName].apply(eventHandlers, args); + } else { + logger.debug('No event handler for ' + eventRepr); } + } }; }; -- 2.20.1 From 854b444f63582fe4fd9aec7068c2d699b4ddbc01 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Wed, 5 Mar 2014 11:58:18 +0100 Subject: [PATCH 10/16] fnpjs: logging - fixing console handler --- src/fnpjs/logging/handlers.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/fnpjs/logging/handlers.js b/src/fnpjs/logging/handlers.js index f6f0509..5b14be6 100644 --- a/src/fnpjs/logging/handlers.js +++ b/src/fnpjs/logging/handlers.js @@ -6,9 +6,13 @@ define(function() { return { console: function(record) { /* global console */ - var method; + var level = record.level, + method; if(console) { - method = (typeof console[record.level] === 'function') ? record.level : 'log'; + if(level === 'warning') { + level = 'warn'; + } + method = (typeof console[level] === 'function') ? level : 'log'; console[method](record.message); } }, -- 2.20.1 From 3bd06959f2210e5d03b9377400b3b02b18a2e1ae Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Wed, 5 Mar 2014 14:08:55 +0100 Subject: [PATCH 11/16] editor: fix - save local draft after source editor commits changes --- src/editor/modules/data/data.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/editor/modules/data/data.js b/src/editor/modules/data/data.js index 84f0af8..7488390 100644 --- a/src/editor/modules/data/data.js +++ b/src/editor/modules/data/data.js @@ -41,11 +41,14 @@ return function(sandbox) { }); var modificationFlag = true; - wlxmlDocument.on('change', function() { + var handleChange = function() { documentDirty = true; draftDirty = true; modificationFlag = true; - }); + }; + wlxmlDocument.on('change', handleChange); + wlxmlDocument.on('contentSet', handleChange); + if(window.localStorage) { window.setInterval(function() { if(modificationFlag) { -- 2.20.1 From e08ad28198c90ee22657ccc692f4beb161cdf108 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Thu, 6 Mar 2014 16:04:30 +0100 Subject: [PATCH 12/16] removing unused code --- src/editor/modules/documentCanvas/canvas/documentElement.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/editor/modules/documentCanvas/canvas/documentElement.js b/src/editor/modules/documentCanvas/canvas/documentElement.js index 60e79de..115981a 100644 --- a/src/editor/modules/documentCanvas/canvas/documentElement.js +++ b/src/editor/modules/documentCanvas/canvas/documentElement.js @@ -205,9 +205,6 @@ $.extend(DocumentNodeElement.prototype, { return this; }, append: function(params) { - if(params.tag !== 'span') { - this.data('orig-end', undefined); - } return manipulate(this, params, 'append'); }, prepend: function(params) { -- 2.20.1 From 94df6d05a448dd5bd429ef4e4dec14595df2bdae Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Fri, 7 Mar 2014 11:32:37 +0100 Subject: [PATCH 13/16] Stricter linting --- .jshintrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.jshintrc b/.jshintrc index be71a0b..0abcc70 100644 --- a/.jshintrc +++ b/.jshintrc @@ -18,7 +18,7 @@ "plusplus" : false, "quotmark" : true, "undef" : true, - "unused" : true, + "unused" : "strict", "strict" : true, "trailing" : true, "maxparams" : false, -- 2.20.1 From 8b83f8a0f1562b8365ccc7735a6301eba613d28c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Fri, 7 Mar 2014 11:54:38 +0100 Subject: [PATCH 14/16] editor: removing unused code --- src/editor/modules/diffViewer/diffViewer.js | 3 +-- src/editor/modules/documentCanvas/canvas/canvas.test.js | 3 +-- src/editor/modules/documentCanvas/canvas/documentElement.js | 3 +-- src/editor/modules/documentCanvas/commands.js | 3 +-- src/editor/modules/documentCanvas/documentCanvas.js | 3 +-- 5 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/editor/modules/diffViewer/diffViewer.js b/src/editor/modules/diffViewer/diffViewer.js index e792545..573d3a6 100644 --- a/src/editor/modules/diffViewer/diffViewer.js +++ b/src/editor/modules/diffViewer/diffViewer.js @@ -1,9 +1,8 @@ define([ 'libs/jquery', -'libs/underscore', 'views/tabs/tabs', 'libs/text!./diff.html' -], function($, _, tabs, diffTemplateSrc) { +], function($, tabs, diffTemplateSrc) { 'use strict'; diff --git a/src/editor/modules/documentCanvas/canvas/canvas.test.js b/src/editor/modules/documentCanvas/canvas/canvas.test.js index 7a0380a..67f59b6 100644 --- a/src/editor/modules/documentCanvas/canvas/canvas.test.js +++ b/src/editor/modules/documentCanvas/canvas/canvas.test.js @@ -3,10 +3,9 @@ define([ 'libs/chai', 'libs/sinon', 'modules/documentCanvas/canvas/canvas', -'modules/documentCanvas/canvas/documentElement', 'modules/documentCanvas/canvas/utils', 'wlxml/wlxml' -], function($, chai, sinon, canvas, documentElement, utils, wlxml) { +], function($, chai, sinon, canvas, utils, wlxml) { 'use strict'; /* global describe, it, beforeEach, afterEach */ diff --git a/src/editor/modules/documentCanvas/canvas/documentElement.js b/src/editor/modules/documentCanvas/canvas/documentElement.js index 115981a..7f448ba 100644 --- a/src/editor/modules/documentCanvas/canvas/documentElement.js +++ b/src/editor/modules/documentCanvas/canvas/documentElement.js @@ -2,9 +2,8 @@ define([ 'libs/jquery', 'libs/underscore', 'modules/documentCanvas/canvas/utils', -'modules/documentCanvas/canvas/widgets', 'modules/documentCanvas/canvas/wlxmlManagers' -], function($, _, utils, widgets, wlxmlManagers) { +], function($, _, utils, wlxmlManagers) { 'use strict'; /* global Node:false, document:false */ diff --git a/src/editor/modules/documentCanvas/commands.js b/src/editor/modules/documentCanvas/commands.js index 4c52c91..11a874a 100644 --- a/src/editor/modules/documentCanvas/commands.js +++ b/src/editor/modules/documentCanvas/commands.js @@ -1,7 +1,6 @@ define([ -'modules/documentCanvas/canvas/documentElement', './canvas/utils' -], function(documentElement, utils) { +], function(utils) { 'use strict'; diff --git a/src/editor/modules/documentCanvas/documentCanvas.js b/src/editor/modules/documentCanvas/documentCanvas.js index fff7996..da7ac81 100644 --- a/src/editor/modules/documentCanvas/documentCanvas.js +++ b/src/editor/modules/documentCanvas/documentCanvas.js @@ -2,10 +2,9 @@ define([ 'libs/jquery', -'libs/underscore', './canvas/canvas', './commands', -'libs/text!./template.html'], function($, _, canvas3, commands, template) { +'libs/text!./template.html'], function($, canvas3, commands, template) { 'use strict'; -- 2.20.1 From 15f84ff3307f6afdfe57a155637202d7a629ac6a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Fri, 7 Mar 2014 11:49:53 +0100 Subject: [PATCH 15/16] wlxml: removing unused code --- src/wlxml/wlxml.test.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/wlxml/wlxml.test.js b/src/wlxml/wlxml.test.js index d3aa912..c37b21f 100644 --- a/src/wlxml/wlxml.test.js +++ b/src/wlxml/wlxml.test.js @@ -1,8 +1,7 @@ define([ - 'libs/jquery', 'libs/chai', './wlxml.js' -], function($, chai, wlxml) { +], function(chai, wlxml) { 'use strict'; -- 2.20.1 From 49906096d20853e8ce794225e7ce14147bf112ec Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Mon, 10 Mar 2014 11:29:05 +0100 Subject: [PATCH 16/16] wlxml: fix argument passing to transformations registered as wlxml class extensions --- src/wlxml/wlxml.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/wlxml/wlxml.js b/src/wlxml/wlxml.js index 9fb6a98..4f6e356 100644 --- a/src/wlxml/wlxml.js +++ b/src/wlxml/wlxml.js @@ -297,8 +297,9 @@ $.extend(WLXMLDocument.prototype, { registerClassTransformation: function(Transformation, className) { var thisClassTransformations = (this.classTransformations[className] = this.classTransformations[className] || {}); - thisClassTransformations[Transformation.prototype.name] = function(args) { + thisClassTransformations[Transformation.prototype.name] = function() { var nodeInstance = this; + var args = Array.prototype.slice.call(arguments, 0); return nodeInstance.transform(Transformation, args); }; }, -- 2.20.1