diff --git a/footnotes/dialogs/footnotes.js b/footnotes/dialogs/footnotes.js index 1fc07d0..739596b 100644 --- a/footnotes/dialogs/footnotes.js +++ b/footnotes/dialogs/footnotes.js @@ -10,39 +10,39 @@ CKEDITOR.dialog.add( 'footnotesDialog', function( editor ) { return { editor_name: false, - // Basic properties of the dialog window: title, minimum size. - title: 'Manage Footnotes', - minWidth: 400, - minHeight: 200, + // Basic properties of the dialog window: title, minimum size. + title: 'Manage Footnotes', + minWidth: 400, + minHeight: 200, footnotes_el: false, - // Dialog window contents definition. - contents: [ - { - // Definition of the Basic Settings dialog tab (page). - id: 'tab-basic', - label: 'Basic Settings', - - // The tab contents. - elements: [ - { - // Text input field for the footnotes text. - type: 'textarea', - id: 'new_footnote', + // Dialog window contents definition. + contents: [ + { + // Definition of the Basic Settings dialog tab (page). + id: 'tab-basic', + label: 'Basic Settings', + + // The tab contents. + elements: [ + { + // Text input field for the footnotes text. + type: 'textarea', + id: 'new_footnote', 'class': 'footnote_text', - label: 'New footnote:', + label: 'New footnote:', inputStyle: 'height: 100px', - }, - { - // Text input field for the footnotes title (explanation). - type: 'text', - id: 'footnote_id', - name: 'footnote_id', - label: 'No existing footnotes', + }, + { + // Text input field for the footnotes title (explanation). + type: 'text', + id: 'footnote_id', + name: 'footnote_id', + label: 'No existing footnotes', - // Called by the main setupContent call on dialog initialization. - setup: function( element ) { + // Called by the main setupContent call on dialog initialization. + setup: function( element ) { var dialog = this.getDialog(); $el = jQuery('#' + this.domId); @@ -76,14 +76,14 @@ CKEDITOR.dialog.add( 'footnotesDialog', function( editor ) { } else { $el.children('div').css('display', 'none'); } - } - } - ] - }, - ], - - // Invoked when the dialog is loaded. - onShow: function() { + } + } + ] + }, + ], + + // Invoked when the dialog is loaded. + onShow: function() { this.setupContent(); var dialog = this; @@ -120,16 +120,18 @@ CKEDITOR.dialog.add( 'footnotesDialog', function( editor ) { return true; }); - }, + }, - // This method is invoked once a user clicks the OK button, confirming the dialog. - onOk: function() { + // This method is invoked once a user clicks the OK button, confirming the dialog. + onOk: function() { var dialog = this; var footnote_editor = CKEDITOR.instances[dialog.editor_name]; - var footnote_id = dialog.getValueOf('tab-basic', 'footnote_id'); var footnote_data = footnote_editor.getData(); footnote_editor.destroy(); + var footnote_id = dialog.getValueOf('tab-basic', 'footnote_id'); + var footnote_data = footnote_editor.getData(); + footnote_editor.destroy(); - editor.fire('saveSnapshot'); + //editor.fire('saveSnapshot'); if (footnote_id == '') { // No existing id selected, check for new footnote: @@ -146,6 +148,12 @@ CKEDITOR.dialog.add( 'footnotesDialog', function( editor ) { } // Destroy the editor so it's rebuilt properly next time: return; - }, onCancel: function() { var dialog = this; var footnote_editor = CKEDITOR.instances[dialog.editor_name]; footnote_editor.destroy(); } - }; + }, + + onCancel: function() { + var dialog = this; + var footnote_editor = CKEDITOR.instances[dialog.editor_name]; + footnote_editor.destroy(); + } + }; }); diff --git a/footnotes/plugin.js b/footnotes/plugin.js index 657ee37..1327c03 100644 --- a/footnotes/plugin.js +++ b/footnotes/plugin.js @@ -10,11 +10,11 @@ CKEDITOR.plugins.add( 'footnotes', { footnote_ids: [], requires: 'widget', - icons: 'footnotes', + icons: 'footnotes', - // The plugin initialization logic goes inside this method. - init: function(editor) { + // The plugin initialization logic goes inside this method. + init: function(editor) { // Allow `cite` to be editable: CKEDITOR.dtd.$editable['cite'] = 1; @@ -24,8 +24,13 @@ CKEDITOR.plugins.add( 'footnotes', { var $this = this; - // Force a reorder on startup to make sure all vars are set: (e.g. footnotes store) - editor.on('instanceReady', function(evt) { $this.reorderMarkers(editor); + editor.on('saveSnapshot', function(evt) { + console.log('saveSnapshot'); + }); + + // Force a reorder on startup to make sure all vars are set: (e.g. footnotes store): + editor.on('instanceReady', function(evt) { + $this.reorderMarkers(editor); }); // Add the reorder change event: @@ -69,58 +74,58 @@ CKEDITOR.plugins.add( 'footnotes', { } // Register the footnotes widget. - editor.widgets.add('footnotes', { + editor.widgets.add('footnotes', { - // Minimum HTML which is required by this widget to work. - requiredContent: 'section(footnotes)', + // Minimum HTML which is required by this widget to work. + requiredContent: 'section(footnotes)', - // Check the elements that need to be converted to widgets. - upcast: function(element) { - return element.name == 'section' && element.hasClass('footnotes'); - }, + // Check the elements that need to be converted to widgets. + upcast: function(element) { + return element.name == 'section' && element.hasClass('footnotes'); + }, editables: def - }); + }); - // Register the footnotemarker widget. - editor.widgets.add('footnotemarker', { + // Register the footnotemarker widget. + editor.widgets.add('footnotemarker', { - // Minimum HTML which is required by this widget to work. - requiredContent: 'sup[data-footnote-id]', + // Minimum HTML which is required by this widget to work. + requiredContent: 'sup[data-footnote-id]', - // Check the elements that need to be converted to widgets. - upcast: function(element) { - return element.name == 'sup' && element.attributes['data-footnote-id'] != 'undefined'; - }, - }); + // Check the elements that need to be converted to widgets. + upcast: function(element) { + return element.name == 'sup' && element.attributes['data-footnote-id'] != 'undefined'; + }, + }); - // Define an editor command that opens our dialog. - editor.addCommand('footnotes', new CKEDITOR.dialogCommand('footnotesDialog', { + // Define an editor command that opens our dialog. + editor.addCommand('footnotes', new CKEDITOR.dialogCommand('footnotesDialog', { // @TODO: This needs work: allowedContent: 'section[*](*);header[*](*);li[*];a[*];cite(*)[*];sup[*]', - requiredContent: 'section[*](*);header[*](*);li[*];a[*];cite(*)[*];sup[*]' - })); + requiredContent: 'section[*](*);header[*](*);li[*];a[*];cite(*)[*];sup[*]' + })); - // Create a toolbar button that executes the above command. - editor.ui.addButton('Footnotes', { + // Create a toolbar button that executes the above command. + editor.ui.addButton('Footnotes', { - // The text part of the button (if available) and tooptip. - label: 'Insert Footnotes', + // The text part of the button (if available) and tooptip. + label: 'Insert Footnotes', - // The command to execute on click. - command: 'footnotes', + // The command to execute on click. + command: 'footnotes', - // The button placement in the toolbar (toolbar group name). - toolbar: 'insert' - }); + // The button placement in the toolbar (toolbar group name). + toolbar: 'insert' + }); - // Register our dialog file. this.path is the plugin folder path. - CKEDITOR.dialog.add('footnotesDialog', this.path + 'dialogs/footnotes.js'); - }, + // Register our dialog file. this.path is the plugin folder path. + CKEDITOR.dialog.add('footnotesDialog', this.path + 'dialogs/footnotes.js'); + }, build: function(footnote, is_new, editor) { - editor.fire('lockSnapshot'); + if (is_new) { // Generate new id: footnote_id = this.generateFootnoteId(); @@ -132,13 +137,13 @@ CKEDITOR.plugins.add( 'footnotes', { // Insert the marker: var footnote_marker = 'X'; - editor.fire('unlockSnapshot'); editor.insertHtml(footnote_marker); - + if (is_new) { + editor.fire('lockSnapshot'); this.addFootnote(this.buildFootnote(footnote_id, footnote, false, editor), editor); + editor.fire('unlockSnapshot'); } - this.reorderMarkers(editor); }, @@ -206,7 +211,8 @@ CKEDITOR.plugins.add( 'footnotes', { // Check that there's a footnotes section. If it's been deleted the markers are useless: if ($contents.find('.footnotes').length == 0) { - $contents.find('sup[data-footnote-id]').remove(); editor.fire('unlockSnapshot'); + $contents.find('sup[data-footnote-id]').remove(); + editor.fire('unlockSnapshot'); return; } @@ -214,7 +220,8 @@ CKEDITOR.plugins.add( 'footnotes', { var $markers = $contents.find('sup[data-footnote-id]'); // If there aren't any, remove the Footnotes container: if ($markers.length == 0) { - $contents.find('.footnotes').remove(); editor.fire('unlockSnapshot'); + $contents.find('.footnotes').remove(); + editor.fire('unlockSnapshot'); return; } @@ -249,7 +256,9 @@ CKEDITOR.plugins.add( 'footnotes', { // Then rebuild the Footnotes content to match marker order: var footnotes = ''; var footnote_text = ''; - for (i in data.order) { + var i = 0 + , l = data.order.length; + for (i; i < l; i++) { footnote_id = data.order[i]; footnote_text = $contents.find('.footnotes [data-footnote-id=' + footnote_id + '] cite').html(); // If the footnotes text can't be found in the editor, it may be in the tmp store