/*! * medium-editor-insert-plugin v0.3.2 - jQuery insert plugin for MediumEditor * * https://github.com/orthes/medium-editor-insert-plugin * * Copyright (c) 2014 Pavel Linkesch (http://linkesch.sk) * Released under the MIT license */ (function ($) { $.fn.mediumInsert.registerAddon('tables', { /** * Table default options */ defaults: { defaultRows: 2, defaultCols: 2 }, /** * Tables initial function * @return {void} */ init : function (options) { this.options = $.extend(this.defaults, options); this.$el = $.fn.mediumInsert.insert.$el; this.setTableButtonEvents(); }, insertButton : function (buttonLabels) { var label = 'Table'; if (buttonLabels === 'fontawesome' || typeof buttonLabels === 'object' && !!(buttonLabels.fontawesome)) { label = ''; } if (typeof buttonLabels === 'object' && buttonLabels.table) { label = buttonLabels.table; } return ''; }, /** * Add table to $placeholder * @param {element} $placeholder $placeholder to add embed to * @return {void} */ add : function ($placeholder) { $.fn.mediumInsert.insert.deselect(); var formHtml = '
'; $(formHtml).appendTo($placeholder.prev()); this.updateDemoTable(); setTimeout(function () { $placeholder.prev().find('input').focus(); }, 50); $.fn.mediumInsert.insert.deselect(); this.currentPlaceholder = $placeholder; }, setTableButtonEvents : function () { var that = this; $(document).on('keyup', 'input.mediumInsert-tableRows, input.mediumInsert-tableCols', function() { that.updateDemoTable(); }); $(document).on('click', function(e) { if ($(e.target).parents('.mediumInsert-buttons').length === 0) { that.removeToolbar(); } }); $(document).on('click', 'button.mediumInsert-tableReadyButton', function() { that.setEnterActionEvents(); that.removeToolbar(); }); }, getDimensions : function () { return { rows: parseFloat($('input.mediumInsert-tableRows').val()) || 1, cols: parseFloat($('input.mediumInsert-tableCols').val()) || 1 }; }, buildTable : function (table) { var i, j, $row, dimensions = this.getDimensions(), $table = $(table); for (i = 0; i < dimensions.rows; i++) { $row = $('