4 var website = openerp.website;
6 website.no_editor = !!$(document.documentElement).data('editable-no-editor');
8 website.add_template_file('/website/static/src/xml/website.editor.xml');
9 website.dom_ready.done(function () {
10 var is_smartphone = $(document.body)[0].clientWidth < 767;
13 website.ready().then(website.init_editor);
15 var resize_smartphone = function () {
16 is_smartphone = $(document.body)[0].clientWidth < 767;
18 $(window).off("resize", resize_smartphone);
19 website.init_editor();
22 $(window).on("resize", resize_smartphone);
25 $(document).on('click', 'a.js_link2post', function (ev) {
27 website.form(this.pathname, 'POST');
30 $(document).on('click', '.cke_editable label', function (ev) {
34 $(document).on('submit', '.cke_editable form', function (ev) {
35 // Disable form submition in editable mode
39 $(document).on('hide.bs.dropdown', '.dropdown', function (ev) {
40 // Prevent dropdown closing when a contenteditable children is focused
42 && $(ev.target).has(ev.originalEvent.target).length
43 && $(ev.originalEvent.target).is('[contenteditable]')) {
50 * An editing host is an HTML element with @contenteditable=true, or the
51 * child of a document in designMode=on (but that one's not supported)
53 * https://dvcs.w3.org/hg/editing/raw-file/tip/editing.html#editing-host
55 function is_editing_host(element) {
56 return element.getAttribute('contentEditable') === 'true';
59 * Checks that both the element's content *and the element itself* are
60 * editable: an editing host is considered non-editable because its content
61 * is editable but its attributes should not be considered editable
63 function is_editable_node(element) {
64 return !(element.data('oe-model') === 'ir.ui.view'
65 || element.data('cke-realelement')
66 || (is_editing_host(element) && element.getAttribute('attributeEditable') !== 'true')
67 || element.isReadOnly());
70 function link_dialog(editor) {
71 return new website.editor.RTELinkDialog(editor).appendTo(document.body);
73 function image_dialog(editor, image) {
74 return new website.editor.MediaDialog(editor, image).appendTo(document.body);
77 // only enable editors manually
78 CKEDITOR.disableAutoInline = true;
79 // EDIT ALL THE THINGS
80 CKEDITOR.dtd.$editable = _.omit(
81 $.extend({}, CKEDITOR.dtd.$block, CKEDITOR.dtd.$inline),
82 // well maybe not *all* the things
83 'ul', 'ol', 'li', 'table', 'tr', 'th', 'td');
84 // Disable removal of empty elements on CKEDITOR activation. Empty
85 // elements are used for e.g. support of FontAwesome icons
86 CKEDITOR.dtd.$removeEmpty = {};
89 website.init_editor = function () {
90 CKEDITOR.plugins.add('customdialogs', {
91 // requires: 'link,image',
92 init: function (editor) {
93 editor.on('doubleclick', function (evt) {
94 var element = evt.data.element;
95 if ((element.is('img') || element.$.className.indexOf(' fa-') != -1) && is_editable_node(element)) {
96 image_dialog(editor, element);
99 var parent = new CKEDITOR.dom.element(element.$.parentNode);
100 if (parent.$.className.indexOf('media_iframe_video') != -1 && is_editable_node(parent)) {
101 image_dialog(editor, parent);
105 element = get_selected_link(editor) || evt.data.element;
106 if (!(element.is('a') && is_editable_node(element))) {
110 editor.getSelection().selectElement(element);
114 //noinspection JSValidateTypes
115 editor.addCommand('link', {
116 exec: function (editor) {
124 //noinspection JSValidateTypes
125 editor.addCommand('cimage', {
126 exec: function (editor) {
127 image_dialog(editor);
135 editor.ui.addButton('Link', {
140 editor.ui.addButton('Image', {
143 toolbar: 'insert,10',
146 editor.setKeystroke(CKEDITOR.CTRL + 76 /*L*/, 'link');
149 CKEDITOR.plugins.add( 'tablebutton', {
150 requires: 'panelbutton,floatpanel',
151 init: function( editor ) {
154 editor.ui.add('TableButton', CKEDITOR.UI_PANELBUTTON, {
157 // use existing 'table' icon
159 modes: { wysiwyg: true },
161 // panel opens in iframe, @css is CSS file <link>-ed within
162 // frame document, @attributes are set on iframe itself.
164 css: '/website/static/src/css/editor.css',
165 attributes: { 'role': 'listbox', 'aria-label': label, },
168 onBlock: function (panel, block) {
169 block.autoSize = true;
170 block.element.setHtml(openerp.qweb.render('website.editor.table.panel', {
175 var $table = $(block.element.$).on('mouseenter', 'td', function (e) {
176 var $e = $(e.target);
177 var y = $e.index() + 1;
178 var x = $e.closest('tr').index() + 1;
181 .find('td').removeClass('selected').end()
182 .find('tr:lt(' + String(x) + ')')
183 .children().filter(function () { return $(this).index() < y; })
184 .addClass('selected');
185 }).on('click', 'td', function (e) {
186 var $e = $(e.target);
188 //noinspection JSPotentiallyInvalidConstructorUsage
189 var table = new CKEDITOR.dom.element(
190 $(openerp.qweb.render('website.editor.table', {
191 rows: $e.closest('tr').index() + 1,
192 cols: $e.index() + 1,
195 editor.insertElement(table);
196 setTimeout(function () {
197 //noinspection JSPotentiallyInvalidConstructorUsage
198 var firstCell = new CKEDITOR.dom.element(table.$.rows[0].cells[0]);
199 var range = editor.createRange();
200 range.moveToPosition(firstCell, CKEDITOR.POSITION_AFTER_START);
205 block.element.getDocument().getBody().setStyle('overflow', 'hidden');
206 CKEDITOR.ui.fire('ready', this);
212 CKEDITOR.plugins.add('oeref', {
215 init: function (editor) {
217 // Can't find the correct ACL rule to only allow img tags
218 image: { content: '*' },
222 selector: 'span.oe_currency_value',
227 _(specials).each(function (editable, type) {
228 editor.widgets.add(type, {
231 upcast: function (el) {
232 return el.attributes['data-oe-type'] === type;
237 editor.widgets.add('oeref', {
245 upcast: function (el) {
246 var type = el.attributes['data-oe-type'];
247 if (!type || (type in specials)) {
250 if (el.attributes['data-oe-original']) {
251 while (el.children.length) {
252 el.children[0].remove();
254 el.add(new CKEDITOR.htmlParser.text(
255 el.attributes['data-oe-original']
262 editor.widgets.add('icons', {
266 this.on('edit', function () {
267 new website.editor.MediaDialog(editor, this.element)
268 .appendTo(document.body);
271 upcast: function (el) {
272 return el.hasClass('fa')
273 // ignore ir.ui.view (other data-oe-model should
274 // already have been matched by oeref and
276 && !el.attributes['data-oe-model'];
282 var editor = new website.EditorBar();
283 var $body = $(document.body);
284 editor.prependTo($body).then(function () {
285 if (location.search.indexOf("enable_editor") >= 0) {
289 website.editor_bar = editor;
292 /* ----- TOP EDITOR BAR FOR ADMIN ---- */
293 website.EditorBar = openerp.Widget.extend({
294 template: 'website.editorbar',
296 'click button[data-action=save]': 'save',
297 'click a[data-action=cancel]': 'cancel',
301 this.saving_mutex = new openerp.Mutex();
304 edit: this.$el.parents().find('button[data-action=edit]'),
305 save: this.$('button[data-action=save]'),
306 cancel: this.$('button[data-action=cancel]'),
309 this.$('#website-top-edit').hide();
310 this.$('#website-top-view').show();
311 this.$buttons.edit.show();
313 var $edit_button = this.$buttons.edit
314 .prop('disabled', website.no_editor);
315 if (website.no_editor) {
316 var help_text = $(document.documentElement).data('editable-no-editor');
317 $edit_button.parent()
318 // help must be set on form above button because it does
319 // not appear on disabled button
320 .attr('title', help_text);
323 $('.dropdown-toggle').dropdown();
325 this.$buttons.edit.click(function(ev) {
329 this.rte = new website.RTE(this);
330 this.rte.on('change', this, this.proxy('rte_changed'));
331 this.rte.on('rte:ready', this, function () {
332 self.setup_hover_buttons();
333 self.trigger('rte:ready');
336 this.rte.appendTo(this.$('#website-top-edit .nav.js_editor_placeholder'));
337 return this._super.apply(this, arguments);
341 this.$buttons.edit.prop('disabled', true);
342 this.$('#website-top-view').hide();
344 this.$('#website-top-edit').show();
345 $('.css_non_editable_mode_hidden').removeClass("css_non_editable_mode_hidden");
347 this.rte.start_edition();
348 this.trigger('rte:called');
350 rte_changed: function () {
351 this.$buttons.save.prop('disabled', false);
356 observer.disconnect();
357 var editor = this.rte.editor;
358 var root = editor.element && editor.element.$;
363 // Hack to avoid the lost of all changes because ckeditor fails in destroy
364 console.log("Error in editor.destroy() : " + err.toString() + "\n " + err.stack);
366 // FIXME: select editables then filter by dirty?
367 var defs = this.rte.fetch_editables(root)
369 .removeAttr('contentEditable')
370 .removeClass('oe_dirty oe_editable cke_focus oe_carlos_danger')
373 // TODO: Add a queue with concurrency limit in webclient
374 // https://github.com/medikoo/deferred/blob/master/lib/ext/function/gate.js
375 return self.saving_mutex.exec(function () {
376 return self.saveElement($el)
377 .then(undefined, function (thing, response) {
378 // because ckeditor regenerates all the dom,
379 // we can't just setup the popover here as
380 // everything will be destroyed by the DOM
381 // regeneration. Add markings instead, and
382 // returns a new rejection with all relevant
384 var id = _.uniqueId('carlos_danger_');
385 $el.addClass('oe_dirty oe_carlos_danger');
387 return $.Deferred().reject({
389 error: response.data,
394 return $.when.apply(null, defs).then(function () {
396 }, function (failed) {
397 // If there were errors, re-enable edition
398 self.rte.start_edition(true).then(function () {
399 // jquery's deferred being a pain in the ass
400 if (!_.isArray(failed)) { failed = [failed]; }
402 _(failed).each(function (failure) {
403 var html = failure.error.exception_type === "except_osv";
405 var msg = $("<div/>").text(failure.error.message).html();
406 var data = msg.substring(3,msg.length-2).split(/', u'/);
407 failure.error.message = '<b>' + data[0] + '</b><br/>' + data[1];
409 $(root).find('.' + failure.id)
410 .removeClass(failure.id)
414 content: failure.error.message,
415 placement: 'auto top',
417 // Force-show popovers so users will notice them.
424 * Saves an RTE content, which always corresponds to a view section (?).
426 saveElement: function ($el) {
427 var markup = $el.prop('outerHTML');
428 return openerp.jsonRpc('/web/dataset/call', 'call', {
431 args: [$el.data('oe-id'), markup,
432 $el.data('oe-xpath') || null,
433 website.get_context()],
436 cancel: function () {
437 new $.Deferred(function (d) {
438 var $dialog = $(openerp.qweb.render('website.editor.discard')).appendTo(document.body);
439 $dialog.on('click', '.btn-danger', function () {
441 }).on('hidden.bs.modal', function () {
444 d.always(function () {
447 $dialog.modal('show');
448 }).then(function () {
454 * Creates a "hover" button for link edition
456 * @param {Function} editfn edition function, called when clicking the button
459 make_hover_button_link: function (editfn) {
460 return $(openerp.qweb.render('website.editor.hoverbutton.link', {}))
462 .click(function (e) {
465 editfn.call(this, e);
467 .appendTo(document.body);
471 * Creates a "hover" button for image
473 * @param {Function} editfn edition function, called when clicking the button
474 * @param {Function} stylefn edition style function, called when clicking the button
477 make_hover_button_image: function (editfn, stylefn) {
478 var $div = $(openerp.qweb.render('website.editor.hoverbutton.media', {}))
480 .appendTo(document.body);
482 $div.find('[data-toggle="dropdown"]').dropdown();
483 $div.find(".hover-edition-button").click(function (e) {
486 editfn.call(this, e);
489 $div.find(".hover-style-button").click(function (e) {
492 stylefn.call(this, e);
498 * For UI clarity, during RTE edition when the user hovers links and
499 * images a small button should appear to make the capability clear,
500 * as not all users think of double-clicking the image or link.
502 setup_hover_buttons: function () {
503 var editor = this.rte.editor;
504 var $link_button = this.make_hover_button_link(function () {
505 var sel = new CKEDITOR.dom.element(previous);
506 editor.getSelection().selectElement(sel);
507 if(sel.hasClass('fa')) {
508 new website.editor.MediaDialog(editor, previous)
509 .appendTo(document.body);
510 } else if (previous.tagName.toUpperCase() === 'A') {
517 function is_icons_widget(element) {
518 var w = editor.widgets.getByElement(element);
519 return w && w.name === 'icons';
522 // previous is the state of the button-trigger: it's the
523 // currently-ish hovered element which can trigger a button showing.
524 // -ish, because when moving to the button itself ``previous`` is
525 // still set to the element having triggered showing the button.
527 $(editor.element.$).on('mouseover', 'a', function () {
528 // Back from edit button -> ignore
529 if (previous && previous === this) { return; }
531 // hover button should appear for "editable" links and images
532 // (img and a nodes whose *attributes* are editable, they
533 // can not be "editing hosts") *or* for non-editing-host
534 // elements bearing an ``fa`` class. These should have been
535 // made into CKE widgets which are editing hosts by
536 // definition, so instead check if the element has been
537 // converted/upcasted to an fa widget
538 var selected = new CKEDITOR.dom.element(this);
539 if (!(is_editable_node(selected) || is_icons_widget(selected))) {
544 var $selected = $(this);
545 var position = $selected.offset();
546 $link_button.show().offset({
547 top: $selected.outerHeight()
549 left: $selected.outerWidth() / 2
551 - $link_button.outerWidth() / 2
553 }).on('mouseleave', 'a, img, .fa', function (e) {
554 var current = document.elementFromPoint(e.clientX, e.clientY);
555 if (current === $link_button[0] || $(current).parent()[0] === $link_button[0]) {
564 website.EditorBarCustomize = openerp.Widget.extend({
566 'mousedown a.dropdown-toggle': 'load_menu',
567 'click ul a[data-action!=ace]': 'do_customize',
571 this.$menu = self.$el.find('ul');
572 this.view_name = $(document.documentElement).data('view-xmlid');
573 if (!this.view_name) {
578 load_menu: function () {
583 openerp.jsonRpc('/website/customize_template_get', 'call', { 'xml_id': this.view_name }).then(
585 _.each(result, function (item) {
586 if (item.xml_id === "website.debugger" && !window.location.search.match(/[&?]debug(&|$)/)) return;
588 self.$menu.append('<li class="dropdown-header">' + item.name + '</li>');
590 self.$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>',
591 item.id, item.active ? '-check' : '', item.name));
598 do_customize: function (event) {
599 var view_id = $(event.currentTarget).data('view-id');
600 return openerp.jsonRpc('/web/dataset/call_kw', 'call', {
605 ids: [parseInt(view_id, 10)],
606 context: website.get_context()
608 }).then( function() {
609 window.location.reload();
614 $(document).ready(function() {
615 var editorBarCustomize = new website.EditorBarCustomize();
616 editorBarCustomize.setElement($('li[id=customize-menu]'));
617 editorBarCustomize.start();
620 var blocks_selector = _.keys(CKEDITOR.dtd.$block).join(',');
621 /* ----- RICH TEXT EDITOR ---- */
622 website.RTE = openerp.Widget.extend({
624 id: 'oe_rte_toolbar',
625 className: 'oe_right oe_rte_toolbar',
626 // editor.ui.items -> possible commands &al
627 // editor.applyStyle(new CKEDITOR.style({element: "span",styles: {color: "#(color)"},overrides: [{element: "font",attributes: {color: null}}]}, {color: '#ff0000'}));
629 init: function (EditorBar) {
630 this.EditorBar = EditorBar;
631 this._super.apply(this, arguments);
635 * In Webkit-based browsers, triple-click will select a paragraph up to
636 * the start of the next "paragraph" including any empty space
637 * inbetween. When said paragraph is removed or altered, it nukes
638 * the empty space and brings part of the content of the next
639 * "paragraph" (which may well be e.g. an image) into the current one,
640 * completely fucking up layouts and breaking snippets.
642 * Try to fuck around with selections on triple-click to attempt to
643 * fix this garbage behavior.
645 * Note: for consistent behavior we may actually want to take over
646 * triple-clicks, in all browsers in order to ensure consistent cross-
647 * platform behavior instead of being at the mercy of rendering engines
648 * & platform selection quirks?
650 webkitSelectionFixer: function (root) {
651 root.addEventListener('click', function (e) {
652 // only webkit seems to have a fucked up behavior, ignore others
653 // FIXME: $.browser goes away in jquery 1.9...
654 if (!$.browser.webkit) { return; }
655 // http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-eventgroupings-mouseevents
656 // The detail attribute indicates the number of times a mouse button has been pressed
657 // we just want the triple click
658 if (e.detail !== 3) { return; }
661 // Get closest block-level element to the triple-clicked
662 // element (using ckeditor's block list because why not)
663 var $closest_block = $(e.target).closest(blocks_selector);
665 // manually set selection range to the content of the
666 // triple-clicked block-level element, to avoid crossing over
667 // between block-level elements
668 document.getSelection().selectAllChildren($closest_block[0]);
671 tableNavigation: function (root) {
673 $(root).on('keydown', function (e) {
675 if (e.which !== 9) { return; }
677 if (self.handleTab(e)) {
683 * Performs whatever operation is necessary on a [TAB] hit, returns
684 * ``true`` if the event's default should be cancelled (if the TAB was
685 * handled by the function)
687 handleTab: function (event) {
688 var forward = !event.shiftKey;
690 var root = window.getSelection().getRangeAt(0).commonAncestorContainer;
691 var $cell = $(root).closest('td,th');
693 if (!$cell.length) { return false; }
697 // find cell in same row
698 var row = cell.parentNode;
699 var sibling = row.cells[cell.cellIndex + (forward ? 1 : -1)];
701 document.getSelection().selectAllChildren(sibling);
705 // find cell in previous/next row
706 var table = row.parentNode;
707 var sibling_row = table.rows[row.rowIndex + (forward ? 1 : -1)];
709 var new_cell = sibling_row.cells[forward ? 0 : sibling_row.cells.length - 1];
710 document.getSelection().selectAllChildren(new_cell);
714 // at edge cells, copy word/openoffice behavior: if going backwards
715 // from first cell do nothing, if going forwards from last cell add
718 var row_size = row.cells.length;
719 var new_row = document.createElement('tr');
721 var newcell = document.createElement('td');
723 newcell.textContent = '\u200B';
724 new_row.appendChild(newcell);
726 table.appendChild(new_row);
727 document.getSelection().selectAllChildren(new_row.cells[0]);
733 * Makes the page editable
735 * @param {Boolean} [restart=false] in case the edition was already set
736 * up once and is being re-enabled.
737 * @returns {$.Deferred} deferred indicating when the RTE is ready
739 start_edition: function (restart) {
741 // create a single editor for the whole page
742 var root = document.getElementById('wrapwrap');
744 $(root).on('dragstart', 'img', function (e) {
747 this.webkitSelectionFixer(root);
748 this.tableNavigation(root);
750 var def = $.Deferred();
751 var editor = this.editor = CKEDITOR.inline(root, self._config());
752 editor.on('instanceReady', function () {
753 editor.setReadOnly(false);
754 // ckeditor set root to editable, disable it (only inner
755 // sections are editable)
756 // FIXME: are there cases where the whole editor is editable?
757 editor.editable().setReadOnly(true);
759 self.setup_editables(root);
762 // disable firefox's broken table resizing thing
763 document.execCommand("enableObjectResizing", false, "false");
764 document.execCommand("enableInlineTableEditing", false, "false");
767 // detect & setup any CKEDITOR widget within a newly dropped
768 // snippet. There does not seem to be a simple way to do it for
769 // HTML not inserted via ckeditor APIs:
770 // https://dev.ckeditor.com/ticket/11472
772 .off('snippet-dropped')
773 .on('snippet-dropped', function (e, el) {
774 // CKEDITOR data processor extended by widgets plugin
775 // to add wrappers around upcasting elements
776 el.innerHTML = editor.dataProcessor.toHtml(el.innerHTML, {
780 // then repository.initOnAll() handles the conversion
781 // from wrapper to actual widget instance (or something
783 setTimeout(function () {
784 editor.widgets.initOnAll();
788 self.trigger('rte:ready');
794 setup_editables: function (root) {
795 // selection of editable sub-items was previously in
796 // EditorBar#edit, but for some unknown reason the elements were
797 // apparently removed and recreated (?) at editor initalization,
798 // and observer setup was lost.
800 // setup dirty-marking for each editable element
801 this.fetch_editables(root)
802 .addClass('oe_editable')
806 // only explicitly set contenteditable on view sections,
807 // cke widgets system will do the widgets themselves
808 if ($node.data('oe-model') === 'ir.ui.view') {
809 node.contentEditable = true;
812 observer.observe(node, OBSERVER_CONFIG);
813 $node.one('content_changed', function () {
814 $node.addClass('oe_dirty');
815 self.trigger('change');
820 fetch_editables: function (root) {
821 return $(root).find('[data-oe-model]')
823 .not('.oe_snippet_editor')
824 .filter(function () {
826 // keep view sections and fields which are *not* in
827 // view sections for top-level editables
828 return $this.data('oe-model') === 'ir.ui.view'
829 || !$this.closest('[data-oe-model = "ir.ui.view"]').length;
833 _current_editor: function () {
834 return CKEDITOR.currentInstance;
836 _config: function () {
837 // base plugins minus
838 // - magicline (captures mousein/mouseout -> breaks draggable)
839 // - contextmenu & tabletools (disable contextual menu)
840 // - bunch of unused plugins
842 'a11yhelp', 'basicstyles', 'blockquote',
843 'clipboard', 'colorbutton', 'colordialog', 'dialogadvtab',
844 'elementspath', /*'enterkey',*/ 'entities', 'filebrowser',
845 'find', 'floatingspace','format', 'htmlwriter', 'iframe',
846 'indentblock', 'indentlist', 'justify',
847 'list', 'pastefromword', 'pastetext', 'preview',
848 'removeformat', 'resize', 'save', 'selectall', 'stylescombo',
849 'table', 'templates', 'toolbar', 'undo', 'wysiwygarea'
854 // Disable auto-generated titles
855 // FIXME: accessibility, need to generate user-sensible title, used for @title and @aria-label
857 plugins: plugins.join(','),
859 // FIXME: currently breaks RTE?
860 // Ensure no config file is loaded
863 allowedContent: true,
864 // Don't insert paragraphs around content in e.g. <li>
865 autoParagraph: false,
866 // Don't automatically add or <br> in empty block-level
867 // elements when edition starts
868 fillEmptyBlocks: false,
869 filebrowserImageUploadUrl: "/website/attach",
870 // Support for sharedSpaces in 4.x
871 extraPlugins: 'sharedspace,customdialogs,tablebutton,oeref',
872 // Place toolbar in controlled location
873 sharedSpaces: { top: 'oe_rte_toolbar' },
875 name: 'basicstyles', items: [
876 "Bold", "Italic", "Underline", "Strike", "Subscript",
877 "Superscript", "TextColor", "BGColor", "RemoveFormat"
879 name: 'span', items: [
880 "Link", "Blockquote", "BulletedList",
881 "NumberedList", "Indent", "Outdent"
883 name: 'justify', items: [
884 "JustifyLeft", "JustifyCenter", "JustifyRight", "JustifyBlock"
886 name: 'special', items: [
887 "Image", "TableButton"
889 name: 'styles', items: [
893 // styles dropdown in toolbar
895 {name: "Normal", element: 'p'},
896 {name: "Heading 1", element: 'h1'},
897 {name: "Heading 2", element: 'h2'},
898 {name: "Heading 3", element: 'h3'},
899 {name: "Heading 4", element: 'h4'},
900 {name: "Heading 5", element: 'h5'},
901 {name: "Heading 6", element: 'h6'},
902 {name: "Formatted", element: 'pre'},
903 {name: "Address", element: 'address'}
909 website.editor = { };
910 website.editor.Dialog = openerp.Widget.extend({
912 'hidden.bs.modal': 'destroy',
913 'click button.save': 'save',
914 'click button[data-dismiss="modal"]': 'cancel',
916 init: function (editor) {
918 this.editor = editor;
921 var sup = this._super();
922 this.$el.modal({backdrop: 'static'});
923 this.$('input:first').focus();
928 this.trigger("saved");
930 cancel: function () {
931 this.trigger("cancel");
934 this.$el.modal('hide');
938 website.editor.LinkDialog = website.editor.Dialog.extend({
939 template: 'website.editor.dialog.link',
940 events: _.extend({}, website.editor.Dialog.prototype.events, {
941 'change :input.url-source': 'changed',
942 'keyup :input.url': 'onkeyup',
943 'keyup :input': 'preview',
944 'mousedown': function (e) {
945 var $target = $(e.target).closest('.list-group-item:has(.url-source)');
946 if (!$target.length || $target.hasClass('active')) {
947 // clicked outside groups, or clicked in active groups
950 $target.find("input.url-source").change();
952 'click button.remove': 'remove_link',
953 'change input#link-text': function (e) {
954 this.text = $(e.target).val();
956 'change .link-style': function (e) {
960 init: function (editor) {
963 // Store last-performed request to be able to cancel/abort it.
964 this.page_exists_req = null;
965 this.search_pages_req = null;
970 this.$('#link-page').select2({
971 minimumInputLength: 1,
972 placeholder: _t("New or existing page"),
973 query: function (q) {
974 if (q.term == last) return;
977 self.page_exists(q.term),
978 self.fetch_pages(q.term)
979 ).then(function (exists, results) {
980 var rs = _.map(results, function (r) {
981 return { id: r.loc, text: r.loc, };
987 text: _.str.sprintf(_t("Create page '%s'"), q.term),
995 q.callback({more: false, results: []});
999 return this._super().then(this.proxy('bind_data'));
1001 get_data: function (test) {
1003 def = new $.Deferred(),
1004 $e = this.$('.active input.url-source').filter(':input'),
1006 label = this.$('#link-text').val() || val;
1008 if (test !== false && (!val || !$e[0].checkValidity())) {
1009 // FIXME: error message
1010 $e.closest('.form-group').addClass('has-error');
1015 var style = this.$("input[name='link-style-type']:checked").val();
1016 var size = this.$("input[name='link-style-size']:checked").val();
1017 var classes = (style && style.length ? "btn " : "") + style + " " + size;
1019 if ($e.hasClass('email-address') && $e.val().indexOf("@") !== -1) {
1020 def.resolve('mailto:' + val, false, label);
1021 } else if ($e.val() && $e.val().length && $e.hasClass('page')) {
1022 var data = $e.select2('data');
1024 def.resolve(data.id, false, data.text);
1026 // Create the page, get the URL back
1027 $.get(_.str.sprintf(
1028 '/website/add/%s?noredirect=1', encodeURI(data.id)))
1029 .then(function (response) {
1030 def.resolve(response, false, data.id);
1034 def.resolve(val, this.$('input.window-new').prop('checked'), label, classes);
1040 var _super = this._super.bind(this);
1041 return this.get_data()
1042 .then(function (url, new_window, label, classes) {
1043 self.make_link(url, new_window, label, classes);
1046 make_link: function (url, new_window, label, classes) {
1048 bind_data: function () {
1049 var href = this.element && (this.element.data( 'cke-saved-href')
1050 || this.element.getAttribute('href'));
1051 var new_window = this.element
1052 ? this.element.getAttribute('target') === '_blank'
1054 var text = this.element ? this.element.getText() : '';
1056 var selection = this.editor.getSelection();
1057 text = selection.getSelectedText();
1060 this.$('input#link-text').val(text);
1061 this.$('input.window-new').prop('checked', new_window);
1063 var classes = this.element && this.element.$.className;
1065 this.$('input[value!=""]').each(function () {
1066 var $option = $(this);
1067 if (classes.indexOf($option.val()) !== -1) {
1068 $option.attr("checked", "checked");
1073 var match, $control;
1074 if (href && (match = /mailto:(.+)/.exec(href))) {
1075 this.$('input.email-address').val(match[1]).change();
1077 if (href && !$control) {
1078 this.$('input.url').val(href).change();
1079 this.$('input.window-new').closest("div").show();
1083 changed: function (e) {
1084 var $e = $(e.target);
1085 this.$('.url-source').filter(':input').not($e).val('')
1086 .filter(function () { return !!$(this).data('select2'); })
1087 .select2('data', null);
1088 $e.closest('.list-group-item')
1090 .siblings().removeClass('active')
1091 .addBack().removeClass('has-error');
1094 call: function (method, args, kwargs) {
1096 var req = method + '_req';
1098 if (this[req]) { this[req].abort(); }
1100 return this[req] = openerp.jsonRpc('/web/dataset/call_kw', 'call', {
1105 }).always(function () {
1109 page_exists: function (term) {
1110 return this.call('page_exists', [null, term], {
1111 context: website.get_context(),
1114 fetch_pages: function (term) {
1115 return this.call('search_pages', [null, term], {
1117 context: website.get_context(),
1120 onkeyup: function (e) {
1121 var $e = $(e.target);
1122 var is_link = ($e.val()||'').length && $e.val().indexOf("@") === -1;
1123 this.$('input.window-new').closest("div").toggle(is_link);
1126 preview: function () {
1127 var $preview = this.$("#link-preview");
1128 this.get_data(false).then(function (url, new_window, label, classes) {
1129 $preview.attr("target", new_window ? '_blank' : "")
1130 .text((label && label.length ? label : url))
1131 .attr("class", classes);
1135 website.editor.RTELinkDialog = website.editor.LinkDialog.extend({
1136 start: function () {
1138 if ((element = this.get_selected_link()) && element.hasAttribute('href')) {
1139 this.editor.getSelection().selectElement(element);
1141 this.element = element;
1143 this.add_removal_button();
1146 return this._super();
1148 add_removal_button: function () {
1149 this.$('.modal-footer').prepend(
1150 openerp.qweb.render(
1151 'website.editor.dialog.link.footer-button'));
1153 remove_link: function () {
1154 var editor = this.editor;
1155 // same issue as in make_link
1156 setTimeout(function () {
1157 editor.removeStyle(new CKEDITOR.style({
1159 type: CKEDITOR.STYLE_INLINE,
1160 alwaysRemoveElement: true,
1166 * Greatly simplified version of CKEDITOR's
1167 * plugins.link.dialogs.link.onOk.
1169 * @param {String} url
1170 * @param {Boolean} [new_window=false]
1171 * @param {String} [label=null]
1173 make_link: function (url, new_window, label, classes) {
1174 var attributes = {href: url, 'data-cke-saved-href': url};
1177 attributes['target'] = '_blank';
1179 to_remove.push('target');
1181 if (classes && classes.length) {
1182 attributes['class'] = classes;
1186 this.element.setAttributes(attributes);
1187 this.element.removeAttributes(to_remove);
1188 if (this.text) { this.element.setText(this.text); }
1190 var selection = this.editor.getSelection();
1191 var range = selection.getRanges(true)[0];
1193 if (range.collapsed) {
1194 //noinspection JSPotentiallyInvalidConstructorUsage
1195 var text = new CKEDITOR.dom.text(
1196 this.text || label || url);
1197 range.insertNode(text);
1198 range.selectNodeContents(text);
1201 //noinspection JSPotentiallyInvalidConstructorUsage
1202 new CKEDITOR.style({
1203 type: CKEDITOR.STYLE_INLINE,
1205 attributes: attributes,
1206 }).applyToRange(range);
1208 // focus dance between RTE & dialog blow up the stack in Safari
1209 // and Chrome, so defer select() until dialog has been closed
1210 setTimeout(function () {
1216 * CKEDITOR.plugins.link.getSelectedLink ignores the editor's root,
1217 * if the editor is set directly on a link it will thus not work.
1219 get_selected_link: function () {
1220 return get_selected_link(this.editor);
1224 website.editor.Media = openerp.Widget.extend({
1225 init: function (parent, editor, media) {
1227 this.parent = parent;
1228 this.editor = editor;
1231 start: function () {
1232 this.$preview = this.$('.preview-container').detach();
1233 return this._super();
1235 search: function (needle) {
1239 clear: function () {
1241 cancel: function () {
1243 close: function () {
1246 website.editor.MediaDialog = website.editor.Dialog.extend({
1247 template: 'website.editor.dialog.media',
1248 events : _.extend({}, website.editor.Dialog.prototype.events, {
1249 'input input#icon-search': 'search',
1252 init: function (editor, media) {
1253 this._super(editor);
1254 this.editor = editor;
1258 start: function () {
1261 this.imageDialog = new website.editor.RTEImageDialog(this, this.editor, this.media);
1262 this.imageDialog.appendTo(this.$("#editor-media-image"));
1263 this.iconDialog = new website.editor.FontIconsDialog(this, this.editor, this.media);
1264 this.iconDialog.appendTo(this.$("#editor-media-icon"));
1265 this.videoDialog = new website.editor.VideoDialog(this, this.editor, this.media);
1266 this.videoDialog.appendTo(this.$("#editor-media-video"));
1268 this.active = this.imageDialog;
1270 $('a[data-toggle="tab"]').on('shown.bs.tab', function (event) {
1271 if ($(event.target).is('[href="#editor-media-image"]')) {
1272 self.active = self.imageDialog;
1273 self.$('li.search, li.previous, li.next').removeClass("hidden");
1274 } else if ($(event.target).is('[href="#editor-media-icon"]')) {
1275 self.active = self.iconDialog;
1276 self.$('li.search, li.previous, li.next').removeClass("hidden");
1277 self.$('.nav-tabs li.previous, .nav-tabs li.next').addClass("hidden");
1278 } else if ($(event.target).is('[href="#editor-media-video"]')) {
1279 self.active = self.videoDialog;
1280 self.$('.nav-tabs li.search').addClass("hidden");
1285 if (this.media.$.nodeName === "IMG") {
1286 this.$('[href="#editor-media-image"]').tab('show');
1287 } else if (this.media.$.className.match(/(^|\s)media_iframe_video($|\s)/)) {
1288 this.$('[href="#editor-media-video"]').tab('show');
1289 } else if (this.media.$.className.match(/(^|\s)fa($|\s)/)) {
1290 this.$('[href="#editor-media-icon"]').tab('show');
1293 if ($(this.media.$).parent().data("oe-field") === "image") {
1294 this.$('[href="#editor-media-video"], [href="#editor-media-icon"]').addClass('hidden');
1298 return this._super();
1303 this.media.$.innerHTML = "";
1304 if (this.active !== this.imageDialog) {
1305 this.imageDialog.clear();
1307 if (this.active !== this.iconDialog) {
1308 this.iconDialog.clear();
1310 if (this.active !== this.videoDialog) {
1311 this.videoDialog.clear();
1314 var selection = this.editor.getSelection();
1315 var range = selection.getRanges(true)[0];
1316 this.media = new CKEDITOR.dom.element("img");
1317 range.insertNode(this.media);
1318 range.selectNodeContents(this.media);
1319 this.active.media = this.media;
1322 var $el = $(self.active.media.$);
1326 this.media.$.className = this.media.$.className.replace(/\s+/g, ' ');
1328 setTimeout(function () {
1329 $el.trigger("saved", self.active.media.$);
1330 $(document.body).trigger("media-saved", [$el[0], self.active.media.$]);
1336 search: function () {
1338 var needle = this.$("input#icon-search").val();
1339 clearTimeout(this.searchTimer);
1340 this.searchTimer = setTimeout(function () {
1341 self.active.search(needle || "");
1347 * ImageDialog widget. Lets users change an image, including uploading a
1348 * new image in OpenERP or selecting the image style (if supported by
1351 * Initialized as usual, but the caller can hook into two events:
1353 * @event start({url, style}) called during dialog initialization and
1354 * opening, the handler can *set* the ``url``
1355 * and ``style`` properties on its parameter
1356 * to provide these as default values to the
1358 * @event save({url, style}) called during dialog finalization, the handler
1359 * is provided with the image url and style
1360 * selected by the users (or possibly the ones
1361 * originally passed in)
1363 var IMAGES_PER_ROW = 6;
1364 var IMAGES_ROWS = 2;
1365 website.editor.ImageDialog = website.editor.Media.extend({
1366 template: 'website.editor.dialog.image',
1367 events: _.extend({}, website.editor.Dialog.prototype.events, {
1368 'change .url-source': function (e) {
1369 this.changed($(e.target));
1371 'click button.filepicker': function () {
1372 this.$('input[type=file]').click();
1374 'change input[type=file]': 'file_selection',
1375 'submit form': 'form_submit',
1376 'change input.url': "change_input",
1377 'keyup input.url': "change_input",
1378 //'change select.image-style': 'preview_image',
1379 'click .existing-attachments img': 'select_existing',
1380 'click .existing-attachment-remove': 'try_remove',
1383 init: function (parent, editor, media) {
1385 this._super(parent, editor, media);
1387 start: function () {
1389 var res = this._super();
1391 var o = { url: null };
1392 // avoid typos, prevent addition of new properties to the object
1393 Object.preventExtensions(o);
1394 this.trigger('start', o);
1396 this.parent.$(".pager > li").click(function (e) {
1398 var $target = $(e.currentTarget);
1399 if ($target.hasClass('disabled')) {
1402 self.page += $target.hasClass('previous') ? -1 : 1;
1403 self.display_attachments();
1406 this.set_image(o.url);
1412 this.link = this.$(".existing-attachments img:first").attr('src');
1414 this.trigger('save', {
1417 this.media.renameNode("img");
1418 $(this.media).attr('src', this.link);
1419 return this._super();
1421 clear: function () {
1422 this.media.$.className = this.media.$.className.replace(/(^|\s)(img(\s|$)|img-[^\s]*)/g, ' ');
1424 cancel: function () {
1425 this.trigger('cancel');
1428 change_input: function (e) {
1429 var $input = $(e.target);
1430 var $button = $input.parent().find("button");
1431 if ($input.val() === "") {
1432 $button.addClass("btn-default").removeClass("btn-primary");
1434 $button.removeClass("btn-default").addClass("btn-primary");
1438 search: function (needle) {
1440 this.fetch_existing(needle).then(function () {
1441 self.selected_existing(self.$('input.url').val());
1445 set_image: function (url, error) {
1447 if (url) this.link = url;
1448 this.$('input.url').val('');
1449 this.fetch_existing().then(function () {
1450 self.selected_existing(url);
1454 form_submit: function (event) {
1456 var $form = this.$('form[action="/website/attach"]');
1457 if (!$form.find('input[name="upload"]').val().length) {
1458 var url = $form.find('input[name="url"]').val();
1459 if (this.selected_existing(url).size()) {
1460 event.preventDefault();
1464 var callback = _.uniqueId('func_');
1465 this.$('input[name=func]').val(callback);
1466 window[callback] = function (url, error) {
1467 delete window[callback];
1468 self.file_selected(url, error);
1471 file_selection: function () {
1472 this.$el.addClass('nosave');
1473 this.$('form').removeClass('has-error').find('.help-block').empty();
1474 this.$('button.filepicker').removeClass('btn-danger btn-success');
1475 this.$('form').submit();
1477 file_selected: function(url, error) {
1478 var $button = this.$('button.filepicker');
1480 $button.addClass('btn-success');
1483 this.$('form').addClass('has-error')
1484 .find('.help-block').text(error);
1485 $button.addClass('btn-danger');
1487 this.set_image(url, error);
1488 // auto save and close popup
1492 fetch_existing: function (needle) {
1493 var domain = [['res_model', '=', 'ir.ui.view'], '|',
1494 ['mimetype', '=', false], ['mimetype', '=like', 'image/%']];
1495 if (needle && needle.length) {
1496 domain.push('|', ['datas_fname', 'ilike', needle], ['name', 'ilike', needle]);
1498 return openerp.jsonRpc('/web/dataset/call_kw', 'call', {
1499 model: 'ir.attachment',
1500 method: 'search_read',
1503 fields: ['name', 'website_url'],
1506 context: website.get_context(),
1508 }).then(this.proxy('fetched_existing'));
1510 fetched_existing: function (records) {
1511 this.records = records;
1512 this.display_attachments();
1514 display_attachments: function () {
1515 this.$('.help-block').empty();
1516 var per_screen = IMAGES_PER_ROW * IMAGES_ROWS;
1518 var from = this.page * per_screen;
1519 var records = this.records;
1521 // Create rows of 3 records
1522 var rows = _(records).chain()
1523 .slice(from, from + per_screen)
1524 .groupBy(function (_, index) { return Math.floor(index / IMAGES_PER_ROW); })
1528 this.$('.existing-attachments').replaceWith(
1529 openerp.qweb.render(
1530 'website.editor.dialog.image.existing.content', {rows: rows}));
1531 this.parent.$('.pager')
1532 .find('li.previous').toggleClass('disabled', (from === 0)).end()
1533 .find('li.next').toggleClass('disabled', (from + per_screen >= records.length));
1535 select_existing: function (e) {
1536 var link = $(e.currentTarget).attr('src');
1538 this.selected_existing(link);
1540 selected_existing: function (link) {
1541 this.$('.existing-attachment-cell.media_selected').removeClass("media_selected");
1542 var $select = this.$('.existing-attachment-cell img').filter(function () {
1543 return $(this).attr("src") == link;
1545 $select.parent().addClass("media_selected");
1549 try_remove: function (e) {
1550 var $help_block = this.$('.help-block').empty();
1552 var $a = $(e.target);
1553 var id = parseInt($a.data('id'), 10);
1554 var attachment = _.findWhere(this.records, {id: id});
1555 var $both = $a.parent().children();
1557 $both.css({borderWidth: "5px", borderColor: "#f00"});
1559 return openerp.jsonRpc('/web/dataset/call_kw', 'call', {
1560 model: 'ir.attachment',
1561 method: 'try_remove',
1565 context: website.get_context()
1567 }).then(function (prevented) {
1568 if (_.isEmpty(prevented)) {
1569 self.records = _.without(self.records, attachment);
1570 self.display_attachments();
1573 $both.css({borderWidth: "", borderColor: ""});
1574 $help_block.replaceWith(openerp.qweb.render(
1575 'website.editor.dialog.image.existing.error', {
1576 views: prevented[id]
1583 website.editor.RTEImageDialog = website.editor.ImageDialog.extend({
1584 init: function (parent, editor, media) {
1585 this._super(parent, editor, media);
1587 this.on('start', this, this.proxy('started'));
1588 this.on('save', this, this.proxy('saved'));
1590 started: function (holder) {
1592 var selection = this.editor.getSelection();
1593 this.media = selection && selection.getSelectedElement();
1596 var el = this.media;
1597 if (!el || !el.is('img')) {
1600 holder.url = el.getAttribute('src');
1602 saved: function (data) {
1603 var element, editor = this.editor;
1604 if (!(element = this.media)) {
1605 element = editor.document.createElement('img');
1606 element.addClass('img');
1607 element.addClass('img-responsive');
1608 // focus event handler interactions between bootstrap (modal)
1609 // and ckeditor (RTE) lead to blowing the stack in Safari and
1610 // Chrome (but not FF) when this is done synchronously =>
1611 // defer insertion so modal has been hidden & destroyed before
1613 setTimeout(function () {
1614 editor.insertElement(element);
1618 var style = data.style;
1619 element.setAttribute('src', data.url);
1620 element.removeAttribute('data-cke-saved-src');
1621 if (style) { element.addClass(style); }
1625 function get_selected_link(editor) {
1626 var sel = editor.getSelection(),
1627 el = sel.getSelectedElement();
1628 if (el && el.is('a')) { return el; }
1630 var range = sel.getRanges(true)[0];
1631 if (!range) { return null; }
1633 range.shrink(CKEDITOR.SHRINK_TEXT);
1634 var commonAncestor = range.getCommonAncestor();
1635 var viewRoot = editor.elementPath(commonAncestor).contains(function (element) {
1636 return element.data('oe-model') === 'ir.ui.view';
1638 if (!viewRoot) { return null; }
1639 // if viewRoot is the first link, don't edit it.
1640 return new CKEDITOR.dom.elementPath(commonAncestor, viewRoot)
1641 .contains('a', true);
1644 website.editor.FontIconsDialog = website.editor.Media.extend({
1645 template: 'website.editor.dialog.font-icons',
1646 events : _.extend({}, website.editor.Dialog.prototype.events, {
1647 change: 'update_preview',
1648 'click .font-icons-icon': function (e) {
1650 e.stopPropagation();
1652 this.$('#fa-icon').val(e.target.getAttribute('data-id'));
1653 this.update_preview();
1655 'click #fa-preview span': function (e) {
1657 e.stopPropagation();
1659 this.$('#fa-size').val(e.target.getAttribute('data-size'));
1660 this.update_preview();
1664 // List of FontAwesome icons in 4.0.3, extracted from the cheatsheet.
1665 // Each icon provides the unicode codepoint as ``text`` and the class
1666 // name as ``id`` so the whole thing can be fed directly to select2
1667 // without post-processing and do the right thing (except for the part
1668 // where we still need to implement ``initSelection``)
1669 // TODO: add id/name to the text in order to allow FAYT selection of icons?
1670 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"}],
1672 * Initializes select2: in Chrome and Safari, <select> font apparently
1673 * isn't customizable (?) and the fontawesome glyphs fail to appear.
1675 start: function () {
1676 return this._super().then(this.proxy('load_data'));
1678 search: function (needle) {
1679 var icons = this.icons;
1681 icons = _(icons).filter(function (icon) {
1682 return icon.id.substring(3).indexOf(needle) !== -1;
1686 this.$('div.font-icons-icons').html(
1687 openerp.qweb.render(
1688 'website.editor.dialog.font-icons.icons',
1692 * Removes existing FontAwesome classes on the bound element, and sets
1693 * all the new ones if necessary.
1696 var style = this.media.$.attributes.style ? this.media.$.attributes.style.textContent : '';
1697 var classes = (this.media.$.className||"").split(/\s+/);
1698 var non_fa_classes = _.reject(classes, function (cls) {
1699 return cls === 'fa' || /^fa-/.test(cls);
1701 var final_classes = non_fa_classes.concat(this.get_fa_classes());
1702 this.media.$.className = final_classes.join(' ');
1703 this.media.renameNode("span");
1704 this.media.$.attributes.style.textContent = style;
1708 * Looks up the various FontAwesome classes on the bound element and
1709 * sets the corresponding template/form elements to the right state.
1710 * If multiple classes of the same category are present on an element
1711 * (e.g. fa-lg and fa-3x) the last one occurring will be selected,
1712 * which may not match the visual look of the element.
1714 load_data: function () {
1715 var classes = (this.media&&this.media.$.className||"").split(/\s+/);
1716 for (var i = 0; i < classes.length; i++) {
1717 var cls = classes[i];
1719 case 'fa-2x':case 'fa-3x':case 'fa-4x':case 'fa-5x':
1721 this.$('#fa-size').val(cls);
1724 case 'fa-rotate-90':case 'fa-rotate-180':case 'fa-rotate-270':
1725 case 'fa-flip-horizontal':case 'fa-rotate-vertical':
1726 this.$('#fa-rotation').val(cls);
1731 this.$('#fa-border').prop('checked', true);
1734 if (!/^fa-/.test(cls)) { continue; }
1735 this.$('#fa-icon').val(cls);
1738 this.update_preview();
1741 * Serializes the dialog to an array of FontAwesome classes. Includes
1744 get_fa_classes: function () {
1747 this.$('#fa-icon').val(),
1748 this.$('#fa-size').val(),
1749 this.$('#fa-rotation').val(),
1750 this.$('#fa-border').prop('checked') ? 'fa-border' : ''
1753 update_preview: function () {
1754 this.$preview.empty();
1755 var $preview = this.$('#fa-preview').empty();
1757 var sizes = ['', 'fa-2x', 'fa-3x', 'fa-4x', 'fa-5x'];
1758 var classes = this.get_fa_classes();
1759 var no_sizes = _.difference(classes, sizes).join(' ');
1760 var selected = false;
1761 for (var i = sizes.length - 1; i >= 0; i--) {
1762 var size = sizes[i];
1764 var $p = $('<span>')
1765 .attr('data-size', size)
1767 .addClass(no_sizes);
1768 if ((size && _.contains(classes, size)) || (classes[2] === "" && !selected)) {
1769 this.$preview.append($p.clone());
1770 this.$('#fa-size').val(size);
1771 $p.addClass('font-icons-selected');
1774 $preview.prepend($p);
1777 clear: function () {
1778 this.media.$.className = this.media.$.className.replace(/(^|\s)(fa(\s|$)|fa-[^\s]*)/g, ' ');
1782 website.editor.VideoDialog = website.editor.Media.extend({
1783 template: 'website.editor.dialog.video',
1784 events : _.extend({}, website.editor.Dialog.prototype.events, {
1785 'click input#urlvideo ~ button': 'get_video',
1786 'click input#embedvideo ~ button': 'get_embed_video',
1787 'change input#urlvideo': 'change_input',
1788 'keyup input#urlvideo': 'change_input',
1789 'change input#embedvideo': 'change_input',
1790 'keyup input#embedvideo': 'change_input'
1792 start: function () {
1793 this.$iframe = this.$("iframe");
1794 var $media = $(this.media && this.media.$);
1795 if ($media.hasClass("media_iframe_video")) {
1796 var src = $media.data('src');
1797 this.$("input#urlvideo").val(src);
1798 this.$("#autoplay").attr("checked", src.indexOf('autoplay=1') != -1);
1801 return this._super();
1803 change_input: function (e) {
1804 var $input = $(e.target);
1805 var $button = $input.parent().find("button");
1806 if ($input.val() === "") {
1807 $button.addClass("btn-default").removeClass("btn-primary");
1809 $button.removeClass("btn-default").addClass("btn-primary");
1812 get_url: function () {
1813 var video_id = this.$("#video_id").val();
1814 var video_type = this.$("#video_type").val();
1815 switch (video_type) {
1817 return "//www.youtube.com/embed/" + video_id + "?autoplay=" + (this.$("#autoplay").is(":checked") ? 1 : 0);
1819 return "//player.vimeo.com/video/" + video_id + "?autoplay=" + (this.$("#autoplay").is(":checked") ? 1 : 0);
1821 return "//www.dailymotion.com/embed/video/" + video_id + "?autoplay=" + (this.$("#autoplay").is(":checked") ? 1 : 0);
1826 get_embed_video: function (event) {
1827 event.preventDefault();
1828 var embedvideo = this.$("input#embedvideo").val().match(/src=["']?([^"']+)["' ]?/);
1830 this.$("input#urlvideo").val(embedvideo[1]);
1831 this.get_video(event);
1835 get_video: function (event) {
1836 if (event) event.preventDefault();
1837 var needle = this.$("input#urlvideo").val();
1841 if (needle.indexOf(".youtube.") != -1) {
1842 video_type = "youtube";
1843 video_id = needle.match(/\.youtube\.[a-z]+\/(embed\/|watch\?v=)?([^\/?&]+)/i)[2];
1844 } else if (needle.indexOf("//youtu.") != -1) {
1845 video_type = "youtube";
1846 video_id = needle.match(/youtube\.[a-z]+\/([^\/?&]+)/i)[1];
1847 } else if (needle.indexOf("player.vimeo.") != -1 || needle.indexOf("//vimeo.") != -1) {
1848 video_type = "vimeo";
1849 video_id = needle.match(/vimeo\.[a-z]+\/(video\/)?([^?&]+)/i)[2];
1850 } else if (needle.indexOf(".dailymotion.") != -1) {
1851 video_type = "dailymotion";
1852 video_id = needle.match(/dailymotion\.[a-z]+\/(embed\/)?(video\/)?([^\/?&]+)/i)[3];
1858 this.$("#video_id").val(video_id);
1859 this.$("#video_type").val(video_type);
1861 this.$iframe.attr("src", this.get_url());
1865 var video_id = this.$("#video_id").val();
1867 this.$("button.btn-primary").click();
1868 video_id = this.$("#video_id").val();
1870 var video_type = this.$("#video_type").val();
1871 var style = this.media.$.attributes.style ? this.media.$.attributes.style.textContent : '';
1873 '<div class="media_iframe_video" data-src="'+this.get_url()+'" style="'+style+'">'+
1874 '<div class="css_editable_mode_display"> </div>'+
1875 '<iframe src="'+this.get_url()+'" frameborder="0" allowfullscreen="allowfullscreen"></iframe>'+
1877 $(this.media.$).replaceWith($iframe);
1878 this.media.$ = $iframe[0];
1881 clear: function () {
1882 delete this.media.$.dataset.src;
1883 this.media.$.className = this.media.$.className.replace(/(^|\s)media_iframe_video(\s|$)/g, ' ');
1887 website.Observer = window.MutationObserver || window.WebkitMutationObserver || window.JsMutationObserver;
1888 var OBSERVER_CONFIG = {
1891 characterData: true,
1893 attributeOldValue: true,
1895 var observer = new website.Observer(function (mutations) {
1896 // NOTE: Webkit does not fire DOMAttrModified => webkit browsers
1897 // relying on JsMutationObserver shim (Chrome < 18, Safari < 6)
1898 // will not mark dirty on attribute changes (@class, img/@src,
1900 _(mutations).chain()
1901 .filter(function (m) {
1902 // ignore any SVG target, these blokes are like weird mon
1903 if (m.target && m.target instanceof SVGElement) {
1907 // ignore any change related to mundane image-edit-button
1908 if (m.target && m.target.className
1909 && m.target.className.indexOf('image-edit-button') !== -1) {
1913 case 'attributes': // ignore .cke_focus being added or removed
1914 // ignore id modification
1915 if (m.attributeName === 'id') { return false; }
1916 // if attribute is not a class, can't be .cke_focus change
1917 if (m.attributeName !== 'class') { return true; }
1919 // find out what classes were added or removed
1920 var oldClasses = (m.oldValue || '').split(/\s+/);
1921 var newClasses = m.target.className.split(/\s+/);
1922 var change = _.union(_.difference(oldClasses, newClasses),
1923 _.difference(newClasses, oldClasses));
1924 // ignore mutation if the *only* change is .cke_focus
1925 return change.length !== 1 || change[0] === 'cke_focus';
1927 setTimeout(function () {
1928 fixup_browser_crap(m.addedNodes);
1930 // Remove ignorable nodes from addedNodes or removedNodes,
1931 // if either set remains non-empty it's considered to be an
1932 // impactful change. Otherwise it's ignored.
1933 return !!remove_mundane_nodes(m.addedNodes).length ||
1934 !!remove_mundane_nodes(m.removedNodes).length;
1940 var node = m.target;
1941 while (node && !$(node).hasClass('oe_editable')) {
1942 node = node.parentNode;
1948 .each(function (node) { $(node).trigger('content_changed'); })
1950 function remove_mundane_nodes(nodes) {
1951 if (!nodes || !nodes.length) { return []; }
1954 for(var i=0; i<nodes.length; ++i) {
1955 var node = nodes[i];
1956 if (node.nodeType === document.ELEMENT_NODE) {
1957 if (node.nodeName === 'BR' && node.getAttribute('type') === '_moz') {
1958 // <br type="_moz"> appears when focusing RTE in FF, ignore
1960 } else if (node.nodeName === 'DIV' && $(node).hasClass('oe_drop_zone')) {
1961 // ignore dropzone inserted by snippets
1971 var programmatic_styles = {
1980 function fixup_browser_crap(nodes) {
1981 if (!nodes || !nodes.length) { return; }
1983 * Checks that the node only has a @style, not e.g. @class or whatever
1985 function has_only_style(node) {
1986 for (var i = 0; i < node.attributes.length; i++) {
1987 var attr = node.attributes[i];
1988 if (attr.attributeName !== 'style') {
1994 function has_programmatic_style(node) {
1995 for (var i = 0; i < node.style.length; i++) {
1996 var style = node.style[i];
1997 if (programmatic_styles[style]) {
2004 for (var i=0; i<nodes.length; ++i) {
2005 var node = nodes[i];
2006 if (node.nodeType !== document.ELEMENT_NODE) { continue; }
2008 if (node.nodeName === 'SPAN'
2009 && has_only_style(node)
2010 && !has_programmatic_style(node)) {
2011 // On backspace, webkit browsers create a <span> with a bunch of
2012 // inline styles "remembering" where they come from. Refs:
2013 // http://www.neotericdesign.com/blog/2013/3/working-around-chrome-s-contenteditable-span-bug
2014 // https://code.google.com/p/chromium/issues/detail?id=226941
2015 // https://bugs.webkit.org/show_bug.cgi?id=114791
2016 // http://dev.ckeditor.com/ticket/9998
2017 var child, parent = node.parentNode;
2018 while (child = node.firstChild) {
2019 parent.insertBefore(child, node);
2021 parent.removeChild(node);
2022 // chances are we had e.g.
2025 // merged the lines getting this in webkit
2026 // <p>foo<span>bar</span></p>
2027 // after unwrapping the span, we have 2 text nodes
2028 // <p>[foo][bar]</p>
2029 // where we probably want only one. Normalize will merge
2030 // adjacent text nodes. However, does not merge text and cdata