(function( $ ){ $.fn.gridEditor = function( options ) { var self = this; var grideditor = self.data('grideditor'); var MAX_ROWS = 100; var MAX_IMAGES = 16; /** Methods **/ if (arguments[0] == 'getHtml') { if (grideditor) { grideditor.deinit(true); var html = self.html(); grideditor.init(true); return html; } else { return self.html(); } } /** Initialize plugin */ self.each(function(baseIndex, baseElem) { baseElem = $(baseElem); var settings = $.extend({ 'custom_filter' : '', 'content_types' : ['tinymce'], 'source_textarea' : '' }, options); // Elems var canvas, mainControls, addRowGroup, htmlTextArea ; var colClasses = ['col-md-']; var curColClassIndex = 0; // Index of the column class we are manipulating currently var curMaxImage = 0; var curMaxRow = 0; var imageSelectorOptions = '' + ''; var imageSelector; additionalImages = $.parseJSON(additionalImages); var additionalImagesNumber = x13allegro_template_images_nb || 5; for (var i = 0; i < additionalImagesNumber; i++) { imageSelectorOptions += ''; } imageSelector = ''; var imagePlaceholder = '
' + '
' + '' + '{product_image}' + imageSelector + '
' + '
'; // Copy html to sourceElement if a source textarea is given if (settings.source_textarea) { var sourceEl = $(settings.source_textarea); sourceEl.addClass('ge-html-output'); htmlTextArea = sourceEl; if (sourceEl.val()) { baseElem.html(sourceEl.val()); } } // Wrap content if it is non-bootstrap if (baseElem.children().length && !baseElem.find('div.row').length) { var children = baseElem.children(); var newRow = $('
').appendTo(baseElem); newRow.find('.col-md-12').append(children); } setup(); init(); function setup() { /* Setup canvas */ canvas = baseElem.addClass('ge-canvas'); if (typeof htmlTextArea === 'undefined' || !htmlTextArea.length) { htmlTextArea = $('