' + footnote + '';
// Move cursor to end of content:
- var range = this.editor.createRange();
+ var range = editor.createRange();
range.moveToElementEditEnd(range.root);
- this.editor.getSelection().selectRanges([range]);
+ editor.getSelection().selectRanges([range]);
// Insert the container:
- this.editor.insertHtml(container);
+ editor.insertHtml(container);
} else {
$footnotes.find('ol').append(footnote);
}
return;
},
-
+
generateFootnoteId: function() {
var id = Math.random().toString(36).substr(2, 5);
while (jQuery.inArray(id, this.footnote_ids) != -1) {
@@ -181,16 +178,21 @@ CKEDITOR.plugins.add( 'footnotes', {
this.footnote_ids.push(id);
return id;
},
-
- reorderMarkers: function() {
- this.editor.fire('lockSnapshot');
- editor = this.editor;
+
+ reorderMarkers: function(editor) {
+ editor.fire('lockSnapshot');
$contents = jQuery('#' + editor.id + '_contents iframe').contents().find('body');
var data = {
order: [],
occurrences: {}
};
+ // 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();
+ return;
+ }
+
// Find all the markers in the document:
var $markers = $contents.find('sup[data-footnote-id]');
// If there aren't any, remove the Footnotes container:
@@ -198,13 +200,13 @@ CKEDITOR.plugins.add( 'footnotes', {
$contents.find('#footnotes').remove();
return;
}
-
+
// Otherwise reorder the markers:
$markers.each(function(){
var footnote_id = jQuery(this).attr('data-footnote-id')
, marker_ref
, n = data.order.indexOf(footnote_id);
-
+
// If this is the markers first occurrence:
if (n == -1) {
// Store the id:
@@ -223,7 +225,7 @@ CKEDITOR.plugins.add( 'footnotes', {
var marker = '[' + n + ']';
jQuery(this).html(marker);
});
-
+
// Then rebuild the Footnotes content to match marker order:
var footnotes = '';
var footnote_text = '';
@@ -233,16 +235,16 @@ CKEDITOR.plugins.add( 'footnotes', {
footnotes += this.buildFootnote(footnote_id, footnote_text, data);
}
$contents.find('#footnotes ol').html(footnotes);
-
+
// Next we need to reinstate the 'editable' properties of the footnotes.
// (we have to do this individually due to Widgets 'fireOnce' for editable selectors)
var el = $contents.find('#footnotes')
, footnote_widget;
// So first we need to find the right Widget instance:
// (I hope there's a better way of doing this but I can't find one)
- for (i in this.editor.widgets.instances) {
- if (this.editor.widgets.instances[i].name == 'footnotes') {
- footnote_widget = this.editor.widgets.instances[i];
+ for (i in editor.widgets.instances) {
+ if (editor.widgets.instances[i].name == 'footnotes') {
+ footnote_widget = editor.widgets.instances[i];
break;
}
}
@@ -252,7 +254,7 @@ CKEDITOR.plugins.add( 'footnotes', {
footnote_widget.initEditable('footnote_' + n, {selector: '#footnote-' + n +' cite', allowedContent: 'a[href]; cite[*](*); b i span'});
}
- this.editor.fire('unlockSnapshot');
+ editor.fire('unlockSnapshot');
return;
}
});