var InlineEditorToolbar = { element: null, // reference to the toolbar element form: null, // reference to the form used to post changes editingMode: false, // true means that Aloha should be enabled drawerButton: null, locale: 'en', // default locale initialize: function() { this.editingMode = window.location.href.match(/\/edit$/) != null; this.locale = $('meta[name=locale]').attr('content'); this._buildHTML(); this.element = $('#page-toolbar'); this.form = this.element.find('form'); this.drawerButton = this.element.find('.drawer a'); this._bindEvents(); if ($.cookie('ie_toolbar_off') == '1') this.hide(0, false); }, toggle: function(animate) { var duration = (typeof animate == 'undefined') || animate == true ? 300 : 0; if (this.drawerButton.hasClass('off')) this.show(duration); else this.hide(duration); }, show: function(duration, withCookie) { var self = this; this.element.animate({ 'right': 0 }, duration, function() { self.drawerButton.removeClass('off'); if ((typeof withCookie == 'undefined') || withCookie == true) $.cookie('ie_toolbar_off', '0'); }); }, hide: function(duration, withCookie) { var self = this; var max = this.element.width() - 17; this.element.animate({ 'right': -max }, duration, function() { self.drawerButton.addClass('off'); if ((typeof withCookie == 'undefined') || withCookie == true) $.cookie('ie_toolbar_off', '1'); }); }, updateForm: function(jEvent, aEvent) { InlineEditorToolbar.element.find('li.save, li.cancel, li.sep:eq(1)').show(); var content = aEvent.editable.getContents().replace(/^\s*/, "").replace(/\s*$/, ""); var editableObj = $(aEvent.editable.obj[0]); var dataId = editableObj.attr('data-element-id'); var idInput = InlineEditorToolbar.form.find('#editable-id'); var contentInput = InlineEditorToolbar.form.find('#editable-content'); idInput.attr('name', 'page[editable_elements_attributes][0][id]').val(dataId); contentInput.attr('name', 'page[editable_elements_attributes][0][content]').val(content); InlineEditorToolbar.show(true, false); }, displaySpinner: function() { this.element.find('li.save, li.cancel, li.sep:eq(1)').hide(); this.element.find('.spinner').show(); }, resetForm: function() { this.form.find('input.auto').each(function() { $(this).attr('name', $(this).attr('name').replace('content', '_index')); $(this).val(''); }); this.element.find('li.save, li.cancel, li.sep:eq(1), li.spinner').hide(); }, /* ___ internal methods ___ */ _buildHTML: function() { var labels = this._translations[this.locale]; var showPageUrl = $('meta[name=page-url]').attr('content'); var editPageUrl = $('meta[name=edit-page-url]').attr('content'); var nbElements = parseInt($('meta[name=page-elements-count]').attr('content')); var formContentHTML = "\ \ "; $('body').prepend("