4 var website = openerp.website;
7 website.add_template_file('/website/static/src/xml/website.editor.xml');
8 website.dom_ready.done(function () {
9 var is_smartphone = $(document.body)[0].clientWidth < 767;
12 website.ready().then(website.init_editor);
14 // remove padding of fake editor bar
15 document.body.style.padding = 0;
18 $(document).on('click', 'a.js_link2post', function (ev) {
20 website.form(this.pathname, 'POST');
23 $(document).on('click', '.cke_editable label', function (ev) {
27 $(document).on('submit', '.cke_editable form', function (ev) {
28 // Disable form submition in editable mode
32 $(document).on('hide.bs.dropdown', '.dropdown', function (ev) {
33 // Prevent dropdown closing when a contenteditable children is focused
35 && $(ev.target).has(ev.originalEvent.target).length
36 && $(ev.originalEvent.target).is('[contenteditable]')) {
43 * An editing host is an HTML element with @contenteditable=true, or the
44 * child of a document in designMode=on (but that one's not supported)
46 * https://dvcs.w3.org/hg/editing/raw-file/tip/editing.html#editing-host
48 function is_editing_host(element) {
49 return element.getAttribute('contentEditable') === 'true';
52 * Checks that both the element's content *and the element itself* are
53 * editable: an editing host is considered non-editable because its content
54 * is editable but its attributes should not be considered editable
56 function is_editable_node(element) {
57 return !(element.data('oe-model') === 'ir.ui.view'
58 || element.data('cke-realelement')
59 || (is_editing_host(element) && element.getAttribute('attributeEditable') !== 'true')
60 || element.isReadOnly());
63 function link_dialog(editor) {
64 return new website.editor.RTELinkDialog(editor).appendTo(document.body);
66 function image_dialog(editor, image) {
67 return new website.editor.MediaDialog(editor, image).appendTo(document.body);
70 // only enable editors manually
71 CKEDITOR.disableAutoInline = true;
72 // EDIT ALL THE THINGS
73 CKEDITOR.dtd.$editable = _.omit(
74 $.extend({}, CKEDITOR.dtd.$block, CKEDITOR.dtd.$inline),
75 // well maybe not *all* the things
76 'ul', 'ol', 'li', 'table', 'tr', 'th', 'td');
77 // Disable removal of empty elements on CKEDITOR activation. Empty
78 // elements are used for e.g. support of FontAwesome icons
79 CKEDITOR.dtd.$removeEmpty = {};
81 website.init_editor = function () {
82 CKEDITOR.plugins.add('customdialogs', {
83 // requires: 'link,image',
84 init: function (editor) {
85 editor.on('doubleclick', function (evt) {
86 var element = evt.data.element;
87 if ((element.is('img') || element.$.className.indexOf(' fa-') != -1) && is_editable_node(element)) {
88 image_dialog(editor, element);
91 var parent = new CKEDITOR.dom.element(element.$.parentNode);
92 if (parent.$.className.indexOf('media_iframe_video') != -1 && is_editable_node(parent)) {
93 image_dialog(editor, parent);
97 element = get_selected_link(editor) || evt.data.element;
98 if (!(element.is('a') && is_editable_node(element))) {
102 editor.getSelection().selectElement(element);
106 //noinspection JSValidateTypes
107 editor.addCommand('link', {
108 exec: function (editor) {
116 //noinspection JSValidateTypes
117 editor.addCommand('cimage', {
118 exec: function (editor) {
119 image_dialog(editor);
127 editor.ui.addButton('Link', {
132 editor.ui.addButton('Image', {
135 toolbar: 'insert,10',
138 editor.setKeystroke(CKEDITOR.CTRL + 76 /*L*/, 'link');
141 CKEDITOR.plugins.add( 'tablebutton', {
142 requires: 'panelbutton,floatpanel',
143 init: function( editor ) {
146 editor.ui.add('TableButton', CKEDITOR.UI_PANELBUTTON, {
149 // use existing 'table' icon
151 modes: { wysiwyg: true },
153 // panel opens in iframe, @css is CSS file <link>-ed within
154 // frame document, @attributes are set on iframe itself.
156 css: '/website/static/src/css/editor.css',
157 attributes: { 'role': 'listbox', 'aria-label': label, },
160 onBlock: function (panel, block) {
161 block.autoSize = true;
162 block.element.setHtml(openerp.qweb.render('website.editor.table.panel', {
167 var $table = $(block.element.$).on('mouseenter', 'td', function (e) {
168 var $e = $(e.target);
169 var y = $e.index() + 1;
170 var x = $e.closest('tr').index() + 1;
173 .find('td').removeClass('selected').end()
174 .find('tr:lt(' + String(x) + ')')
175 .children().filter(function () { return $(this).index() < y; })
176 .addClass('selected');
177 }).on('click', 'td', function (e) {
178 var $e = $(e.target);
180 //noinspection JSPotentiallyInvalidConstructorUsage
181 var table = new CKEDITOR.dom.element(
182 $(openerp.qweb.render('website.editor.table', {
183 rows: $e.closest('tr').index() + 1,
184 cols: $e.index() + 1,
187 editor.insertElement(table);
188 setTimeout(function () {
189 //noinspection JSPotentiallyInvalidConstructorUsage
190 var firstCell = new CKEDITOR.dom.element(table.$.rows[0].cells[0]);
191 var range = editor.createRange();
192 range.moveToPosition(firstCell, CKEDITOR.POSITION_AFTER_START);
197 block.element.getDocument().getBody().setStyle('overflow', 'hidden');
198 CKEDITOR.ui.fire('ready', this);
204 CKEDITOR.plugins.add('linkstyle', {
205 requires: 'panelbutton,floatpanel',
206 init: function (editor) {
207 var label = "Link Style";
209 editor.ui.add('LinkStyle', CKEDITOR.UI_PANELBUTTON, {
212 icon: '/website/static/src/img/bglink.png',
213 modes: { wysiwyg: true },
217 css: '/web/static/lib/bootstrap/css/bootstrap.css',
218 attributes: { 'role': 'listbox', 'aria-label': label },
222 'btn-default': _t("Basic"),
223 'btn-primary': _t("Primary"),
224 'btn-success': _t("Success"),
225 'btn-info': _t("Info"),
226 'btn-warning': _t("Warning"),
227 'btn-danger': _t("Danger"),
230 'btn-xs': _t("Extra Small"),
231 'btn-sm': _t("Small"),
233 'btn-lg': _t("Large")
236 onRender: function () {
238 editor.on('selectionChange', function (e) {
239 var path = e.data.path, el;
241 if (!(e = path.contains('a')) || e.isReadOnly()) {
248 // no hook where button is available, so wait
249 // "some time" after render.
250 setTimeout(function () {
254 enable: function () {
255 this.setState(CKEDITOR.TRISTATE_OFF);
257 disable: function () {
258 this.setState(CKEDITOR.TRISTATE_DISABLED);
261 onOpen: function () {
262 var link = get_selected_link(editor);
264 var block = this._.panel._.panel._.blocks[id];
265 var $root = $(block.element.$);
266 $root.find('button').removeClass('active').removeProp('disabled');
268 // enable buttons matching link state
269 for (var type in this.types) {
270 if (!this.types.hasOwnProperty(type)) { continue; }
271 if (!link.hasClass(type)) { continue; }
273 $root.find('button[data-type=types].' + type)
277 for (var size in this.sizes) {
278 if (!this.sizes.hasOwnProperty(size)) { continue; }
279 if (!size || !link.hasClass(size)) { continue; }
281 $root.find('button[data-type=sizes].' + size)
284 if (!found && link.hasClass('btn')) {
285 $root.find('button[data-type="sizes"][data-set-class=""]')
290 onBlock: function (panel, block) {
292 block.autoSize = true;
294 var html = ['<div style="padding: 5px">'];
295 html.push('<div style="white-space: nowrap">');
296 _(this.types).each(function (label, key) {
297 html.push(_.str.sprintf(
298 '<button type="button" class="btn %s" ' +
299 'data-type="types" data-set-class="%s">%s</button>',
303 html.push('<div style="white-space: nowrap; margin: 5px 0; text-align: center">');
304 _(this.sizes).each(function (label, key) {
305 html.push(_.str.sprintf(
306 '<button type="button" class="btn btn-default %s" ' +
307 'data-type="sizes" data-set-class="%s">%s</button>',
311 html.push('<button type="button" class="btn btn-link btn-block" ' +
312 'data-type="reset">Reset</button>');
315 block.element.setHtml(html.join(' '));
316 var $panel = $(block.element.$);
317 $panel.on('click', 'button', function () {
321 clicked: function (button) {
323 editor.fire('saveSnapshot');
325 var $button = $(button),
326 $link = $(get_selected_link(editor).$);
327 if (!$link.hasClass('btn')) {
328 $link.addClass('btn btn-default');
330 switch($button.data('type')) {
332 $link.removeClass('btn')
333 .removeClass(_.keys(this.types).join(' '))
334 .removeClass(_.keys(this.sizes).join(' '));
337 $link.removeClass(_.keys(this.types).join(' '))
338 .addClass($button.data('set-class'));
341 $link.removeClass(_.keys(this.sizes).join(' '))
342 .addClass($button.data('set-class'));
346 editor.fire('saveSnapshot');
353 CKEDITOR.plugins.add('oeref', {
356 init: function (editor) {
358 // Can't find the correct ACL rule to only allow img tags
359 image: { content: '*' },
363 selector: 'span.oe_currency_value',
368 _(specials).each(function (editable, type) {
369 editor.widgets.add(type, {
372 upcast: function (el) {
373 return el.attributes['data-oe-type'] === type;
378 editor.widgets.add('oeref', {
386 upcast: function (el) {
387 var type = el.attributes['data-oe-type'];
388 if (!type || (type in specials)) {
391 if (el.attributes['data-oe-original']) {
392 while (el.children.length) {
393 el.children[0].remove();
395 el.add(new CKEDITOR.htmlParser.text(
396 el.attributes['data-oe-original']
403 editor.widgets.add('icons', {
407 this.on('edit', function () {
408 new website.editor.MediaDialog(editor, this.element)
409 .appendTo(document.body);
412 upcast: function (el) {
413 return el.hasClass('fa')
414 // ignore ir.ui.view (other data-oe-model should
415 // already have been matched by oeref and
417 && !el.attributes['data-oe-model'];
423 var editor = new website.EditorBar();
424 var $body = $(document.body);
425 editor.prependTo($body).then(function () {
426 if (location.search.indexOf("enable_editor") >= 0) {
430 website.editor_bar = editor;
433 /* ----- TOP EDITOR BAR FOR ADMIN ---- */
434 website.EditorBar = openerp.Widget.extend({
435 template: 'website.editorbar',
437 'click button[data-action=edit]': 'edit',
438 'click button[data-action=save]': 'save',
439 'click a[data-action=cancel]': 'cancel',
442 customize_setup: function() {
444 var view_name = $(document.documentElement).data('view-xmlid');
446 this.$('#customize-menu-button').addClass("hidden");
448 var menu = $('#customize-menu');
449 this.$('#customize-menu-button').click(function(event) {
451 openerp.jsonRpc('/website/customize_template_get', 'call', { 'xml_id': view_name }).then(
453 _.each(result, function (item) {
454 if (item.xml_id === "website.debugger" && !window.location.search.match(/[&?]debug(&|$)/)) return;
456 menu.append('<li class="dropdown-header">' + item.name + '</li>');
458 menu.append(_.str.sprintf('<li role="presentation"><a href="#" data-view-id="%s" role="menuitem"><strong class="fa fa%s-square-o"></strong> %s</a></li>',
459 item.id, item.active ? '-check' : '', item.name));
462 // Adding Static Menus
463 menu.append('<li class="divider"></li>');
464 menu.append('<li><a data-action="ace" href="#">HTML Editor</a></li>');
465 menu.append('<li class="js_change_theme"><a href="/page/website.themes">Change Theme</a></li>');
466 menu.append('<li><a href="/web#return_label=Website&action=website.action_module_website">Install Apps</a></li>');
467 self.trigger('rte:customize_menu_ready');
471 menu.on('click', 'a[data-view-id]', function (event) {
472 var view_id = $(event.currentTarget).data('view-id');
473 openerp.jsonRpc('/website/customize_template_toggle', 'call', {
475 }).then( function() {
476 window.location.reload();
481 // remove placeholder editor bar
482 var fakebar = document.getElementById('website-top-navbar-placeholder');
484 fakebar.parentNode.removeChild(fakebar);
488 this.saving_mutex = new openerp.Mutex();
490 this.$('#website-top-edit').hide();
491 this.$('#website-top-view').show();
493 $('.dropdown-toggle').dropdown();
494 this.customize_setup();
497 edit: this.$('button[data-action=edit]'),
498 save: this.$('button[data-action=save]'),
499 cancel: this.$('button[data-action=cancel]'),
502 this.rte = new website.RTE(this);
503 this.rte.on('change', this, this.proxy('rte_changed'));
504 this.rte.on('rte:ready', this, function () {
505 self.setup_hover_buttons();
506 self.trigger('rte:ready');
510 $(window).on('resize', _.debounce(this.check_height.bind(this), 50));
513 if (website.is_editable_button) {
514 this.$("button[data-action=edit]").removeClass("hidden");
518 this._super.apply(this, arguments),
519 this.rte.appendTo(this.$('#website-top-edit .nav.pull-right'))
524 check_height: function () {
525 var editor_height = this.$el.outerHeight();
526 if (this.get('height') != editor_height) {
527 $(document.body).css('padding-top', editor_height);
528 this.set('height', editor_height);
532 this.$buttons.edit.prop('disabled', true);
533 this.$('#website-top-view').hide();
534 this.$('#website-top-edit').show();
535 $('.css_non_editable_mode_hidden').removeClass("css_non_editable_mode_hidden");
537 this.rte.start_edition().then(this.check_height.bind(this));
538 this.trigger('rte:called');
540 rte_changed: function () {
541 this.$buttons.save.prop('disabled', false);
546 observer.disconnect();
547 var editor = this.rte.editor;
548 var root = editor.element.$;
550 // FIXME: select editables then filter by dirty?
551 var defs = this.rte.fetch_editables(root)
553 .removeAttr('contentEditable')
554 .removeClass('oe_dirty oe_editable cke_focus oe_carlos_danger')
557 // TODO: Add a queue with concurrency limit in webclient
558 // https://github.com/medikoo/deferred/blob/master/lib/ext/function/gate.js
559 return self.saving_mutex.exec(function () {
560 return self.saveElement($el)
561 .then(undefined, function (thing, response) {
562 // because ckeditor regenerates all the dom,
563 // we can't just setup the popover here as
564 // everything will be destroyed by the DOM
565 // regeneration. Add markings instead, and
566 // returns a new rejection with all relevant
568 var id = _.uniqueId('carlos_danger_');
569 $el.addClass('oe_dirty oe_carlos_danger');
571 return $.Deferred().reject({
573 error: response.data,
578 return $.when.apply(null, defs).then(function () {
580 }, function (failed) {
581 // If there were errors, re-enable edition
582 self.rte.start_edition(true).then(function () {
583 // jquery's deferred being a pain in the ass
584 if (!_.isArray(failed)) { failed = [failed]; }
586 _(failed).each(function (failure) {
587 var html = failure.error.exception_type === "except_osv";
589 var msg = $("<div/>").text(failure.error.message).html();
590 var data = msg.substring(3,msg.length-2).split(/', u'/);
591 failure.error.message = '<b>' + data[0] + '</b><br/>' + data[1];
593 $(root).find('.' + failure.id)
594 .removeClass(failure.id)
598 content: failure.error.message,
599 placement: 'auto top',
601 // Force-show popovers so users will notice them.
608 * Saves an RTE content, which always corresponds to a view section (?).
610 saveElement: function ($el) {
611 var markup = $el.prop('outerHTML');
612 return openerp.jsonRpc('/web/dataset/call', 'call', {
615 args: [$el.data('oe-id'), markup,
616 $el.data('oe-xpath') || null,
617 website.get_context()],
620 cancel: function () {
621 new $.Deferred(function (d) {
622 var $dialog = $(openerp.qweb.render('website.editor.discard')).appendTo(document.body);
623 $dialog.on('click', '.btn-danger', function () {
625 }).on('hidden.bs.modal', function () {
628 d.always(function () {
631 $dialog.modal('show');
632 }).then(function () {
638 * Creates a "hover" button for link edition
640 * @param {Function} editfn edition function, called when clicking the button
643 make_hover_button_link: function (editfn) {
644 return $(openerp.qweb.render('website.editor.hoverbutton.link', {}))
646 .click(function (e) {
649 editfn.call(this, e);
651 .appendTo(document.body);
655 * Creates a "hover" button for image
657 * @param {Function} editfn edition function, called when clicking the button
658 * @param {Function} stylefn edition style function, called when clicking the button
661 make_hover_button_image: function (editfn, stylefn) {
662 var $div = $(openerp.qweb.render('website.editor.hoverbutton.media', {}))
664 .appendTo(document.body);
666 $div.find('[data-toggle="dropdown"]').dropdown();
667 $div.find(".hover-edition-button").click(function (e) {
670 editfn.call(this, e);
673 $div.find(".hover-style-button").click(function (e) {
676 stylefn.call(this, e);
682 * For UI clarity, during RTE edition when the user hovers links and
683 * images a small button should appear to make the capability clear,
684 * as not all users think of double-clicking the image or link.
686 setup_hover_buttons: function () {
687 var editor = this.rte.editor;
688 var $link_button = this.make_hover_button_link(function () {
689 var sel = new CKEDITOR.dom.element(previous);
690 editor.getSelection().selectElement(sel);
691 if(sel.hasClass('fa')) {
692 new website.editor.MediaDialog(editor, previous)
693 .appendTo(document.body);
694 } else if (previous.tagName.toUpperCase() === 'A') {
701 function is_icons_widget(element) {
702 var w = editor.widgets.getByElement(element);
703 return w && w.name === 'icons';
706 // previous is the state of the button-trigger: it's the
707 // currently-ish hovered element which can trigger a button showing.
708 // -ish, because when moving to the button itself ``previous`` is
709 // still set to the element having triggered showing the button.
711 $(editor.element.$).on('mouseover', 'a', function () {
712 // Back from edit button -> ignore
713 if (previous && previous === this) { return; }
715 // hover button should appear for "editable" links and images
716 // (img and a nodes whose *attributes* are editable, they
717 // can not be "editing hosts") *or* for non-editing-host
718 // elements bearing an ``fa`` class. These should have been
719 // made into CKE widgets which are editing hosts by
720 // definition, so instead check if the element has been
721 // converted/upcasted to an fa widget
722 var selected = new CKEDITOR.dom.element(this);
723 if (!(is_editable_node(selected) || is_icons_widget(selected))) {
728 var $selected = $(this);
729 var position = $selected.offset();
730 $link_button.show().offset({
731 top: $selected.outerHeight()
733 left: $selected.outerWidth() / 2
735 - $link_button.outerWidth() / 2
737 }).on('mouseleave', 'a, img, .fa', function (e) {
738 var current = document.elementFromPoint(e.clientX, e.clientY);
739 if (current === $link_button[0] || $(current).parent()[0] === $link_button[0]) {
748 var blocks_selector = _.keys(CKEDITOR.dtd.$block).join(',');
749 /* ----- RICH TEXT EDITOR ---- */
750 website.RTE = openerp.Widget.extend({
752 id: 'oe_rte_toolbar',
753 className: 'oe_right oe_rte_toolbar',
754 // editor.ui.items -> possible commands &al
755 // editor.applyStyle(new CKEDITOR.style({element: "span",styles: {color: "#(color)"},overrides: [{element: "font",attributes: {color: null}}]}, {color: '#ff0000'}));
757 init: function (EditorBar) {
758 this.EditorBar = EditorBar;
759 this._super.apply(this, arguments);
763 * In Webkit-based browsers, triple-click will select a paragraph up to
764 * the start of the next "paragraph" including any empty space
765 * inbetween. When said paragraph is removed or altered, it nukes
766 * the empty space and brings part of the content of the next
767 * "paragraph" (which may well be e.g. an image) into the current one,
768 * completely fucking up layouts and breaking snippets.
770 * Try to fuck around with selections on triple-click to attempt to
771 * fix this garbage behavior.
773 * Note: for consistent behavior we may actually want to take over
774 * triple-clicks, in all browsers in order to ensure consistent cross-
775 * platform behavior instead of being at the mercy of rendering engines
776 * & platform selection quirks?
778 webkitSelectionFixer: function (root) {
779 root.addEventListener('click', function (e) {
780 // only webkit seems to have a fucked up behavior, ignore others
781 // FIXME: $.browser goes away in jquery 1.9...
782 if (!$.browser.webkit) { return; }
783 // http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-eventgroupings-mouseevents
784 // The detail attribute indicates the number of times a mouse button has been pressed
785 // we just want the triple click
786 if (e.detail !== 3) { return; }
789 // Get closest block-level element to the triple-clicked
790 // element (using ckeditor's block list because why not)
791 var $closest_block = $(e.target).closest(blocks_selector);
793 // manually set selection range to the content of the
794 // triple-clicked block-level element, to avoid crossing over
795 // between block-level elements
796 document.getSelection().selectAllChildren($closest_block[0]);
799 tableNavigation: function (root) {
801 $(root).on('keydown', function (e) {
803 if (e.which !== 9) { return; }
805 if (self.handleTab(e)) {
811 * Performs whatever operation is necessary on a [TAB] hit, returns
812 * ``true`` if the event's default should be cancelled (if the TAB was
813 * handled by the function)
815 handleTab: function (event) {
816 var forward = !event.shiftKey;
818 var root = window.getSelection().getRangeAt(0).commonAncestorContainer;
819 var $cell = $(root).closest('td,th');
821 if (!$cell.length) { return false; }
825 // find cell in same row
826 var row = cell.parentNode;
827 var sibling = row.cells[cell.cellIndex + (forward ? 1 : -1)];
829 document.getSelection().selectAllChildren(sibling);
833 // find cell in previous/next row
834 var table = row.parentNode;
835 var sibling_row = table.rows[row.rowIndex + (forward ? 1 : -1)];
837 var new_cell = sibling_row.cells[forward ? 0 : sibling_row.cells.length - 1];
838 document.getSelection().selectAllChildren(new_cell);
842 // at edge cells, copy word/openoffice behavior: if going backwards
843 // from first cell do nothing, if going forwards from last cell add
846 var row_size = row.cells.length;
847 var new_row = document.createElement('tr');
849 var newcell = document.createElement('td');
851 newcell.textContent = '\u200B';
852 new_row.appendChild(newcell);
854 table.appendChild(new_row);
855 document.getSelection().selectAllChildren(new_row.cells[0]);
861 * Makes the page editable
863 * @param {Boolean} [restart=false] in case the edition was already set
864 * up once and is being re-enabled.
865 * @returns {$.Deferred} deferred indicating when the RTE is ready
867 start_edition: function (restart) {
869 // create a single editor for the whole page
870 var root = document.getElementById('wrapwrap');
872 $(root).on('dragstart', 'img', function (e) {
875 this.webkitSelectionFixer(root);
876 this.tableNavigation(root);
878 var def = $.Deferred();
879 var editor = this.editor = CKEDITOR.inline(root, self._config());
880 editor.on('instanceReady', function () {
881 editor.setReadOnly(false);
882 // ckeditor set root to editable, disable it (only inner
883 // sections are editable)
884 // FIXME: are there cases where the whole editor is editable?
885 editor.editable().setReadOnly(true);
887 self.setup_editables(root);
890 // disable firefox's broken table resizing thing
891 document.execCommand("enableObjectResizing", false, "false");
892 document.execCommand("enableInlineTableEditing", false, "false");
895 // detect & setup any CKEDITOR widget within a newly dropped
896 // snippet. There does not seem to be a simple way to do it for
897 // HTML not inserted via ckeditor APIs:
898 // https://dev.ckeditor.com/ticket/11472
900 .off('snippet-dropped')
901 .on('snippet-dropped', function (e, el) {
902 // CKEDITOR data processor extended by widgets plugin
903 // to add wrappers around upcasting elements
904 el.innerHTML = editor.dataProcessor.toHtml(el.innerHTML, {
908 // then repository.initOnAll() handles the conversion
909 // from wrapper to actual widget instance (or something
911 setTimeout(function () {
912 editor.widgets.initOnAll();
916 self.trigger('rte:ready');
922 setup_editables: function (root) {
923 // selection of editable sub-items was previously in
924 // EditorBar#edit, but for some unknown reason the elements were
925 // apparently removed and recreated (?) at editor initalization,
926 // and observer setup was lost.
928 // setup dirty-marking for each editable element
929 this.fetch_editables(root)
930 .addClass('oe_editable')
934 // only explicitly set contenteditable on view sections,
935 // cke widgets system will do the widgets themselves
936 if ($node.data('oe-model') === 'ir.ui.view') {
937 node.contentEditable = true;
940 observer.observe(node, OBSERVER_CONFIG);
941 $node.one('content_changed', function () {
942 $node.addClass('oe_dirty');
943 self.trigger('change');
948 fetch_editables: function (root) {
949 return $(root).find('[data-oe-model]')
951 .not('.oe_snippet_editor')
952 .filter(function () {
954 // keep view sections and fields which are *not* in
955 // view sections for top-level editables
956 return $this.data('oe-model') === 'ir.ui.view'
957 || !$this.closest('[data-oe-model = "ir.ui.view"]').length;
961 _current_editor: function () {
962 return CKEDITOR.currentInstance;
964 _config: function () {
965 // base plugins minus
966 // - magicline (captures mousein/mouseout -> breaks draggable)
967 // - contextmenu & tabletools (disable contextual menu)
968 // - bunch of unused plugins
970 'a11yhelp', 'basicstyles', 'blockquote',
971 'clipboard', 'colorbutton', 'colordialog', 'dialogadvtab',
972 'elementspath', /*'enterkey',*/ 'entities', 'filebrowser',
973 'find', 'floatingspace','format', 'htmlwriter', 'iframe',
974 'indentblock', 'indentlist', 'justify',
975 'list', 'pastefromword', 'pastetext', 'preview',
976 'removeformat', 'resize', 'save', 'selectall', 'stylescombo',
977 'table', 'templates', 'toolbar', 'undo', 'wysiwygarea'
982 // Disable auto-generated titles
983 // FIXME: accessibility, need to generate user-sensible title, used for @title and @aria-label
985 plugins: plugins.join(','),
987 // FIXME: currently breaks RTE?
988 // Ensure no config file is loaded
991 allowedContent: true,
992 // Don't insert paragraphs around content in e.g. <li>
993 autoParagraph: false,
994 // Don't automatically add or <br> in empty block-level
995 // elements when edition starts
996 fillEmptyBlocks: false,
997 filebrowserImageUploadUrl: "/website/attach",
998 // Support for sharedSpaces in 4.x
999 extraPlugins: 'sharedspace,customdialogs,tablebutton,oeref,linkstyle',
1000 // Place toolbar in controlled location
1001 sharedSpaces: { top: 'oe_rte_toolbar' },
1003 name: 'basicstyles', items: [
1004 "Bold", "Italic", "Underline", "Strike", "Subscript",
1005 "Superscript", "TextColor", "BGColor", "RemoveFormat"
1007 name: 'span', items: [
1008 "Link", "LinkStyle", "Blockquote", "BulletedList",
1009 "NumberedList", "Indent", "Outdent"
1011 name: 'justify', items: [
1012 "JustifyLeft", "JustifyCenter", "JustifyRight", "JustifyBlock"
1014 name: 'special', items: [
1015 "Image", "TableButton"
1017 name: 'styles', items: [
1021 // styles dropdown in toolbar
1023 {name: "Normal", element: 'p'},
1024 {name: "Heading 1", element: 'h1'},
1025 {name: "Heading 2", element: 'h2'},
1026 {name: "Heading 3", element: 'h3'},
1027 {name: "Heading 4", element: 'h4'},
1028 {name: "Heading 5", element: 'h5'},
1029 {name: "Heading 6", element: 'h6'},
1030 {name: "Formatted", element: 'pre'},
1031 {name: "Address", element: 'address'}
1037 website.editor = { };
1038 website.editor.Dialog = openerp.Widget.extend({
1040 'hidden.bs.modal': 'destroy',
1041 'click button.save': 'save',
1042 'click button[data-dismiss="modal"]': 'cancel',
1044 init: function (editor) {
1046 this.editor = editor;
1048 start: function () {
1049 var sup = this._super();
1050 this.$el.modal({backdrop: 'static'});
1051 this.$('input:first').focus();
1056 this.trigger("saved");
1058 cancel: function () {
1059 this.trigger("cancel");
1061 close: function () {
1062 this.$el.modal('hide');
1066 website.editor.LinkDialog = website.editor.Dialog.extend({
1067 template: 'website.editor.dialog.link',
1068 events: _.extend({}, website.editor.Dialog.prototype.events, {
1069 'change :input.url-source': function (e) { this.changed($(e.target)); },
1070 'mousedown': function (e) {
1071 var $target = $(e.target).closest('.list-group-item');
1072 if (!$target.length || $target.hasClass('active')) {
1073 // clicked outside groups, or clicked in active groups
1077 this.changed($target.find('.url-source').filter(':input'));
1079 'click button.remove': 'remove_link',
1080 'change input#link-text': function (e) {
1081 this.text = $(e.target).val()
1084 init: function (editor) {
1085 this._super(editor);
1087 // Store last-performed request to be able to cancel/abort it.
1088 this.page_exists_req = null;
1089 this.search_pages_req = null;
1091 start: function () {
1094 this.$('#link-page').select2({
1095 minimumInputLength: 1,
1096 placeholder: _t("New or existing page"),
1097 query: function (q) {
1098 if (q.term == last) return;
1101 self.page_exists(q.term),
1102 self.fetch_pages(q.term)
1103 ).then(function (exists, results) {
1104 var rs = _.map(results, function (r) {
1105 return { id: r.url, text: r.name, };
1111 text: _.str.sprintf(_t("Create page '%s'"), q.term),
1119 q.callback({more: false, results: []});
1123 return this._super().then(this.proxy('bind_data'));
1126 var self = this, _super = this._super.bind(this);
1127 var $e = this.$('.list-group-item.active .url-source').filter(':input');
1129 if (!val || !$e[0].checkValidity()) {
1130 // FIXME: error message
1131 $e.closest('.form-group').addClass('has-error');
1136 var done = $.when();
1137 if ($e.hasClass('email-address')) {
1138 this.make_link('mailto:' + val, false, val);
1139 } else if ($e.hasClass('page')) {
1140 var data = $e.select2('data');
1142 self.make_link(data.id, false, data.text);
1144 // Create the page, get the URL back
1145 done = $.get(_.str.sprintf(
1146 '/website/add/%s?noredirect=1', encodeURI(data.id)))
1147 .then(function (response) {
1148 self.make_link(response, false, data.id);
1152 this.make_link(val, this.$('input.window-new').prop('checked'));
1156 make_link: function (url, new_window, label) {
1158 bind_data: function (text, href, new_window) {
1159 href = href || this.element && (this.element.data( 'cke-saved-href')
1160 || this.element.getAttribute('href'));
1162 if (new_window === undefined) {
1163 new_window = this.element
1164 ? this.element.getAttribute('target') === '_blank'
1167 if (text === undefined) {
1168 text = this.element ? this.element.getText() : '';
1171 this.$('input#link-text').val(text);
1172 this.$('input.window-new').prop('checked', new_window);
1174 if (!href) { return; }
1175 var match, $control;
1176 if ((match = /mailto:(.+)/.exec(href))) {
1177 $control = this.$('input.email-address').val(match[1]);
1180 $control = this.$('input.url').val(href);
1183 this.changed($control);
1185 changed: function ($e) {
1186 this.$('.url-source').filter(':input').not($e).val('')
1187 .filter(function () { return !!$(this).data('select2'); })
1188 .select2('data', null);
1189 $e.closest('.list-group-item')
1191 .siblings().removeClass('active')
1192 .addBack().removeClass('has-error');
1194 call: function (method, args, kwargs) {
1196 var req = method + '_req';
1198 if (this[req]) { this[req].abort(); }
1200 return this[req] = openerp.jsonRpc('/web/dataset/call_kw', 'call', {
1205 }).always(function () {
1209 page_exists: function (term) {
1210 return this.call('page_exists', [null, term], {
1211 context: website.get_context(),
1214 fetch_pages: function (term) {
1215 return this.call('search_pages', [null, term], {
1217 context: website.get_context(),
1221 website.editor.RTELinkDialog = website.editor.LinkDialog.extend({
1222 start: function () {
1224 if ((element = this.get_selected_link()) && element.hasAttribute('href')) {
1225 this.editor.getSelection().selectElement(element);
1227 this.element = element;
1229 this.add_removal_button();
1232 return this._super();
1234 add_removal_button: function () {
1235 this.$('.modal-footer').prepend(
1236 openerp.qweb.render(
1237 'website.editor.dialog.link.footer-button'));
1239 remove_link: function () {
1240 var editor = this.editor;
1241 // same issue as in make_link
1242 setTimeout(function () {
1243 editor.removeStyle(new CKEDITOR.style({
1245 type: CKEDITOR.STYLE_INLINE,
1246 alwaysRemoveElement: true,
1252 * Greatly simplified version of CKEDITOR's
1253 * plugins.link.dialogs.link.onOk.
1255 * @param {String} url
1256 * @param {Boolean} [new_window=false]
1257 * @param {String} [label=null]
1259 make_link: function (url, new_window, label) {
1260 var attributes = {href: url, 'data-cke-saved-href': url};
1263 attributes['target'] = '_blank';
1265 to_remove.push('target');
1269 this.element.setAttributes(attributes);
1270 this.element.removeAttributes(to_remove);
1271 if (this.text) { this.element.setText(this.text); }
1273 var selection = this.editor.getSelection();
1274 var range = selection.getRanges(true)[0];
1276 if (range.collapsed) {
1277 //noinspection JSPotentiallyInvalidConstructorUsage
1278 var text = new CKEDITOR.dom.text(
1279 this.text || label || url);
1280 range.insertNode(text);
1281 range.selectNodeContents(text);
1284 //noinspection JSPotentiallyInvalidConstructorUsage
1285 new CKEDITOR.style({
1286 type: CKEDITOR.STYLE_INLINE,
1288 attributes: attributes,
1289 }).applyToRange(range);
1291 // focus dance between RTE & dialog blow up the stack in Safari
1292 // and Chrome, so defer select() until dialog has been closed
1293 setTimeout(function () {
1299 * CKEDITOR.plugins.link.getSelectedLink ignores the editor's root,
1300 * if the editor is set directly on a link it will thus not work.
1302 get_selected_link: function () {
1303 return get_selected_link(this.editor);
1307 website.editor.Media = openerp.Widget.extend({
1308 init: function (parent, editor, media) {
1310 this.parent = parent;
1311 this.editor = editor;
1314 start: function () {
1315 this.$preview = this.$('.preview-container').detach();
1316 return this._super();
1318 search: function (needle) {
1322 clear: function () {
1324 cancel: function () {
1326 close: function () {
1329 website.editor.MediaDialog = website.editor.Dialog.extend({
1330 template: 'website.editor.dialog.media',
1331 events : _.extend({}, website.editor.Dialog.prototype.events, {
1332 'input input#icon-search': 'search',
1335 init: function (editor, media) {
1336 this._super(editor);
1337 this.editor = editor;
1341 start: function () {
1344 this.imageDialog = new website.editor.RTEImageDialog(this, this.editor, this.media);
1345 this.imageDialog.appendTo(this.$("#editor-media-image"));
1346 this.iconDialog = new website.editor.FontIconsDialog(this, this.editor, this.media);
1347 this.iconDialog.appendTo(this.$("#editor-media-icon"));
1348 this.videoDialog = new website.editor.VideoDialog(this, this.editor, this.media);
1349 this.videoDialog.appendTo(this.$("#editor-media-video"));
1351 this.active = this.imageDialog;
1353 $('a[data-toggle="tab"]').on('shown.bs.tab', function (event) {
1354 if ($(event.target).is('[href="#editor-media-image"]')) {
1355 self.active = self.imageDialog;
1356 self.$('li.search, li.previous, li.next').removeClass("hidden");
1357 } else if ($(event.target).is('[href="#editor-media-icon"]')) {
1358 self.active = self.iconDialog;
1359 self.$('li.search, li.previous, li.next').removeClass("hidden");
1360 self.$('.nav-tabs li.previous, .nav-tabs li.next').addClass("hidden");
1361 } else if ($(event.target).is('[href="#editor-media-video"]')) {
1362 self.active = self.videoDialog;
1363 self.$('.nav-tabs li.search').addClass("hidden");
1368 if (this.media.$.nodeName === "IMG") {
1369 this.$('[href="#editor-media-image"]').tab('show');
1370 } else if (this.media.$.className.match(/(^|\s)media_iframe_video($|\s)/)) {
1371 this.$('[href="#editor-media-video"]').tab('show');
1372 } else if (this.media.$.className.match(/(^|\s)fa($|\s)/)) {
1373 this.$('[href="#editor-media-icon"]').tab('show');
1376 if ($(this.media.$).parent().data("oe-field") === "image") {
1377 this.$('[href="#editor-media-video"], [href="#editor-media-icon"]').addClass('hidden');
1381 return this._super();
1386 this.media.$.innerHTML = "";
1387 if (this.active !== this.imageDialog) {
1388 this.imageDialog.clear();
1390 if (this.active !== this.iconDialog) {
1391 this.iconDialog.clear();
1393 if (this.active !== this.videoDialog) {
1394 this.videoDialog.clear();
1397 var selection = this.editor.getSelection();
1398 var range = selection.getRanges(true)[0];
1399 this.media = new CKEDITOR.dom.element("img");
1400 range.insertNode(this.media);
1401 range.selectNodeContents(this.media);
1402 this.active.media = this.media;
1405 var $el = $(self.active.media.$);
1409 this.media.$.className = this.media.$.className.replace(/\s+/g, ' ');
1411 setTimeout(function () {
1412 $el.trigger("saved", self.active.media.$);
1413 $(document.body).trigger("media-saved", [$el[0], self.active.media.$]);
1419 search: function () {
1421 var needle = this.$("input#icon-search").val();
1422 clearTimeout(this.searchTimer);
1423 this.searchTimer = setTimeout(function () {
1424 self.active.search(needle || "");
1430 * ImageDialog widget. Lets users change an image, including uploading a
1431 * new image in OpenERP or selecting the image style (if supported by
1434 * Initialized as usual, but the caller can hook into two events:
1436 * @event start({url, style}) called during dialog initialization and
1437 * opening, the handler can *set* the ``url``
1438 * and ``style`` properties on its parameter
1439 * to provide these as default values to the
1441 * @event save({url, style}) called during dialog finalization, the handler
1442 * is provided with the image url and style
1443 * selected by the users (or possibly the ones
1444 * originally passed in)
1446 var IMAGES_PER_ROW = 6;
1447 var IMAGES_ROWS = 2;
1448 website.editor.ImageDialog = website.editor.Media.extend({
1449 template: 'website.editor.dialog.image',
1450 events: _.extend({}, website.editor.Dialog.prototype.events, {
1451 'change .url-source': function (e) {
1452 this.changed($(e.target));
1454 'click button.filepicker': function () {
1455 this.$('input[type=file]').click();
1457 'change input[type=file]': 'file_selection',
1458 'submit form': 'form_submit',
1459 'change input.url': "change_input",
1460 'keyup input.url': "change_input",
1461 //'change select.image-style': 'preview_image',
1462 'click .existing-attachments img': 'select_existing',
1463 'click .existing-attachment-remove': 'try_remove',
1466 init: function (parent, editor, media) {
1468 this._super(parent, editor, media);
1470 start: function () {
1472 var res = this._super();
1474 var o = { url: null };
1475 // avoid typos, prevent addition of new properties to the object
1476 Object.preventExtensions(o);
1477 this.trigger('start', o);
1479 this.parent.$(".pager > li").click(function (e) {
1481 var $target = $(e.currentTarget);
1482 if ($target.hasClass('disabled')) {
1485 self.page += $target.hasClass('previous') ? -1 : 1;
1486 self.display_attachments();
1489 this.set_image(o.url);
1495 this.link = this.$(".existing-attachments img:first").attr('src');
1497 this.trigger('save', {
1500 this.media.renameNode("img");
1501 this.media.$.attributes.src = this.link;
1502 return this._super();
1504 clear: function () {
1505 this.media.$.className = this.media.$.className.replace(/(^|\s)(img(\s|$)|img-[^\s]*)/g, ' ');
1507 cancel: function () {
1508 this.trigger('cancel');
1511 change_input: function (e) {
1512 var $input = $(e.target);
1513 var $button = $input.parent().find("button");
1514 if ($input.val() === "") {
1515 $button.addClass("btn-default").removeClass("btn-primary");
1517 $button.removeClass("btn-default").addClass("btn-primary");
1521 search: function (needle) {
1523 this.fetch_existing(needle).then(function () {
1524 self.selected_existing(self.$('input.url').val());
1528 set_image: function (url, error) {
1530 if (url) this.link = url;
1531 this.$('input.url').val('');
1532 this.fetch_existing().then(function () {
1533 self.selected_existing(url);
1537 form_submit: function (event) {
1539 var $form = this.$('form[action="/website/attach"]');
1540 if (!$form.find('input[name="upload"]').val().length) {
1541 var url = $form.find('input[name="url"]').val();
1542 if (this.selected_existing(url).size()) {
1543 event.preventDefault();
1547 var callback = _.uniqueId('func_');
1548 this.$('input[name=func]').val(callback);
1549 window[callback] = function (url, error) {
1550 delete window[callback];
1551 self.file_selected(url, error);
1554 file_selection: function () {
1555 this.$el.addClass('nosave');
1556 this.$('form').removeClass('has-error').find('.help-block').empty();
1557 this.$('button.filepicker').removeClass('btn-danger btn-success');
1558 this.$('form').submit();
1560 file_selected: function(url, error) {
1561 var $button = this.$('button.filepicker');
1563 $button.addClass('btn-success');
1566 this.$('form').addClass('has-error')
1567 .find('.help-block').text(error);
1568 $button.addClass('btn-danger');
1570 this.set_image(url, error);
1571 // auto save and close popup
1575 fetch_existing: function (needle) {
1576 var domain = [['res_model', '=', 'ir.ui.view'], '|',
1577 ['mimetype', '=', false], ['mimetype', '=like', 'image/%']];
1578 if (needle && needle.length) {
1579 domain.push('|', ['datas_fname', 'ilike', needle], ['name', 'ilike', needle]);
1581 return openerp.jsonRpc('/web/dataset/call_kw', 'call', {
1582 model: 'ir.attachment',
1583 method: 'search_read',
1586 fields: ['name', 'website_url'],
1589 context: website.get_context(),
1591 }).then(this.proxy('fetched_existing'));
1593 fetched_existing: function (records) {
1594 this.records = records;
1595 this.display_attachments();
1597 display_attachments: function () {
1598 this.$('.help-block').empty();
1599 var per_screen = IMAGES_PER_ROW * IMAGES_ROWS;
1601 var from = this.page * per_screen;
1602 var records = this.records;
1604 // Create rows of 3 records
1605 var rows = _(records).chain()
1606 .slice(from, from + per_screen)
1607 .groupBy(function (_, index) { return Math.floor(index / IMAGES_PER_ROW); })
1611 this.$('.existing-attachments').replaceWith(
1612 openerp.qweb.render(
1613 'website.editor.dialog.image.existing.content', {rows: rows}));
1614 this.parent.$('.pager')
1615 .find('li.previous').toggleClass('disabled', (from === 0)).end()
1616 .find('li.next').toggleClass('disabled', (from + per_screen >= records.length));
1618 select_existing: function (e) {
1619 var link = $(e.currentTarget).attr('src');
1621 this.selected_existing(link);
1623 selected_existing: function (link) {
1624 this.$('.existing-attachment-cell.media_selected').removeClass("media_selected");
1625 var $select = this.$('.existing-attachment-cell img').filter(function () {
1626 return $(this).attr("src") == link;
1628 $select.parent().addClass("media_selected");
1632 try_remove: function (e) {
1633 var $help_block = this.$('.help-block').empty();
1635 var $a = $(e.target);
1636 var id = parseInt($a.data('id'), 10);
1637 var attachment = _.findWhere(this.records, {id: id});
1638 var $both = $a.parent().children();
1640 $both.css({borderWidth: "5px", borderColor: "#f00"});
1642 return openerp.jsonRpc('/web/dataset/call_kw', 'call', {
1643 model: 'ir.attachment',
1644 method: 'try_remove',
1648 context: website.get_context()
1650 }).then(function (prevented) {
1651 if (_.isEmpty(prevented)) {
1652 self.records = _.without(self.records, attachment);
1653 self.display_attachments();
1656 $both.css({borderWidth: "", borderColor: ""});
1657 $help_block.replaceWith(openerp.qweb.render(
1658 'website.editor.dialog.image.existing.error', {
1659 views: prevented[id]
1666 website.editor.RTEImageDialog = website.editor.ImageDialog.extend({
1667 init: function (parent, editor, media) {
1668 this._super(parent, editor, media);
1670 this.on('start', this, this.proxy('started'));
1671 this.on('save', this, this.proxy('saved'));
1673 started: function (holder) {
1675 var selection = this.editor.getSelection();
1676 this.media = selection && selection.getSelectedElement();
1679 var el = this.media;
1680 if (!el || !el.is('img')) {
1683 holder.url = el.getAttribute('src');
1685 saved: function (data) {
1686 var element, editor = this.editor;
1687 if (!(element = this.media)) {
1688 element = editor.document.createElement('img');
1689 element.addClass('img');
1690 element.addClass('img-responsive');
1691 // focus event handler interactions between bootstrap (modal)
1692 // and ckeditor (RTE) lead to blowing the stack in Safari and
1693 // Chrome (but not FF) when this is done synchronously =>
1694 // defer insertion so modal has been hidden & destroyed before
1696 setTimeout(function () {
1697 editor.insertElement(element);
1701 var style = data.style;
1702 element.setAttribute('src', data.url);
1703 element.removeAttribute('data-cke-saved-src');
1704 if (style) { element.addClass(style); }
1708 function get_selected_link(editor) {
1709 var sel = editor.getSelection(),
1710 el = sel.getSelectedElement();
1711 if (el && el.is('a')) { return el; }
1713 var range = sel.getRanges(true)[0];
1714 if (!range) { return null; }
1716 range.shrink(CKEDITOR.SHRINK_TEXT);
1717 var commonAncestor = range.getCommonAncestor();
1718 var viewRoot = editor.elementPath(commonAncestor).contains(function (element) {
1719 return element.data('oe-model') === 'ir.ui.view';
1721 if (!viewRoot) { return null; }
1722 // if viewRoot is the first link, don't edit it.
1723 return new CKEDITOR.dom.elementPath(commonAncestor, viewRoot)
1724 .contains('a', true);
1727 website.editor.FontIconsDialog = website.editor.Media.extend({
1728 template: 'website.editor.dialog.font-icons',
1729 events : _.extend({}, website.editor.Dialog.prototype.events, {
1730 change: 'update_preview',
1731 'click .font-icons-icon': function (e) {
1733 e.stopPropagation();
1735 this.$('#fa-icon').val(e.target.getAttribute('data-id'));
1736 this.update_preview();
1738 'click #fa-preview span': function (e) {
1740 e.stopPropagation();
1742 this.$('#fa-size').val(e.target.getAttribute('data-size'));
1743 this.update_preview();
1747 // List of FontAwesome icons in 4.0.3, extracted from the cheatsheet.
1748 // Each icon provides the unicode codepoint as ``text`` and the class
1749 // name as ``id`` so the whole thing can be fed directly to select2
1750 // without post-processing and do the right thing (except for the part
1751 // where we still need to implement ``initSelection``)
1752 // TODO: add id/name to the text in order to allow FAYT selection of icons?
1753 icons: [{"text": "\uf000", "id": "fa-glass"}, {"text": "\uf001", "id": "fa-music"}, {"text": "\uf002", "id": "fa-search"}, {"text": "\uf003", "id": "fa-envelope-o"}, {"text": "\uf004", "id": "fa-heart"}, {"text": "\uf005", "id": "fa-star"}, {"text": "\uf006", "id": "fa-star-o"}, {"text": "\uf007", "id": "fa-user"}, {"text": "\uf008", "id": "fa-film"}, {"text": "\uf009", "id": "fa-th-large"}, {"text": "\uf00a", "id": "fa-th"}, {"text": "\uf00b", "id": "fa-th-list"}, {"text": "\uf00c", "id": "fa-check"}, {"text": "\uf00d", "id": "fa-times"}, {"text": "\uf00e", "id": "fa-search-plus"}, {"text": "\uf010", "id": "fa-search-minus"}, {"text": "\uf011", "id": "fa-power-off"}, {"text": "\uf012", "id": "fa-signal"}, {"text": "\uf013", "id": "fa-cog"}, {"text": "\uf014", "id": "fa-trash-o"}, {"text": "\uf015", "id": "fa-home"}, {"text": "\uf016", "id": "fa-file-o"}, {"text": "\uf017", "id": "fa-clock-o"}, {"text": "\uf018", "id": "fa-road"}, {"text": "\uf019", "id": "fa-download"}, {"text": "\uf01a", "id": "fa-arrow-circle-o-down"}, {"text": "\uf01b", "id": "fa-arrow-circle-o-up"}, {"text": "\uf01c", "id": "fa-inbox"}, {"text": "\uf01d", "id": "fa-play-circle-o"}, {"text": "\uf01e", "id": "fa-repeat"}, {"text": "\uf021", "id": "fa-refresh"}, {"text": "\uf022", "id": "fa-list-alt"}, {"text": "\uf023", "id": "fa-lock"}, {"text": "\uf024", "id": "fa-flag"}, {"text": "\uf025", "id": "fa-headphones"}, {"text": "\uf026", "id": "fa-volume-off"}, {"text": "\uf027", "id": "fa-volume-down"}, {"text": "\uf028", "id": "fa-volume-up"}, {"text": "\uf029", "id": "fa-qrcode"}, {"text": "\uf02a", "id": "fa-barcode"}, {"text": "\uf02b", "id": "fa-tag"}, {"text": "\uf02c", "id": "fa-tags"}, {"text": "\uf02d", "id": "fa-book"}, {"text": "\uf02e", "id": "fa-bookmark"}, {"text": "\uf02f", "id": "fa-print"}, {"text": "\uf030", "id": "fa-camera"}, {"text": "\uf031", "id": "fa-font"}, {"text": "\uf032", "id": "fa-bold"}, {"text": "\uf033", "id": "fa-italic"}, {"text": "\uf034", "id": "fa-text-height"}, {"text": "\uf035", "id": "fa-text-width"}, {"text": "\uf036", "id": "fa-align-left"}, {"text": "\uf037", "id": "fa-align-center"}, {"text": "\uf038", "id": "fa-align-right"}, {"text": "\uf039", "id": "fa-align-justify"}, {"text": "\uf03a", "id": "fa-list"}, {"text": "\uf03b", "id": "fa-outdent"}, {"text": "\uf03c", "id": "fa-indent"}, {"text": "\uf03d", "id": "fa-video-camera"}, {"text": "\uf03e", "id": "fa-picture-o"}, {"text": "\uf040", "id": "fa-pencil"}, {"text": "\uf041", "id": "fa-map-marker"}, {"text": "\uf042", "id": "fa-adjust"}, {"text": "\uf043", "id": "fa-tint"}, {"text": "\uf044", "id": "fa-pencil-square-o"}, {"text": "\uf045", "id": "fa-share-square-o"}, {"text": "\uf046", "id": "fa-check-square-o"}, {"text": "\uf047", "id": "fa-arrows"}, {"text": "\uf048", "id": "fa-step-backward"}, {"text": "\uf049", "id": "fa-fast-backward"}, {"text": "\uf04a", "id": "fa-backward"}, {"text": "\uf04b", "id": "fa-play"}, {"text": "\uf04c", "id": "fa-pause"}, {"text": "\uf04d", "id": "fa-stop"}, {"text": "\uf04e", "id": "fa-forward"}, {"text": "\uf050", "id": "fa-fast-forward"}, {"text": "\uf051", "id": "fa-step-forward"}, {"text": "\uf052", "id": "fa-eject"}, {"text": "\uf053", "id": "fa-chevron-left"}, {"text": "\uf054", "id": "fa-chevron-right"}, {"text": "\uf055", "id": "fa-plus-circle"}, {"text": "\uf056", "id": "fa-minus-circle"}, {"text": "\uf057", "id": "fa-times-circle"}, {"text": "\uf058", "id": "fa-check-circle"}, {"text": "\uf059", "id": "fa-question-circle"}, {"text": "\uf05a", "id": "fa-info-circle"}, {"text": "\uf05b", "id": "fa-crosshairs"}, {"text": "\uf05c", "id": "fa-times-circle-o"}, {"text": "\uf05d", "id": "fa-check-circle-o"}, {"text": "\uf05e", "id": "fa-ban"}, {"text": "\uf060", "id": "fa-arrow-left"}, {"text": "\uf061", "id": "fa-arrow-right"}, {"text": "\uf062", "id": "fa-arrow-up"}, {"text": "\uf063", "id": "fa-arrow-down"}, {"text": "\uf064", "id": "fa-share"}, {"text": "\uf065", "id": "fa-expand"}, {"text": "\uf066", "id": "fa-compress"}, {"text": "\uf067", "id": "fa-plus"}, {"text": "\uf068", "id": "fa-minus"}, {"text": "\uf069", "id": "fa-asterisk"}, {"text": "\uf06a", "id": "fa-exclamation-circle"}, {"text": "\uf06b", "id": "fa-gift"}, {"text": "\uf06c", "id": "fa-leaf"}, {"text": "\uf06d", "id": "fa-fire"}, {"text": "\uf06e", "id": "fa-eye"}, {"text": "\uf070", "id": "fa-eye-slash"}, {"text": "\uf071", "id": "fa-exclamation-triangle"}, {"text": "\uf072", "id": "fa-plane"}, {"text": "\uf073", "id": "fa-calendar"}, {"text": "\uf074", "id": "fa-random"}, {"text": "\uf075", "id": "fa-comment"}, {"text": "\uf076", "id": "fa-magnet"}, {"text": "\uf077", "id": "fa-chevron-up"}, {"text": "\uf078", "id": "fa-chevron-down"}, {"text": "\uf079", "id": "fa-retweet"}, {"text": "\uf07a", "id": "fa-shopping-cart"}, {"text": "\uf07b", "id": "fa-folder"}, {"text": "\uf07c", "id": "fa-folder-open"}, {"text": "\uf07d", "id": "fa-arrows-v"}, {"text": "\uf07e", "id": "fa-arrows-h"}, {"text": "\uf080", "id": "fa-bar-chart-o"}, {"text": "\uf081", "id": "fa-twitter-square"}, {"text": "\uf082", "id": "fa-facebook-square"}, {"text": "\uf083", "id": "fa-camera-retro"}, {"text": "\uf084", "id": "fa-key"}, {"text": "\uf085", "id": "fa-cogs"}, {"text": "\uf086", "id": "fa-comments"}, {"text": "\uf087", "id": "fa-thumbs-o-up"}, {"text": "\uf088", "id": "fa-thumbs-o-down"}, {"text": "\uf089", "id": "fa-star-half"}, {"text": "\uf08a", "id": "fa-heart-o"}, {"text": "\uf08b", "id": "fa-sign-out"}, {"text": "\uf08c", "id": "fa-linkedin-square"}, {"text": "\uf08d", "id": "fa-thumb-tack"}, {"text": "\uf08e", "id": "fa-external-link"}, {"text": "\uf090", "id": "fa-sign-in"}, {"text": "\uf091", "id": "fa-trophy"}, {"text": "\uf092", "id": "fa-github-square"}, {"text": "\uf093", "id": "fa-upload"}, {"text": "\uf094", "id": "fa-lemon-o"}, {"text": "\uf095", "id": "fa-phone"}, {"text": "\uf096", "id": "fa-square-o"}, {"text": "\uf097", "id": "fa-bookmark-o"}, {"text": "\uf098", "id": "fa-phone-square"}, {"text": "\uf099", "id": "fa-twitter"}, {"text": "\uf09a", "id": "fa-facebook"}, {"text": "\uf09b", "id": "fa-github"}, {"text": "\uf09c", "id": "fa-unlock"}, {"text": "\uf09d", "id": "fa-credit-card"}, {"text": "\uf09e", "id": "fa-rss"}, {"text": "\uf0a0", "id": "fa-hdd-o"}, {"text": "\uf0a1", "id": "fa-bullhorn"}, {"text": "\uf0f3", "id": "fa-bell"}, {"text": "\uf0a3", "id": "fa-certificate"}, {"text": "\uf0a4", "id": "fa-hand-o-right"}, {"text": "\uf0a5", "id": "fa-hand-o-left"}, {"text": "\uf0a6", "id": "fa-hand-o-up"}, {"text": "\uf0a7", "id": "fa-hand-o-down"}, {"text": "\uf0a8", "id": "fa-arrow-circle-left"}, {"text": "\uf0a9", "id": "fa-arrow-circle-right"}, {"text": "\uf0aa", "id": "fa-arrow-circle-up"}, {"text": "\uf0ab", "id": "fa-arrow-circle-down"}, {"text": "\uf0ac", "id": "fa-globe"}, {"text": "\uf0ad", "id": "fa-wrench"}, {"text": "\uf0ae", "id": "fa-tasks"}, {"text": "\uf0b0", "id": "fa-filter"}, {"text": "\uf0b1", "id": "fa-briefcase"}, {"text": "\uf0b2", "id": "fa-arrows-alt"}, {"text": "\uf0c0", "id": "fa-users"}, {"text": "\uf0c1", "id": "fa-link"}, {"text": "\uf0c2", "id": "fa-cloud"}, {"text": "\uf0c3", "id": "fa-flask"}, {"text": "\uf0c4", "id": "fa-scissors"}, {"text": "\uf0c5", "id": "fa-files-o"}, {"text": "\uf0c6", "id": "fa-paperclip"}, {"text": "\uf0c7", "id": "fa-floppy-o"}, {"text": "\uf0c8", "id": "fa-square"}, {"text": "\uf0c9", "id": "fa-bars"}, {"text": "\uf0ca", "id": "fa-list-ul"}, {"text": "\uf0cb", "id": "fa-list-ol"}, {"text": "\uf0cc", "id": "fa-strikethrough"}, {"text": "\uf0cd", "id": "fa-underline"}, {"text": "\uf0ce", "id": "fa-table"}, {"text": "\uf0d0", "id": "fa-magic"}, {"text": "\uf0d1", "id": "fa-truck"}, {"text": "\uf0d2", "id": "fa-pinterest"}, {"text": "\uf0d3", "id": "fa-pinterest-square"}, {"text": "\uf0d4", "id": "fa-google-plus-square"}, {"text": "\uf0d5", "id": "fa-google-plus"}, {"text": "\uf0d6", "id": "fa-money"}, {"text": "\uf0d7", "id": "fa-caret-down"}, {"text": "\uf0d8", "id": "fa-caret-up"}, {"text": "\uf0d9", "id": "fa-caret-left"}, {"text": "\uf0da", "id": "fa-caret-right"}, {"text": "\uf0db", "id": "fa-columns"}, {"text": "\uf0dc", "id": "fa-sort"}, {"text": "\uf0dd", "id": "fa-sort-asc"}, {"text": "\uf0de", "id": "fa-sort-desc"}, {"text": "\uf0e0", "id": "fa-envelope"}, {"text": "\uf0e1", "id": "fa-linkedin"}, {"text": "\uf0e2", "id": "fa-undo"}, {"text": "\uf0e3", "id": "fa-gavel"}, {"text": "\uf0e4", "id": "fa-tachometer"}, {"text": "\uf0e5", "id": "fa-comment-o"}, {"text": "\uf0e6", "id": "fa-comments-o"}, {"text": "\uf0e7", "id": "fa-bolt"}, {"text": "\uf0e8", "id": "fa-sitemap"}, {"text": "\uf0e9", "id": "fa-umbrella"}, {"text": "\uf0ea", "id": "fa-clipboard"}, {"text": "\uf0eb", "id": "fa-lightbulb-o"}, {"text": "\uf0ec", "id": "fa-exchange"}, {"text": "\uf0ed", "id": "fa-cloud-download"}, {"text": "\uf0ee", "id": "fa-cloud-upload"}, {"text": "\uf0f0", "id": "fa-user-md"}, {"text": "\uf0f1", "id": "fa-stethoscope"}, {"text": "\uf0f2", "id": "fa-suitcase"}, {"text": "\uf0a2", "id": "fa-bell-o"}, {"text": "\uf0f4", "id": "fa-coffee"}, {"text": "\uf0f5", "id": "fa-cutlery"}, {"text": "\uf0f6", "id": "fa-file-text-o"}, {"text": "\uf0f7", "id": "fa-building-o"}, {"text": "\uf0f8", "id": "fa-hospital-o"}, {"text": "\uf0f9", "id": "fa-ambulance"}, {"text": "\uf0fa", "id": "fa-medkit"}, {"text": "\uf0fb", "id": "fa-fighter-jet"}, {"text": "\uf0fc", "id": "fa-beer"}, {"text": "\uf0fd", "id": "fa-h-square"}, {"text": "\uf0fe", "id": "fa-plus-square"}, {"text": "\uf100", "id": "fa-angle-double-left"}, {"text": "\uf101", "id": "fa-angle-double-right"}, {"text": "\uf102", "id": "fa-angle-double-up"}, {"text": "\uf103", "id": "fa-angle-double-down"}, {"text": "\uf104", "id": "fa-angle-left"}, {"text": "\uf105", "id": "fa-angle-right"}, {"text": "\uf106", "id": "fa-angle-up"}, {"text": "\uf107", "id": "fa-angle-down"}, {"text": "\uf108", "id": "fa-desktop"}, {"text": "\uf109", "id": "fa-laptop"}, {"text": "\uf10a", "id": "fa-tablet"}, {"text": "\uf10b", "id": "fa-mobile"}, {"text": "\uf10c", "id": "fa-circle-o"}, {"text": "\uf10d", "id": "fa-quote-left"}, {"text": "\uf10e", "id": "fa-quote-right"}, {"text": "\uf110", "id": "fa-spinner"}, {"text": "\uf111", "id": "fa-circle"}, {"text": "\uf112", "id": "fa-reply"}, {"text": "\uf113", "id": "fa-github-alt"}, {"text": "\uf114", "id": "fa-folder-o"}, {"text": "\uf115", "id": "fa-folder-open-o"}, {"text": "\uf118", "id": "fa-smile-o"}, {"text": "\uf119", "id": "fa-frown-o"}, {"text": "\uf11a", "id": "fa-meh-o"}, {"text": "\uf11b", "id": "fa-gamepad"}, {"text": "\uf11c", "id": "fa-keyboard-o"}, {"text": "\uf11d", "id": "fa-flag-o"}, {"text": "\uf11e", "id": "fa-flag-checkered"}, {"text": "\uf120", "id": "fa-terminal"}, {"text": "\uf121", "id": "fa-code"}, {"text": "\uf122", "id": "fa-reply-all"}, {"text": "\uf122", "id": "fa-mail-reply-all"}, {"text": "\uf123", "id": "fa-star-half-o"}, {"text": "\uf124", "id": "fa-location-arrow"}, {"text": "\uf125", "id": "fa-crop"}, {"text": "\uf126", "id": "fa-code-fork"}, {"text": "\uf127", "id": "fa-chain-broken"}, {"text": "\uf128", "id": "fa-question"}, {"text": "\uf129", "id": "fa-info"}, {"text": "\uf12a", "id": "fa-exclamation"}, {"text": "\uf12b", "id": "fa-superscript"}, {"text": "\uf12c", "id": "fa-subscript"}, {"text": "\uf12d", "id": "fa-eraser"}, {"text": "\uf12e", "id": "fa-puzzle-piece"}, {"text": "\uf130", "id": "fa-microphone"}, {"text": "\uf131", "id": "fa-microphone-slash"}, {"text": "\uf132", "id": "fa-shield"}, {"text": "\uf133", "id": "fa-calendar-o"}, {"text": "\uf134", "id": "fa-fire-extinguisher"}, {"text": "\uf135", "id": "fa-rocket"}, {"text": "\uf136", "id": "fa-maxcdn"}, {"text": "\uf137", "id": "fa-chevron-circle-left"}, {"text": "\uf138", "id": "fa-chevron-circle-right"}, {"text": "\uf139", "id": "fa-chevron-circle-up"}, {"text": "\uf13a", "id": "fa-chevron-circle-down"}, {"text": "\uf13b", "id": "fa-html5"}, {"text": "\uf13c", "id": "fa-css3"}, {"text": "\uf13d", "id": "fa-anchor"}, {"text": "\uf13e", "id": "fa-unlock-alt"}, {"text": "\uf140", "id": "fa-bullseye"}, {"text": "\uf141", "id": "fa-ellipsis-h"}, {"text": "\uf142", "id": "fa-ellipsis-v"}, {"text": "\uf143", "id": "fa-rss-square"}, {"text": "\uf144", "id": "fa-play-circle"}, {"text": "\uf145", "id": "fa-ticket"}, {"text": "\uf146", "id": "fa-minus-square"}, {"text": "\uf147", "id": "fa-minus-square-o"}, {"text": "\uf148", "id": "fa-level-up"}, {"text": "\uf149", "id": "fa-level-down"}, {"text": "\uf14a", "id": "fa-check-square"}, {"text": "\uf14b", "id": "fa-pencil-square"}, {"text": "\uf14c", "id": "fa-external-link-square"}, {"text": "\uf14d", "id": "fa-share-square"}, {"text": "\uf14e", "id": "fa-compass"}, {"text": "\uf150", "id": "fa-caret-square-o-down"}, {"text": "\uf151", "id": "fa-caret-square-o-up"}, {"text": "\uf152", "id": "fa-caret-square-o-right"}, {"text": "\uf153", "id": "fa-eur"}, {"text": "\uf154", "id": "fa-gbp"}, {"text": "\uf155", "id": "fa-usd"}, {"text": "\uf156", "id": "fa-inr"}, {"text": "\uf157", "id": "fa-jpy"}, {"text": "\uf158", "id": "fa-rub"}, {"text": "\uf159", "id": "fa-krw"}, {"text": "\uf15a", "id": "fa-btc"}, {"text": "\uf15b", "id": "fa-file"}, {"text": "\uf15c", "id": "fa-file-text"}, {"text": "\uf15d", "id": "fa-sort-alpha-asc"}, {"text": "\uf15e", "id": "fa-sort-alpha-desc"}, {"text": "\uf160", "id": "fa-sort-amount-asc"}, {"text": "\uf161", "id": "fa-sort-amount-desc"}, {"text": "\uf162", "id": "fa-sort-numeric-asc"}, {"text": "\uf163", "id": "fa-sort-numeric-desc"}, {"text": "\uf164", "id": "fa-thumbs-up"}, {"text": "\uf165", "id": "fa-thumbs-down"}, {"text": "\uf166", "id": "fa-youtube-square"}, {"text": "\uf167", "id": "fa-youtube"}, {"text": "\uf168", "id": "fa-xing"}, {"text": "\uf169", "id": "fa-xing-square"}, {"text": "\uf16a", "id": "fa-youtube-play"}, {"text": "\uf16b", "id": "fa-dropbox"}, {"text": "\uf16c", "id": "fa-stack-overflow"}, {"text": "\uf16d", "id": "fa-instagram"}, {"text": "\uf16e", "id": "fa-flickr"}, {"text": "\uf170", "id": "fa-adn"}, {"text": "\uf171", "id": "fa-bitbucket"}, {"text": "\uf172", "id": "fa-bitbucket-square"}, {"text": "\uf173", "id": "fa-tumblr"}, {"text": "\uf174", "id": "fa-tumblr-square"}, {"text": "\uf175", "id": "fa-long-arrow-down"}, {"text": "\uf176", "id": "fa-long-arrow-up"}, {"text": "\uf177", "id": "fa-long-arrow-left"}, {"text": "\uf178", "id": "fa-long-arrow-right"}, {"text": "\uf179", "id": "fa-apple"}, {"text": "\uf17a", "id": "fa-windows"}, {"text": "\uf17b", "id": "fa-android"}, {"text": "\uf17c", "id": "fa-linux"}, {"text": "\uf17d", "id": "fa-dribbble"}, {"text": "\uf17e", "id": "fa-skype"}, {"text": "\uf180", "id": "fa-foursquare"}, {"text": "\uf181", "id": "fa-trello"}, {"text": "\uf182", "id": "fa-female"}, {"text": "\uf183", "id": "fa-male"}, {"text": "\uf184", "id": "fa-gittip"}, {"text": "\uf185", "id": "fa-sun-o"}, {"text": "\uf186", "id": "fa-moon-o"}, {"text": "\uf187", "id": "fa-archive"}, {"text": "\uf188", "id": "fa-bug"}, {"text": "\uf189", "id": "fa-vk"}, {"text": "\uf18a", "id": "fa-weibo"}, {"text": "\uf18b", "id": "fa-renren"}, {"text": "\uf18c", "id": "fa-pagelines"}, {"text": "\uf18d", "id": "fa-stack-exchange"}, {"text": "\uf18e", "id": "fa-arrow-circle-o-right"}, {"text": "\uf190", "id": "fa-arrow-circle-o-left"}, {"text": "\uf191", "id": "fa-caret-square-o-left"}, {"text": "\uf192", "id": "fa-dot-circle-o"}, {"text": "\uf193", "id": "fa-wheelchair"}, {"text": "\uf194", "id": "fa-vimeo-square"}, {"text": "\uf195", "id": "fa-try"}, {"text": "\uf196", "id": "fa-plus-square-o"}],
1755 * Initializes select2: in Chrome and Safari, <select> font apparently
1756 * isn't customizable (?) and the fontawesome glyphs fail to appear.
1758 start: function () {
1759 return this._super().then(this.proxy('load_data'));
1761 search: function (needle) {
1762 var icons = this.icons;
1764 icons = _(icons).filter(function (icon) {
1765 return icon.id.substring(3).indexOf(needle) !== -1;
1769 this.$('div.font-icons-icons').html(
1770 openerp.qweb.render(
1771 'website.editor.dialog.font-icons.icons',
1775 * Removes existing FontAwesome classes on the bound element, and sets
1776 * all the new ones if necessary.
1779 var style = this.media.$.attributes.style ? this.media.$.attributes.style.textContent : '';
1780 var classes = (this.media.$.className||"").split(/\s+/);
1781 var non_fa_classes = _.reject(classes, function (cls) {
1782 return cls === 'fa' || /^fa-/.test(cls);
1784 var final_classes = non_fa_classes.concat(this.get_fa_classes());
1785 this.media.$.className = final_classes.join(' ');
1786 this.media.renameNode("span");
1787 this.media.$.attributes.style.textContent = style;
1791 * Looks up the various FontAwesome classes on the bound element and
1792 * sets the corresponding template/form elements to the right state.
1793 * If multiple classes of the same category are present on an element
1794 * (e.g. fa-lg and fa-3x) the last one occurring will be selected,
1795 * which may not match the visual look of the element.
1797 load_data: function () {
1798 var classes = (this.media&&this.media.$.className||"").split(/\s+/);
1799 for (var i = 0; i < classes.length; i++) {
1800 var cls = classes[i];
1802 case 'fa-2x':case 'fa-3x':case 'fa-4x':case 'fa-5x':
1804 this.$('#fa-size').val(cls);
1807 case 'fa-rotate-90':case 'fa-rotate-180':case 'fa-rotate-270':
1808 case 'fa-flip-horizontal':case 'fa-rotate-vertical':
1809 this.$('#fa-rotation').val(cls);
1814 this.$('#fa-border').prop('checked', true);
1817 if (!/^fa-/.test(cls)) { continue; }
1818 this.$('#fa-icon').val(cls);
1821 this.update_preview();
1824 * Serializes the dialog to an array of FontAwesome classes. Includes
1827 get_fa_classes: function () {
1830 this.$('#fa-icon').val(),
1831 this.$('#fa-size').val(),
1832 this.$('#fa-rotation').val(),
1833 this.$('#fa-border').prop('checked') ? 'fa-border' : ''
1836 update_preview: function () {
1837 this.$preview.empty();
1838 var $preview = this.$('#fa-preview').empty();
1840 var sizes = ['', 'fa-2x', 'fa-3x', 'fa-4x', 'fa-5x'];
1841 var classes = this.get_fa_classes();
1842 var no_sizes = _.difference(classes, sizes).join(' ');
1843 var selected = false;
1844 for (var i = sizes.length - 1; i >= 0; i--) {
1845 var size = sizes[i];
1847 var $p = $('<span>')
1848 .attr('data-size', size)
1850 .addClass(no_sizes);
1851 if ((size && _.contains(classes, size)) || (classes[2] === "" && !selected)) {
1852 this.$preview.append($p.clone());
1853 this.$('#fa-size').val(size);
1854 $p.addClass('font-icons-selected');
1857 $preview.prepend($p);
1860 clear: function () {
1861 this.media.$.className = this.media.$.className.replace(/(^|\s)(fa(\s|$)|fa-[^\s]*)/g, ' ');
1865 website.editor.VideoDialog = website.editor.Media.extend({
1866 template: 'website.editor.dialog.video',
1867 events : _.extend({}, website.editor.Dialog.prototype.events, {
1868 'click input#urlvideo ~ button': 'get_video',
1869 'click input#embedvideo ~ button': 'get_embed_video',
1870 'change input#urlvideo': 'change_input',
1871 'keyup input#urlvideo': 'change_input',
1872 'change input#embedvideo': 'change_input',
1873 'keyup input#embedvideo': 'change_input'
1875 start: function () {
1876 this.$iframe = this.$("iframe");
1877 var $media = $(this.media && this.media.$);
1878 if ($media.hasClass("media_iframe_video")) {
1879 var src = $media.data('src');
1880 this.$("input#urlvideo").val(src);
1881 this.$("#autoplay").attr("checked", src.indexOf('autoplay=1') != -1);
1884 return this._super();
1886 change_input: function (e) {
1887 var $input = $(e.target);
1888 var $button = $input.parent().find("button");
1889 if ($input.val() === "") {
1890 $button.addClass("btn-default").removeClass("btn-primary");
1892 $button.removeClass("btn-default").addClass("btn-primary");
1895 get_url: function () {
1896 var video_id = this.$("#video_id").val();
1897 var video_type = this.$("#video_type").val();
1898 switch (video_type) {
1900 return "//www.youtube.com/embed/" + video_id + "?autoplay=" + (this.$("#autoplay").is(":checked") ? 1 : 0);
1902 return "//player.vimeo.com/video/" + video_id + "?autoplay=" + (this.$("#autoplay").is(":checked") ? 1 : 0);
1904 return "//www.dailymotion.com/embed/video/" + video_id + "?autoplay=" + (this.$("#autoplay").is(":checked") ? 1 : 0);
1909 get_embed_video: function (event) {
1910 event.preventDefault();
1911 var embedvideo = this.$("input#embedvideo").val().match(/src=["']?([^"']+)["' ]?/);
1913 this.$("input#urlvideo").val(embedvideo[1]);
1914 this.get_video(event);
1918 get_video: function (event) {
1919 if (event) event.preventDefault();
1920 var needle = this.$("input#urlvideo").val();
1924 if (needle.indexOf(".youtube.") != -1) {
1925 video_type = "youtube";
1926 video_id = needle.match(/\.youtube\.[a-z]+\/(embed\/|watch\?v=)?([^\/?&]+)/i)[2];
1927 } else if (needle.indexOf("//youtu.") != -1) {
1928 video_type = "youtube";
1929 video_id = needle.match(/youtube\.[a-z]+\/([^\/?&]+)/i)[1];
1930 } else if (needle.indexOf("player.vimeo.") != -1 || needle.indexOf("//vimeo.") != -1) {
1931 video_type = "vimeo";
1932 video_id = needle.match(/vimeo\.[a-z]+\/(video\/)?([^?&]+)/i)[2];
1933 } else if (needle.indexOf(".dailymotion.") != -1) {
1934 video_type = "dailymotion";
1935 video_id = needle.match(/dailymotion\.[a-z]+\/(embed\/)?(video\/)?([^\/?&]+)/i)[3];
1941 this.$("#video_id").val(video_id);
1942 this.$("#video_type").val(video_type);
1944 this.$iframe.attr("src", this.get_url());
1948 var video_id = this.$("#video_id").val();
1950 this.$("button.btn-primary").click();
1951 video_id = this.$("#video_id").val();
1953 var video_type = this.$("#video_type").val();
1954 var style = this.media.$.attributes.style ? this.media.$.attributes.style.textContent : '';
1956 '<div class="media_iframe_video" data-src="'+this.get_url()+'" style="'+style+'">'+
1957 '<div class="css_editable_mode_display"> </div>'+
1958 '<iframe src="'+this.get_url()+'" frameborder="0" allowfullscreen="allowfullscreen"></iframe>'+
1960 $(this.media.$).replaceWith($iframe);
1961 this.media.$ = $iframe[0];
1964 clear: function () {
1965 delete this.media.$.dataset.src;
1966 this.media.$.className = this.media.$.className.replace(/(^|\s)media_iframe_video(\s|$)/g, ' ');
1970 website.Observer = window.MutationObserver || window.WebkitMutationObserver || window.JsMutationObserver;
1971 var OBSERVER_CONFIG = {
1974 characterData: true,
1976 attributeOldValue: true,
1978 var observer = new website.Observer(function (mutations) {
1979 // NOTE: Webkit does not fire DOMAttrModified => webkit browsers
1980 // relying on JsMutationObserver shim (Chrome < 18, Safari < 6)
1981 // will not mark dirty on attribute changes (@class, img/@src,
1983 _(mutations).chain()
1984 .filter(function (m) {
1985 // ignore any change related to mundane image-edit-button
1986 if (m.target && m.target.className
1987 && m.target.className.indexOf('image-edit-button') !== -1) {
1991 case 'attributes': // ignore .cke_focus being added or removed
1992 // ignore id modification
1993 if (m.attributeName === 'id') { return false; }
1994 // if attribute is not a class, can't be .cke_focus change
1995 if (m.attributeName !== 'class') { return true; }
1997 // find out what classes were added or removed
1998 var oldClasses = (m.oldValue || '').split(/\s+/);
1999 var newClasses = m.target.className.split(/\s+/);
2000 var change = _.union(_.difference(oldClasses, newClasses),
2001 _.difference(newClasses, oldClasses));
2002 // ignore mutation if the *only* change is .cke_focus
2003 return change.length !== 1 || change[0] === 'cke_focus';
2005 setTimeout(function () {
2006 fixup_browser_crap(m.addedNodes);
2008 // Remove ignorable nodes from addedNodes or removedNodes,
2009 // if either set remains non-empty it's considered to be an
2010 // impactful change. Otherwise it's ignored.
2011 return !!remove_mundane_nodes(m.addedNodes).length ||
2012 !!remove_mundane_nodes(m.removedNodes).length;
2018 var node = m.target;
2019 while (node && !$(node).hasClass('oe_editable')) {
2020 node = node.parentNode;
2026 .each(function (node) { $(node).trigger('content_changed'); })
2028 function remove_mundane_nodes(nodes) {
2029 if (!nodes || !nodes.length) { return []; }
2032 for(var i=0; i<nodes.length; ++i) {
2033 var node = nodes[i];
2034 if (node.nodeType === document.ELEMENT_NODE) {
2035 if (node.nodeName === 'BR' && node.getAttribute('type') === '_moz') {
2036 // <br type="_moz"> appears when focusing RTE in FF, ignore
2038 } else if (node.nodeName === 'DIV' && $(node).hasClass('oe_drop_zone')) {
2039 // ignore dropzone inserted by snippets
2049 var programmatic_styles = {
2058 function fixup_browser_crap(nodes) {
2059 if (!nodes || !nodes.length) { return; }
2061 * Checks that the node only has a @style, not e.g. @class or whatever
2063 function has_only_style(node) {
2064 for (var i = 0; i < node.attributes.length; i++) {
2065 var attr = node.attributes[i];
2066 if (attr.attributeName !== 'style') {
2072 function has_programmatic_style(node) {
2073 for (var i = 0; i < node.style.length; i++) {
2074 var style = node.style[i];
2075 if (programmatic_styles[style]) {
2082 for (var i=0; i<nodes.length; ++i) {
2083 var node = nodes[i];
2084 if (node.nodeType !== document.ELEMENT_NODE) { continue; }
2086 if (node.nodeName === 'SPAN'
2087 && has_only_style(node)
2088 && !has_programmatic_style(node)) {
2089 // On backspace, webkit browsers create a <span> with a bunch of
2090 // inline styles "remembering" where they come from. Refs:
2091 // http://www.neotericdesign.com/blog/2013/3/working-around-chrome-s-contenteditable-span-bug
2092 // https://code.google.com/p/chromium/issues/detail?id=226941
2093 // https://bugs.webkit.org/show_bug.cgi?id=114791
2094 // http://dev.ckeditor.com/ticket/9998
2095 var child, parent = node.parentNode;
2096 while (child = node.firstChild) {
2097 parent.insertBefore(child, node);
2099 parent.removeChild(node);
2100 // chances are we had e.g.
2103 // merged the lines getting this in webkit
2104 // <p>foo<span>bar</span></p>
2105 // after unwrapping the span, we have 2 text nodes
2106 // <p>[foo][bar]</p>
2107 // where we probably want only one. Normalize will merge
2108 // adjacent text nodes. However, does not merge text and cdata