summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.txt1
-rw-r--r--editors/js/nicedit.js48
2 files changed, 47 insertions, 2 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index 7435e7a..6237973 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -6,6 +6,7 @@ Wysiwyg x.x-x.x, xxxx-xx-xx
Wysiwyg 5.x-2.x, xxxx-xx-xx
---------------------------
+#594322 by TwoD: Added insert method for NicEdit.
#659200 by TwoD: Fixed YUI Editor content lost in IE.
#594928 by ericbellot, TwoD, sun: Fixed 'attribs' button missing in TinyMCE.
#557090 by TwoD: Fixed Whizzywig 56 instance not removed on detach().
diff --git a/editors/js/nicedit.js b/editors/js/nicedit.js
index 6fdc603..9c23402 100644
--- a/editors/js/nicedit.js
+++ b/editors/js/nicedit.js
@@ -7,12 +7,15 @@ Drupal.wysiwyg.editor.attach.nicedit = function(context, params, settings) {
// Attach editor.
var editor = new nicEditor(settings);
editor.panelInstance(params.field);
+ editor.addEvent('focus', function () {
+ Drupal.wysiwyg.activeId = params.field;
+ });
};
/**
* Detach a single or all editors.
*
- * See Drupal.wysiwyg.editor.detach.none() for a full desciption of this hook.
+ * See Drupal.wysiwyg.editor.detach.none() for a full description of this hook.
*/
Drupal.wysiwyg.editor.detach.nicedit = function(context, params) {
if (typeof params != 'undefined') {
@@ -26,7 +29,7 @@ Drupal.wysiwyg.editor.detach.nicedit = function(context, params) {
for (var e in nicEditors.editors) {
// Save contents of all editors back into textareas.
var instances = nicEditors.editors[e].nicInstances;
- for (var i = 0; i < instances.length; i++) {
+ for (var i = 0; i < instances.length; i++) {
instances[i].remove();
}
// Remove all editor instances.
@@ -35,3 +38,44 @@ Drupal.wysiwyg.editor.detach.nicedit = function(context, params) {
}
};
+/**
+ * Instance methods for nicEdit.
+ */
+Drupal.wysiwyg.editor.instance.nicedit = {
+ insert: function (content) {
+ var instance = nicEditors.findEditor(this.field);
+ var editingArea = instance.getElm();
+ var sel = instance.getSel();
+ // IE.
+ if (document.selection) {
+ editingArea.focus();
+ sel.createRange().text = content;
+ }
+ else {
+ // Convert selection to a range.
+ var range;
+ // W3C compatible.
+ if (sel.getRangeAt) {
+ range = sel.getRangeAt(0);
+ }
+ // Safari.
+ else {
+ range = editingArea.ownerDocument.createRange();
+ range.setStart(sel.anchorNode, sel.anchorOffset);
+ range.setEnd(sel.focusNode, userSeletion.focusOffset);
+ }
+ // The code below doesn't work in IE, but it never gets here.
+ var fragment = editingArea.ownerDocument.createDocumentFragment();
+ // Fragments don't support innerHTML.
+ var wrapper = editingArea.ownerDocument.createElement('div');
+ wrapper.innerHTML = content;
+ while (wrapper.firstChild) {
+ fragment.appendChild(wrapper.firstChild);
+ }
+ range.deleteContents();
+ // Only fragment children are inserted.
+ range.insertNode(fragment);
+ }
+ }
+};
+