summaryrefslogtreecommitdiff
path: root/addons/website/static/src/js/website.editor.js
diff options
context:
space:
mode:
authorFabien Meghazi <fme@openerp.com>2013-10-28 17:26:23 +0100
committerFabien Meghazi <fme@openerp.com>2013-10-28 17:26:23 +0100
commit82c749c91d472f5e85693bbbcd823ec6f3b259c5 (patch)
treed2632d9ac4dfd51f693e6a59e9ad18b3368bda40 /addons/website/static/src/js/website.editor.js
parent4f3e17ba333e7f3aaccfa63cbd9ad9a5f3b0dbe5 (diff)
[IMP] Refactor LinkDialog -> RTELinkDialog
bzr revid: fme@openerp.com-20131028162623-i2a4cixspm8q1crx
Diffstat (limited to 'addons/website/static/src/js/website.editor.js')
-rw-r--r--addons/website/static/src/js/website.editor.js170
1 files changed, 89 insertions, 81 deletions
diff --git a/addons/website/static/src/js/website.editor.js b/addons/website/static/src/js/website.editor.js
index 25453bde0d6..b3c568c16fc 100644
--- a/addons/website/static/src/js/website.editor.js
+++ b/addons/website/static/src/js/website.editor.js
@@ -14,7 +14,7 @@
});
function link_dialog(editor) {
- return new website.editor.LinkDialog(editor).appendTo(document.body);
+ return new website.editor.RTELinkDialog(editor).appendTo(document.body);
}
function image_dialog(editor) {
return new website.editor.RTEImageDialog(editor).appendTo(document.body);
@@ -662,85 +662,12 @@
this.text = null;
},
start: function () {
- var element;
- if ((element = this.get_selected_link()) && element.hasAttribute('href')) {
- this.editor.getSelection().selectElement(element);
- }
- this.element = element;
- if (element) {
- this.add_removal_button();
- }
-
return $.when(
this.fetch_pages().done(this.proxy('fill_pages')),
this.fetch_menus().done(this.proxy('fill_menus')),
this._super()
).done(this.proxy('bind_data'));
},
- add_removal_button: function () {
- this.$('.modal-footer').prepend(
- openerp.qweb.render(
- 'website.editor.dialog.link.footer-button'));
- },
- remove_link: function () {
- var editor = this.editor;
- // same issue as in make_link
- setTimeout(function () {
- editor.removeStyle(new CKEDITOR.style({
- element: 'a',
- type: CKEDITOR.STYLE_INLINE,
- alwaysRemoveElement: true,
- }));
- }, 0);
- this.close();
- },
- /**
- * Greatly simplified version of CKEDITOR's
- * plugins.link.dialogs.link.onOk.
- *
- * @param {String} url
- * @param {Boolean} [new_window=false]
- * @param {String} [label=null]
- */
- make_link: function (url, new_window, label) {
- var attributes = {href: url, 'data-cke-saved-href': url};
- var to_remove = [];
- if (new_window) {
- attributes['target'] = '_blank';
- } else {
- to_remove.push('target');
- }
-
- if (this.element) {
- this.element.setAttributes(attributes);
- this.element.removeAttributes(to_remove);
- if (this.text) { this.element.setText(this.text); }
- } else {
- var selection = this.editor.getSelection();
- var range = selection.getRanges(true)[0];
-
- if (range.collapsed) {
- //noinspection JSPotentiallyInvalidConstructorUsage
- var text = new CKEDITOR.dom.text(
- this.text || label || url);
- range.insertNode(text);
- range.selectNodeContents(text);
- }
-
- //noinspection JSPotentiallyInvalidConstructorUsage
- new CKEDITOR.style({
- type: CKEDITOR.STYLE_INLINE,
- element: 'a',
- attributes: attributes,
- }).applyToRange(range);
-
- // focus dance between RTE & dialog blow up the stack in Safari
- // and Chrome, so defer select() until dialog has been closed
- setTimeout(function () {
- range.select();
- }, 0);
- }
- },
save: function () {
var self = this, _super = this._super.bind(this);
var $e = this.$('.list-group-item.active .url-source');
@@ -785,6 +712,8 @@
}
done.then(_super);
},
+ make_link: function (url, new_window, label) {
+ },
bind_data: function () {
var href = this.element && (this.element.data( 'cke-saved-href')
|| this.element.getAttribute('href'));
@@ -818,13 +747,6 @@
.siblings().removeClass('active')
.addBack().removeClass('has-error');
},
- /**
- * CKEDITOR.plugins.link.getSelectedLink ignores the editor's root,
- * if the editor is set directly on a link it will thus not work.
- */
- get_selected_link: function () {
- return get_selected_link(this.editor);
- },
fetch_pages: function () {
return openerp.jsonRpc('/web/dataset/call_kw', 'call', {
model: 'website',
@@ -869,6 +791,92 @@
process_tree(tree);
},
});
+ website.editor.RTELinkDialog = website.editor.LinkDialog.extend({
+ start: function () {
+ var element;
+ if ((element = this.get_selected_link()) && element.hasAttribute('href')) {
+ this.editor.getSelection().selectElement(element);
+ }
+ this.element = element;
+ if (element) {
+ this.add_removal_button();
+ }
+
+ return this._super();
+ },
+ add_removal_button: function () {
+ this.$('.modal-footer').prepend(
+ openerp.qweb.render(
+ 'website.editor.dialog.link.footer-button'));
+ },
+ remove_link: function () {
+ var editor = this.editor;
+ // same issue as in make_link
+ setTimeout(function () {
+ editor.removeStyle(new CKEDITOR.style({
+ element: 'a',
+ type: CKEDITOR.STYLE_INLINE,
+ alwaysRemoveElement: true,
+ }));
+ }, 0);
+ this.close();
+ },
+ /**
+ * Greatly simplified version of CKEDITOR's
+ * plugins.link.dialogs.link.onOk.
+ *
+ * @param {String} url
+ * @param {Boolean} [new_window=false]
+ * @param {String} [label=null]
+ */
+ make_link: function (url, new_window, label) {
+ var attributes = {href: url, 'data-cke-saved-href': url};
+ var to_remove = [];
+ if (new_window) {
+ attributes['target'] = '_blank';
+ } else {
+ to_remove.push('target');
+ }
+
+ if (this.element) {
+ this.element.setAttributes(attributes);
+ this.element.removeAttributes(to_remove);
+ if (this.text) { this.element.setText(this.text); }
+ } else {
+ var selection = this.editor.getSelection();
+ var range = selection.getRanges(true)[0];
+
+ if (range.collapsed) {
+ //noinspection JSPotentiallyInvalidConstructorUsage
+ var text = new CKEDITOR.dom.text(
+ this.text || label || url);
+ range.insertNode(text);
+ range.selectNodeContents(text);
+ }
+
+ //noinspection JSPotentiallyInvalidConstructorUsage
+ new CKEDITOR.style({
+ type: CKEDITOR.STYLE_INLINE,
+ element: 'a',
+ attributes: attributes,
+ }).applyToRange(range);
+
+ // focus dance between RTE & dialog blow up the stack in Safari
+ // and Chrome, so defer select() until dialog has been closed
+ setTimeout(function () {
+ range.select();
+ }, 0);
+ }
+ },
+ /**
+ * CKEDITOR.plugins.link.getSelectedLink ignores the editor's root,
+ * if the editor is set directly on a link it will thus not work.
+ */
+ get_selected_link: function () {
+ return get_selected_link(this.editor);
+ },
+ });
+
/**
* ImageDialog widget. Lets users change an image, including uploading a
* new image in OpenERP or selecting the image style (if supported by