diff --git a/Gruntfile.js b/Gruntfile.js index 9afd65fa9..9dd44c9bd 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -2,69 +2,27 @@ module.exports = function(grunt) { grunt.initConfig({ pkg: grunt.file.readJSON('package.json'), + banner: '/*! \n * <%= pkg.name %> v<%= pkg.version %> - <%= pkg.description %>\n *\n * <%= pkg.homepage %>\n * \n * Copyright (c) 2014 <%= pkg.author.name %> (<%= pkg.author.url %>)\n * Released under the <%= pkg.license %> license\n */\n\n', uglify: { build: { options: { - banner: '/*! \n * <%= pkg.name %> v<%= pkg.version %> - <%= pkg.description %>\n *\n * <%= pkg.homepage %>\n * \n * Copyright (c) 2014 <%= pkg.author.name %> (<%= pkg.author.url %>)\n * Released under the <%= pkg.license %> license\n */\n\n' + banner: '<%= banner %>' }, src: ['src/js/medium-editor-insert-plugin.js', 'src/js/medium-editor-insert-images.js', 'src/js/medium-editor-insert-maps.js', 'src/js/medium-editor-insert-embeds.js', 'src/js/medium-editor-insert-tables.js'], dest: 'dist/js/<%= pkg.name %>.all.min.js' }, - f1: { + build2: { options: { - preserveComments: 'some' + banner: '<%= banner %>' }, - src: 'src/js/medium-editor-insert-plugin.js', - dest: 'dist/js/addons/medium-editor-insert-plugin.min.js' - }, - f2: { - options: { - preserveComments: 'some' - }, - src: 'src/js/medium-editor-insert-images.js', - dest: 'dist/js/addons/medium-editor-insert-images.min.js' - }, - f3: { - options: { - preserveComments: 'some' - }, - src: 'src/js/medium-editor-insert-maps.js', - dest: 'dist/js/addons/medium-editor-insert-maps.min.js' - }, - f4: { - options: { - preserveComments: 'some' - }, - src: 'src/js/medium-editor-insert-embeds.js', - dest: 'dist/js/addons/medium-editor-insert-embeds.min.js' - }, - f5: { - options: { - preserveComments: 'some' - }, - src: 'src/js/medium-editor-insert-tables.js', - dest: 'dist/js/addons/medium-editor-insert-tables.min.js' - } - }, - - copy: { - main: { - files: [ - { - expand: true, - cwd: 'src/js/', - src: ['*'], - dest: 'dist/js/addons/' - } - ] - } - }, - - concat: { - dist: { - src: ['src/js/medium-editor-insert-plugin.js', 'src/js/medium-editor-insert-images.js', 'src/js/medium-editor-insert-maps.js', 'src/js/medium-editor-insert-tables.js', 'src/js/medium-editor-insert-embeds.js'], - dest: 'dist/js/<%= pkg.name %>.all.js' + files: [{ + expand: true, + cwd: 'src/js', + src: '**/*.js', + dest: 'dist/js/addons', + ext: '.min.js' + }] } }, @@ -130,14 +88,12 @@ module.exports = function(grunt) { grunt.loadNpmTasks('grunt-contrib-qunit'); grunt.loadNpmTasks('grunt-contrib-compass'); grunt.loadNpmTasks('grunt-contrib-watch'); - grunt.loadNpmTasks('grunt-contrib-copy'); - grunt.loadNpmTasks('grunt-contrib-concat'); grunt.loadNpmTasks('grunt-autoprefixer'); grunt.loadNpmTasks('grunt-sass'); grunt.loadNpmTasks('grunt-csso'); grunt.registerTask('test', ['jshint', 'qunit']); - grunt.registerTask('js', ['test', 'uglify', 'copy', 'concat']); + grunt.registerTask('js', ['test', 'uglify']); grunt.registerTask('css', ['sass', 'autoprefixer', 'csso']); grunt.registerTask('default', ['js', 'css']); diff --git a/bower.json b/bower.json index d08b4a386..b72fec61d 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "medium-editor-insert-plugin", - "version": "0.2.6", + "version": "0.2.7", "description": "jQuery insert plugin for MediumEditor", "main": [ "dist/js/medium-editor-insert-plugin.all.js", diff --git a/dist/js/addons/medium-editor-insert-embeds.js b/dist/js/addons/medium-editor-insert-embeds.js deleted file mode 100644 index 7fde24cb8..000000000 --- a/dist/js/addons/medium-editor-insert-embeds.js +++ /dev/null @@ -1,133 +0,0 @@ -/*! - * medium-editor-insert-plugin v0.2.6 - jQuery insert plugin for MediumEditor - * - * Embeds Addon - * - * https://github.com/orthes/medium-editor-insert-plugin - * - * Copyright (c) 2014 Vexus2 (https://github.com/vexus2) - * Released under the MIT license - */ - -(function ($) { - - $.fn.mediumInsert.registerAddon('embeds', { - - /** - * Embed default options - */ - - default: { - urlPlaceholder: 'type or paste url here' - }, - - /** - * Embeds initial function - * @return {void} - */ - init : function (options) { - this.options = $.extend(this.default, options); - this.$el = $.fn.mediumInsert.insert.$el; - this.setEmbedButtonEvents(); - this.preparePreviousEmbeds(); - }, - - insertButton : function (buttonLabels) { - var label = 'Embed'; - if (buttonLabels == 'fontawesome' || typeof buttonLabels === 'object' && !!(buttonLabels.fontawesome)) { - label = ''; - } - return ''; - }, - - /** - * Add embed 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()); - setTimeout(function () { - $placeholder.prev().find('input').focus(); - }, 50); - - $.fn.mediumInsert.insert.deselect(); - - this.currentPlaceholder = $placeholder; - $(".mediumInsert-embedsText").focus(); - }, - - /** - * Make existing embeds interactive - * - * @return {void} - */ - - preparePreviousEmbeds: function () { - this.$el.find('.mediumInsert-embeds').each(function() { - var $parent = $(this).parent(); - $parent.html('
' + $parent.html() + '
'); - }); - }, - - setEmbedButtonEvents : function () { - var that = this; - $(document).on('keypress', 'input.mediumInsert-embedsText', function (e) { - if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) { - that.setEnterActionEvents(); - that.removeToolbar(); - } - }); - - this.$el.on('blur', '.mediumInsert-embedsText', function () { - that.removeToolbar(); - }); - - }, - setEnterActionEvents : function () { - var that = this; - if ($.fn.mediumInsert.settings.enabled === false) { - return false; - } - - var url = $("input.mediumInsert-embedsText").val(); - if (!url) { - return false; - } - var embed_tag = that.convertUrlToEmbedTag(url); - if (!embed_tag) { - alert('Incorrect URL format specified'); - return false; - } else { - embed_tag = $('
').append(embed_tag); - that.currentPlaceholder.append(embed_tag); - - that.currentPlaceholder.closest('[data-medium-element]').trigger('keyup').trigger('input'); - } - }, - - removeToolbar : function () { - $(".mediumInsert-embedsWire").remove(); - }, - - convertUrlToEmbedTag : function (url) { - var embed_tag = url.replace(/\n?/g, '').replace(/^((http(s)?:\/\/)?(www\.)?(youtube\.com|youtu\.be)\/(watch\?v=|v\/)?)([a-zA-Z0-9-_]+)(.*)?$/, '
') - .replace(/http:\/\/vimeo\.com\/(\d+)$/, '') - - // TWITTER EMBEDDING NEEDS REWORK! Serialized version of embeded Twitter status is unusable because the Twitter script complitely removes blockquote element and replaces it with iframe - //.replace(/https:\/\/twitter\.com\/(\w+)\/status\/(\d+)\/?$/, '
') - - // FACEBOOK EMBEDDING NEEDS REWORK! Similarly to Twitter, FB script removes .fb-post element and replaces it with iframe, which is unusable after serializing editor's content - //.replace(/https:\/\/www\.facebook\.com\/(\w+)\/posts\/(\d+)$/, '
') - - .replace(/http:\/\/instagram\.com\/p\/(.+)\/?$/, ''); - return /<("[^"]*"|'[^']*'|[^'">])*>/.test(embed_tag) ? embed_tag : false; - } - - }); - -}(jQuery)); diff --git a/dist/js/addons/medium-editor-insert-embeds.min.js b/dist/js/addons/medium-editor-insert-embeds.min.js index afaf592f5..5f72d0e8a 100644 --- a/dist/js/addons/medium-editor-insert-embeds.min.js +++ b/dist/js/addons/medium-editor-insert-embeds.min.js @@ -1,11 +1,10 @@ -/*! - * medium-editor-insert-plugin v0.2.6 - jQuery insert plugin for MediumEditor - * - * Embeds Addon +/*! + * medium-editor-insert-plugin v0.2.7 - jQuery insert plugin for MediumEditor * * https://github.com/orthes/medium-editor-insert-plugin - * - * Copyright (c) 2014 Vexus2 (https://github.com/vexus2) + * + * Copyright (c) 2014 Pavel Linkesch (http://linkesch.sk) * Released under the MIT license */ + !function(a){a.fn.mediumInsert.registerAddon("embeds",{"default":{urlPlaceholder:"type or paste url here"},init:function(b){this.options=a.extend(this.default,b),this.$el=a.fn.mediumInsert.insert.$el,this.setEmbedButtonEvents(),this.preparePreviousEmbeds()},insertButton:function(a){var b="Embed";return("fontawesome"==a||"object"==typeof a&&a.fontawesome)&&(b=''),'"},add:function(b){a.fn.mediumInsert.insert.deselect();var c='
';a(c).appendTo(b.prev()),setTimeout(function(){b.prev().find("input").focus()},50),a.fn.mediumInsert.insert.deselect(),this.currentPlaceholder=b,a(".mediumInsert-embedsText").focus()},preparePreviousEmbeds:function(){this.$el.find(".mediumInsert-embeds").each(function(){var b=a(this).parent();b.html('
'+b.html()+"
")})},setEmbedButtonEvents:function(){var b=this;a(document).on("keypress","input.mediumInsert-embedsText",function(a){(a.which&&13==a.which||a.keyCode&&13==a.keyCode)&&(b.setEnterActionEvents(),b.removeToolbar())}),this.$el.on("blur",".mediumInsert-embedsText",function(){b.removeToolbar()})},setEnterActionEvents:function(){var b=this;if(a.fn.mediumInsert.settings.enabled===!1)return!1;var c=a("input.mediumInsert-embedsText").val();if(!c)return!1;var d=b.convertUrlToEmbedTag(c);return d?(d=a('
').append(d),b.currentPlaceholder.append(d),b.currentPlaceholder.closest("[data-medium-element]").trigger("keyup").trigger("input"),void 0):(alert("Incorrect URL format specified"),!1)},removeToolbar:function(){a(".mediumInsert-embedsWire").remove()},convertUrlToEmbedTag:function(a){var b=a.replace(/\n?/g,"").replace(/^((http(s)?:\/\/)?(www\.)?(youtube\.com|youtu\.be)\/(watch\?v=|v\/)?)([a-zA-Z0-9-_]+)(.*)?$/,'
').replace(/http:\/\/vimeo\.com\/(\d+)$/,'').replace(/http:\/\/instagram\.com\/p\/(.+)\/?$/,'');return/<("[^"]*"|'[^']*'|[^'">])*>/.test(b)?b:!1}})}(jQuery); \ No newline at end of file diff --git a/dist/js/addons/medium-editor-insert-images.js b/dist/js/addons/medium-editor-insert-images.js deleted file mode 100644 index 8dc6fe1a9..000000000 --- a/dist/js/addons/medium-editor-insert-images.js +++ /dev/null @@ -1,496 +0,0 @@ -/*! - * medium-editor-insert-plugin v0.2.6 - jQuery insert plugin for MediumEditor - * - * Images Addon - * - * https://github.com/orthes/medium-editor-insert-plugin - * - * Copyright (c) 2013 Pavel Linkesch (http://linkesch.sk) - * Released under the MIT license - */ - -(function ($) { - - $.fn.mediumInsert.registerAddon('images', { - - /** - * Images default options - */ - - default: { - /** - * Active or inactive image's drag and drop - */ - useDragAndDrop: true, - - /** - * Relative path to a script that handles file uploads - */ - imagesUploadScript: 'upload.php', - - /** - * Relative path to a script that handles file deleting - */ - imagesDeleteScript: 'delete.php', - - /** - * Format data before sending them to server while uploading an image - * - * @param {File} file File to upload - * @return {object} formData FormData instance - */ - formatData: function (file) { - var formData = new FormData(); - formData.append('file', file); - return formData; - }, - - /** - * Upload single file - * - * @param {element} $placeholder Placeholder to add image to - * @param {File} file File to upload - * @param {object} that Context - * @param {void} - */ - uploadFile: function ($placeholder, file, that) { - $.ajax({ - type: "post", - url: that.options.imagesUploadScript, - xhr: function () { - var xhr = new XMLHttpRequest(); - xhr.upload.onprogress = that.updateProgressBar; - return xhr; - }, - cache: false, - contentType: false, - complete: function (jqxhr) { - that.uploadCompleted(jqxhr, $placeholder); - }, - processData: false, - data: that.options.formatData(file) - }); - }, - - /** - * Makes ajax call for deleting a file on a server - * - * @param {string} file File name - * @param {object} that Context - * @return {void} - */ - deleteFile: function (file, that) { - $.ajax({ - type: "post", - url: that.options.imagesDeleteScript, - data: { - file: file - } - }); - } - }, - - - /** - * Images initial function - * - * @param {object} options Options to overide defaults - * @return {void} - */ - - init: function (options) { - if (options && options.$el) { - this.$el = options.$el; - } - this.options = $.extend(this.default, options); - - this.setImageEvents(); - - if (this.options.useDragAndDrop === true){ - this.setDragAndDropEvents(); - } - - this.preparePreviousImages(); - - }, - - - /** - * Returns insert button - * - * @param {string} buttonLabels - * @return {string} - */ - - insertButton: function(buttonLabels){ - var label = 'Img'; - if (buttonLabels == 'fontawesome' || typeof buttonLabels === 'object' && !!(buttonLabels.fontawesome)) { - label = ''; - } - return ''; - }, - - /** - * Make existing images interactive - * - * @return {void} - */ - - preparePreviousImages: function () { - this.$el.find('.mediumInsert-images').each(function() { - var $parent = $(this).parent(); - $parent.html($.fn.mediumInsert.insert.getButtons('images') + - '
' + $parent.html() + '
' - ); - }); - }, - - /** - * Add image to placeholder - * - * @param {element} $placeholder Placeholder to add image to - * @return {element} $selectFile element - */ - - add: function ($placeholder) { - var that = this, - $selectFile, files; - - $selectFile = $('').click(); - $selectFile.change(function () { - files = this.files; - that.uploadFiles($placeholder, files, that); - }); - - $.fn.mediumInsert.insert.deselect(); - - return $selectFile; - }, - - /** - * Update progressbar while upload - * - * @param {event} e XMLHttpRequest.upload.onprogress event - * @return {void} - */ - - updateProgressBar: function (e) { - var $progress = $('.progress:first', this.$el), - complete; - - if (e.lengthComputable) { - complete = e.loaded / e.total * 100; - complete = complete ? complete : 0; - $progress.attr('value', complete); - $progress.html(complete); - } - }, - - /** - * Show uploaded image after upload completed - * - * @param {jqXHR} jqxhr jqXHR object - * @return {void} - */ - - uploadCompleted: function (jqxhr, $placeholder) { - var $progress = $('.progress:first', $placeholder), - $img; - - $progress.attr('value', 100); - $progress.html(100); - - if (jqxhr.responseText) { - $progress.before('
'); - $img = $progress.siblings('img'); - - $img.load(function () { - $img.parent().mouseleave().mouseenter(); - }); - } else { - $progress.before('
There was a problem uploading the file.
'); - - setTimeout(function () { - $('.mediumInsert-error:first', $placeholder).fadeOut(function () { - $(this).remove(); - }); - }, 3000); - } - - $progress.remove(); - - $placeholder.closest('[data-medium-element]').trigger('keyup').trigger('input'); - }, - - /** - * Upload single file - * - * @param {element} $placeholder Placeholder to add image to - * @param {File} file File to upload - * @param {object} that Context - * @param {void} - */ - - uploadFile: function ($placeholder, file, that) { - return that.options.uploadFile($placeholder, file, that); - }, - - /** - * Lopp though files, check file types and call uploadFile() function on each file that passes - * - * @param {element} placeholder Placeholder to add image to - * @param {FileList} files Files to upload - * @param {object} that Context - * @return {void} - */ - - uploadFiles: function ($placeholder, files, that) { - var acceptedTypes = { - 'image/png': true, - 'image/jpeg': true, - 'image/gif': true - }; - - for (var i = 0; i < files.length; i++) { - var file = files[i]; - - if (acceptedTypes[file.type] === true) { - $placeholder.append('0'); - - that.uploadFile($placeholder, file, that); - } - } - }, - - /** - * Makes ajax call for deleting a file on a server - * - * @param {string} file File name - * @param {object} that Context - * @return {void} - */ - - deleteFile: function (file, that) { - return that.options.deleteFile(file, that); - }, - - /** - * Set image events displaying remove and resize buttons - * - * @return {void} - */ - - setImageEvents: function () { - var that = this; - - this.$el.on('mouseenter', '.mediumInsert-images', function () { - var $img = $('img', this), - positionTop, - positionLeft; - - if ($.fn.mediumInsert.settings.enabled === false) { - return; - } - - if ($img.length > 0) { - $(this).append(''); - - if ($(this).parent().parent().hasClass('small')) { - $(this).append(''); - } else { - $(this).append(''); - } - - positionTop = $img.position().top + parseInt($img.css('margin-top'), 10); - positionLeft = $img.position().left + $img.width() -30; - $('.mediumInsert-imageRemove', this).css({ - 'right': 'auto', - 'top': positionTop, - 'left': positionLeft - }); - $('.mediumInsert-imageResizeBigger, .mediumInsert-imageResizeSmaller', this).css({ - 'right': 'auto', - 'top': positionTop, - 'left': positionLeft-31 - }); - } - }); - - this.$el.on('mouseleave', '.mediumInsert-images', function () { - $('.mediumInsert-imageRemove, .mediumInsert-imageResizeSmaller, .mediumInsert-imageResizeBigger', this).remove(); - }); - - this.$el.on('click', '.mediumInsert-imageResizeSmaller', function () { - $(this).parent().parent().parent().addClass('small'); - $(this).parent().mouseleave().mouseleave(); - - $.fn.mediumInsert.insert.deselect(); - that.$el.closest('[data-medium-element]').trigger('keyup').trigger('input'); - }); - - this.$el.on('click', '.mediumInsert-imageResizeBigger', function () { - $(this).parent().parent().parent().removeClass('small'); - $(this).parent().mouseleave().mouseleave(); - - $.fn.mediumInsert.insert.deselect(); - that.$el.closest('[data-medium-element]').trigger('keyup').trigger('input'); - }); - - this.$el.on('click', '.mediumInsert-imageRemove', function () { - var img = $(this).siblings('img').attr('src'); - - if ($(this).parent().siblings().length === 0) { - $(this).parent().parent().parent().removeClass('small'); - } - $(this).parent().remove(); - - that.deleteFile(img, that); - - $.fn.mediumInsert.insert.deselect(); - that.$el.closest('[data-medium-element]').trigger('keyup').trigger('input'); - }); - }, - - /** - * Set drag and drop events - * - * @return {void} - */ - - setDragAndDropEvents: function () { - var that = this, - dropSuccessful = false, - dropSort = false, - dropSortIndex, dropSortParent; - - $(document).on('dragover', 'body', function () { - if ($.fn.mediumInsert.settings.enabled === false) { - return; - } - - that.$el.addClass('hover'); - }); - - $(document).on('dragend', 'body', function () { - if ($.fn.mediumInsert.settings.enabled === false) { - return; - } - - that.$el.removeClass('hover'); - }); - - this.$el.on('dragover', '.mediumInsert', function () { - if ($.fn.mediumInsert.settings.enabled === false) { - return; - } - - $(this).addClass('hover'); - $(this).attr('contenteditable', true); - }); - - this.$el.on('dragleave', '.mediumInsert', function () { - if ($.fn.mediumInsert.settings.enabled === false) { - return; - } - - $(this).removeClass('hover'); - $(this).attr('contenteditable', false); - }); - - this.$el.on('dragstart', '.mediumInsert .mediumInsert-images img', function () { - if ($.fn.mediumInsert.settings.enabled === false) { - return; - } - - dropSortIndex = $(this).parent().index(); - dropSortParent = $(this).parent().parent().parent().attr('id'); - }); - - this.$el.on('dragend', '.mediumInsert .mediumInsert-images img', function (e) { - if ($.fn.mediumInsert.settings.enabled === false) { - return; - } - - if (dropSuccessful === true) { - if ($(e.originalEvent.target.parentNode).siblings().length === 0) { - $(e.originalEvent.target.parentNode).parent().parent().removeClass('small'); - } - $(e.originalEvent.target.parentNode).mouseleave(); - $(e.originalEvent.target.parentNode).remove(); - dropSuccessful = false; - dropSort = false; - - that.$el.closest('[data-medium-element]').trigger('keyup').trigger('input'); - } - }); - - this.$el.on('dragover', '.mediumInsert .mediumInsert-images img', function (e) { - if ($.fn.mediumInsert.settings.enabled === false) { - return; - } - - e.preventDefault(); - }); - - this.$el.on('drop', '.mediumInsert .mediumInsert-images img', function () { - var index, $dragged, finalIndex; - - if ($.fn.mediumInsert.settings.enabled === false) { - return; - } - - - if (dropSortParent !== $(this).parent().parent().parent().attr('id')) { - dropSort = false; - dropSortIndex = dropSortParent = null; - return; - } - - index = parseInt(dropSortIndex, 10); - - // Sort - $dragged = $(this).parent().parent().find('.mediumInsert-images:nth-child('+ (index+1) +')'); - finalIndex = $(this).parent().index(); - if(index < finalIndex) { - $dragged.insertAfter($(this).parent()); - } else if(index > finalIndex) { - $dragged.insertBefore($(this).parent()); - } - - $dragged.mouseleave(); - - dropSort = true; - dropSortIndex = null; - - that.$el.closest('[data-medium-element]').trigger('keyup').trigger('input'); - }); - - this.$el.on('drop', '.mediumInsert', function (e) { - var files; - - e.preventDefault(); - - if ($.fn.mediumInsert.settings.enabled === false) { - return; - } - - $(this).removeClass('hover'); - that.$el.removeClass('hover'); - $(this).attr('contenteditable', false); - - files = e.originalEvent.dataTransfer.files; - if (files.length > 0) { - // File upload - that.uploadFiles($('.mediumInsert-placeholder', this), files, that); - } else if (dropSort === true) { - dropSort = false; - } else { - // Image move from block to block - $('.mediumInsert-placeholder', this).append('
'+ e.originalEvent.dataTransfer.getData('text/html') +'
'); - $('meta', this).remove(); - dropSuccessful = true; - } - }); - } - }); -}(jQuery)); diff --git a/dist/js/addons/medium-editor-insert-images.min.js b/dist/js/addons/medium-editor-insert-images.min.js index 9f732a5f4..0cd2e4d31 100644 --- a/dist/js/addons/medium-editor-insert-images.min.js +++ b/dist/js/addons/medium-editor-insert-images.min.js @@ -1,11 +1,10 @@ -/*! - * medium-editor-insert-plugin v0.2.6 - jQuery insert plugin for MediumEditor - * - * Images Addon +/*! + * medium-editor-insert-plugin v0.2.7 - jQuery insert plugin for MediumEditor * * https://github.com/orthes/medium-editor-insert-plugin - * - * Copyright (c) 2013 Pavel Linkesch (http://linkesch.sk) + * + * Copyright (c) 2014 Pavel Linkesch (http://linkesch.sk) * Released under the MIT license */ + !function(a){a.fn.mediumInsert.registerAddon("images",{"default":{useDragAndDrop:!0,imagesUploadScript:"upload.php",imagesDeleteScript:"delete.php",formatData:function(a){var b=new FormData;return b.append("file",a),b},uploadFile:function(b,c,d){a.ajax({type:"post",url:d.options.imagesUploadScript,xhr:function(){var a=new XMLHttpRequest;return a.upload.onprogress=d.updateProgressBar,a},cache:!1,contentType:!1,complete:function(a){d.uploadCompleted(a,b)},processData:!1,data:d.options.formatData(c)})},deleteFile:function(b,c){a.ajax({type:"post",url:c.options.imagesDeleteScript,data:{file:b}})}},init:function(b){b&&b.$el&&(this.$el=b.$el),this.options=a.extend(this.default,b),this.setImageEvents(),this.options.useDragAndDrop===!0&&this.setDragAndDropEvents(),this.preparePreviousImages()},insertButton:function(a){var b="Img";return("fontawesome"==a||"object"==typeof a&&a.fontawesome)&&(b=''),'"},preparePreviousImages:function(){this.$el.find(".mediumInsert-images").each(function(){var b=a(this).parent();b.html(a.fn.mediumInsert.insert.getButtons("images")+'
'+b.html()+"
")})},add:function(b){var c,d,e=this;return c=a('').click(),c.change(function(){d=this.files,e.uploadFiles(b,d,e)}),a.fn.mediumInsert.insert.deselect(),c},updateProgressBar:function(b){var c,d=a(".progress:first",this.$el);b.lengthComputable&&(c=b.loaded/b.total*100,c=c?c:0,d.attr("value",c),d.html(c))},uploadCompleted:function(b,c){var d,e=a(".progress:first",c);e.attr("value",100),e.html(100),b.responseText?(e.before('
'),d=e.siblings("img"),d.load(function(){d.parent().mouseleave().mouseenter()})):(e.before('
There was a problem uploading the file.
'),setTimeout(function(){a(".mediumInsert-error:first",c).fadeOut(function(){a(this).remove()})},3e3)),e.remove(),c.closest("[data-medium-element]").trigger("keyup").trigger("input")},uploadFile:function(a,b,c){return c.options.uploadFile(a,b,c)},uploadFiles:function(a,b,c){for(var d={"image/png":!0,"image/jpeg":!0,"image/gif":!0},e=0;e0'),c.uploadFile(a,f,c))}},deleteFile:function(a,b){return b.options.deleteFile(a,b)},setImageEvents:function(){var b=this;this.$el.on("mouseenter",".mediumInsert-images",function(){var b,c,d=a("img",this);a.fn.mediumInsert.settings.enabled!==!1&&d.length>0&&(a(this).append(''),a(this).append(a(this).parent().parent().hasClass("small")?'':''),b=d.position().top+parseInt(d.css("margin-top"),10),c=d.position().left+d.width()-30,a(".mediumInsert-imageRemove",this).css({right:"auto",top:b,left:c}),a(".mediumInsert-imageResizeBigger, .mediumInsert-imageResizeSmaller",this).css({right:"auto",top:b,left:c-31}))}),this.$el.on("mouseleave",".mediumInsert-images",function(){a(".mediumInsert-imageRemove, .mediumInsert-imageResizeSmaller, .mediumInsert-imageResizeBigger",this).remove()}),this.$el.on("click",".mediumInsert-imageResizeSmaller",function(){a(this).parent().parent().parent().addClass("small"),a(this).parent().mouseleave().mouseleave(),a.fn.mediumInsert.insert.deselect(),b.$el.closest("[data-medium-element]").trigger("keyup").trigger("input")}),this.$el.on("click",".mediumInsert-imageResizeBigger",function(){a(this).parent().parent().parent().removeClass("small"),a(this).parent().mouseleave().mouseleave(),a.fn.mediumInsert.insert.deselect(),b.$el.closest("[data-medium-element]").trigger("keyup").trigger("input")}),this.$el.on("click",".mediumInsert-imageRemove",function(){var c=a(this).siblings("img").attr("src");0===a(this).parent().siblings().length&&a(this).parent().parent().parent().removeClass("small"),a(this).parent().remove(),b.deleteFile(c,b),a.fn.mediumInsert.insert.deselect(),b.$el.closest("[data-medium-element]").trigger("keyup").trigger("input")})},setDragAndDropEvents:function(){var b,c,d=this,e=!1,f=!1;a(document).on("dragover","body",function(){a.fn.mediumInsert.settings.enabled!==!1&&d.$el.addClass("hover")}),a(document).on("dragend","body",function(){a.fn.mediumInsert.settings.enabled!==!1&&d.$el.removeClass("hover")}),this.$el.on("dragover",".mediumInsert",function(){a.fn.mediumInsert.settings.enabled!==!1&&(a(this).addClass("hover"),a(this).attr("contenteditable",!0))}),this.$el.on("dragleave",".mediumInsert",function(){a.fn.mediumInsert.settings.enabled!==!1&&(a(this).removeClass("hover"),a(this).attr("contenteditable",!1))}),this.$el.on("dragstart",".mediumInsert .mediumInsert-images img",function(){a.fn.mediumInsert.settings.enabled!==!1&&(b=a(this).parent().index(),c=a(this).parent().parent().parent().attr("id"))}),this.$el.on("dragend",".mediumInsert .mediumInsert-images img",function(b){a.fn.mediumInsert.settings.enabled!==!1&&e===!0&&(0===a(b.originalEvent.target.parentNode).siblings().length&&a(b.originalEvent.target.parentNode).parent().parent().removeClass("small"),a(b.originalEvent.target.parentNode).mouseleave(),a(b.originalEvent.target.parentNode).remove(),e=!1,f=!1,d.$el.closest("[data-medium-element]").trigger("keyup").trigger("input"))}),this.$el.on("dragover",".mediumInsert .mediumInsert-images img",function(b){a.fn.mediumInsert.settings.enabled!==!1&&b.preventDefault()}),this.$el.on("drop",".mediumInsert .mediumInsert-images img",function(){var e,g,h;if(a.fn.mediumInsert.settings.enabled!==!1){if(c!==a(this).parent().parent().parent().attr("id"))return f=!1,void(b=c=null);e=parseInt(b,10),g=a(this).parent().parent().find(".mediumInsert-images:nth-child("+(e+1)+")"),h=a(this).parent().index(),h>e?g.insertAfter(a(this).parent()):e>h&&g.insertBefore(a(this).parent()),g.mouseleave(),f=!0,b=null,d.$el.closest("[data-medium-element]").trigger("keyup").trigger("input")}}),this.$el.on("drop",".mediumInsert",function(b){var c;b.preventDefault(),a.fn.mediumInsert.settings.enabled!==!1&&(a(this).removeClass("hover"),d.$el.removeClass("hover"),a(this).attr("contenteditable",!1),c=b.originalEvent.dataTransfer.files,c.length>0?d.uploadFiles(a(".mediumInsert-placeholder",this),c,d):f===!0?f=!1:(a(".mediumInsert-placeholder",this).append('
'+b.originalEvent.dataTransfer.getData("text/html")+"
"),a("meta",this).remove(),e=!0))})}})}(jQuery); \ No newline at end of file diff --git a/dist/js/addons/medium-editor-insert-maps.js b/dist/js/addons/medium-editor-insert-maps.js deleted file mode 100644 index 521dfcb12..000000000 --- a/dist/js/addons/medium-editor-insert-maps.js +++ /dev/null @@ -1,47 +0,0 @@ -/*! - * medium-editor-insert-plugin v0.2.6 - jQuery insert plugin for MediumEditor - * - * Maps Addon - * - * https://github.com/orthes/medium-editor-insert-plugin - * - * Copyright (c) 2013 Pavel Linkesch (http://linkesch.sk) - * Released under the MIT license - */ - -(function ($) { - - $.fn.mediumInsert.registerAddon('maps', { - - /** - * Maps initial function - * @return {void} - */ - - init: function () { - this.$el = $.fn.mediumInsert.insert.$el; - }, - - insertButton: function(buttonLabels){ - var label = 'Map'; - if (buttonLabels == 'fontawesome' || typeof buttonLabels === 'object' && !!(buttonLabels.fontawesome)) { - label = ''; - } - return ''; - }, - - /** - * Add map to placeholder - * @param {element} placeholder Placeholder to add map to - * @return {void} - */ - - add: function (placeholder) { - $.fn.mediumInsert.insert.deselect(); - - placeholder.append('
Map - Coming soon...
'); - } - - }); - -}(jQuery)); diff --git a/dist/js/addons/medium-editor-insert-maps.min.js b/dist/js/addons/medium-editor-insert-maps.min.js index aac6b4d58..5b5ec3277 100644 --- a/dist/js/addons/medium-editor-insert-maps.min.js +++ b/dist/js/addons/medium-editor-insert-maps.min.js @@ -1,11 +1,10 @@ -/*! - * medium-editor-insert-plugin v0.2.6 - jQuery insert plugin for MediumEditor - * - * Maps Addon +/*! + * medium-editor-insert-plugin v0.2.7 - jQuery insert plugin for MediumEditor * * https://github.com/orthes/medium-editor-insert-plugin - * - * Copyright (c) 2013 Pavel Linkesch (http://linkesch.sk) + * + * Copyright (c) 2014 Pavel Linkesch (http://linkesch.sk) * Released under the MIT license */ + !function(a){a.fn.mediumInsert.registerAddon("maps",{init:function(){this.$el=a.fn.mediumInsert.insert.$el},insertButton:function(a){var b="Map";return("fontawesome"==a||"object"==typeof a&&a.fontawesome)&&(b=''),'"},add:function(b){a.fn.mediumInsert.insert.deselect(),b.append('
Map - Coming soon...
')}})}(jQuery); \ No newline at end of file diff --git a/dist/js/addons/medium-editor-insert-plugin.js b/dist/js/addons/medium-editor-insert-plugin.js deleted file mode 100644 index fc064beff..000000000 --- a/dist/js/addons/medium-editor-insert-plugin.js +++ /dev/null @@ -1,469 +0,0 @@ -/*! - * medium-editor-insert-plugin v0.2.6 - jQuery insert plugin for MediumEditor - * - * Addon Initialization - * - * https://github.com/orthes/medium-editor-insert-plugin - * - * Copyright (c) 2013 Pavel Linkesch (http://linkesch.sk) - * Released under the MIT license - */ - -/* global MediumEditor */ - -(function ($) { - /* - * Private storage of registered addons - */ - var addons = {}; - - /** - * Extend MediumEditor functions if the editor exists - */ - if (MediumEditor && typeof(MediumEditor) === "function") { - /** - * Extend MediumEditor's serialize function to get rid of unnecesarry Medium Editor Insert Plugin stuff - * - * @return {object} content Object containing HTML content of each element - */ - - MediumEditor.prototype.serialize = function () { - var i, j, - elementid, - content = {}, - $clone, $inserts, $insert, $insertData, html; - for (i = 0; i < this.elements.length; i += 1) { - elementid = (this.elements[i].id !== '') ? this.elements[i].id : 'element-' + i; - - $clone = $(this.elements[i]).clone(); - $inserts = $('.mediumInsert', $clone); - for (j = 0; j < $inserts.length; j++) { - $insert = $($inserts[j]); - $insertData = $('.mediumInsert-placeholder', $insert).children(); - if ($insertData.length === 0) { - $insert.remove(); - } else { - $insert.removeAttr('contenteditable'); - $('img[draggable]', $insert).removeAttr('draggable'); - if ($insert.hasClass('small')) { - $insertData.addClass('small'); - } - $('.mediumInsert-buttons', $insert).remove(); - $insertData.unwrap(); - } - } - - html = $clone.html().trim(); - content[elementid] = { - value: html - }; - } - return content; - }; - - /** - * Extend MediumEditor's deactivate function to call $.fn.mediumInsert.insert.disable function - * - * @return {void} - */ - - MediumEditor.prototype.deactivate = function () { - var i; - if (!this.isActive) { - return false; - } - this.isActive = false; - - if (this.toolbar !== undefined) { - this.toolbar.style.display = 'none'; - } - - document.documentElement.removeEventListener('mouseup', this.checkSelectionWrapper); - - for (i = 0; i < this.elements.length; i += 1) { - this.elements[i].removeEventListener('keyup', this.checkSelectionWrapper); - this.elements[i].removeEventListener('blur', this.checkSelectionWrapper); - this.elements[i].removeAttribute('contentEditable'); - } - - $.fn.mediumInsert.insert.$el.mediumInsert('disable'); - }; - - /** - * Extend MediumEditor's activate function to call $.fn.mediumInsert.insert.enable function - * - * @return {void} - */ - - MediumEditor.prototype.activate = function () { - var i; - if (this.isActive) { - return false; - } - - if (this.toolbar !== undefined) { - this.toolbar.style.display = 'block'; - } - - this.isActive = true; - for (i = 0; i < this.elements.length; i += 1) { - this.elements[i].setAttribute('contentEditable', true); - } - this.bindSelect(); - - $.fn.mediumInsert.insert.$el.mediumInsert('enable'); - }; - } - - /** - * Medium Editor Insert Plugin - * - * @param {object} options Options for the plugin - * @param {void} - */ - - $.fn.mediumInsert = function (options) { - - if (typeof options === 'string' && $.fn.mediumInsert.insert[options]) { - $.fn.mediumInsert.insert[options](); - } else { - $.fn.mediumInsert.settings = $.extend($.fn.mediumInsert.settings, options); - - - - /** - * Initial plugin loop - */ - - return this.each(function () { - $(this).addClass('medium-editor-insert-plugin'); - - var blocks = 'p, h1, h2, h3, h4, h5, h6, ol, ul, blockquote'; - $(this).on('dragover drop', blocks, function (e) { - e.preventDefault(); - return false; - }); - - $.fn.mediumInsert.insert.init($(this)); - - $.each($.fn.mediumInsert.settings.addons, function (i) { - var addonOptions = $.fn.mediumInsert.settings.addons[i]; - addonOptions.$el = $.fn.mediumInsert.insert.$el; - addons[i].init(addonOptions); - }); - }); - } - }; - - - /** - * Settings - */ - $.fn.mediumInsert.settings = { - enabled: true, - addons: { - images: {}, - embeds: {} - } - }; - - /** - * Register new addon - */ - $.fn.mediumInsert.registerAddon = function(name, addon){ - addons[name] = addon; - }; - - /** - * Get registered addon - */ - $.fn.mediumInsert.getAddon = function(name){ - return addons[name]; - }; - - - /** - * Addon Initialization - */ - - $.fn.mediumInsert.insert = { - - /** - * Insert initial function - * - * @param {element} el Parent container element - * @return {void} - */ - - init: function ($el) { - this.$el = $el; - this.isFirefox = navigator.userAgent.match(/firefox/i); - this.setPlaceholders(); - this.setEvents(); - }, - - /** - * Deselect selected text - * - * @return {void} - */ - - deselect: function () { - document.getSelection().removeAllRanges(); - }, - - /** - * Disable the plugin - * - * @return {void} - */ - - disable: function () { - $.fn.mediumInsert.settings.enabled = false; - - $.fn.mediumInsert.insert.$el.find('.mediumInsert-buttons').addClass('hide'); - }, - - /** - * Enable the plugin - * - * @return {void} - */ - - enable: function () { - $.fn.mediumInsert.settings.enabled = true; - - $.fn.mediumInsert.insert.$el.find('.mediumInsert-buttons').removeClass('hide'); - }, - - /** - * Return max id in #mediumInsert-* - * - * @return {int} max (Max number, -1 if no placeholders exist) - */ - getMaxId: function () { - var max = -1; - - $('div[id^="mediumInsert-"]').each(function () { - var id = parseInt($(this).attr('id').split('-')[1], 10); - if (id > max) { - max = id; - } - }); - - return max; - }, - - /** - * Return insert buttons optionally filtered by addon name - * - * @param {string} addon Addon name of addon to display only - * @return {void} - */ - getButtons: function (addon) { - var editor = $.fn.mediumInsert.settings.editor, - buttonLabels = (editor && editor.options) ? editor.options.buttonLabels : '', - buttons = '
'+ - '+'+ - '
'; - - return buttons; - }, - - /** - * Method setting placeholders - * - * @return {void} - */ - - setPlaceholders: function () { - var that = this, - $el = $.fn.mediumInsert.insert.$el, - editor = $.fn.mediumInsert.settings.editor, - buttonLabels = (editor && editor.options) ? editor.options.buttonLabels : '', - insertBlock = this.getButtons(); - - if (insertBlock === false) { - return false; - } - - insertBlock = '
'+ - insertBlock + - '
'+ - '
'; - - if ($el.is(':empty')) { - $el.html('


'); - } - - $el.keyup(function () { - var $lastChild = $el.children(':last'), - i; - - // Fix #39 - // After deleting all content (ctrl+A and delete) in Firefox, all content is deleted and only
appears - // To force placeholder to appear, set


as content of the $el - if ($el.html() === '' || $el.html() === '
') { - $el.html('


'); - } - - if ($lastChild.hasClass('mediumInsert') && $lastChild.find('.mediumInsert-placeholder').children().length > 0) { - $el.append('


'); - } - - // Fix not deleting placeholder in Firefox - // by removing all empty placeholders - if (this.isFirefox){ - $('.mediumInsert .mediumInsert-placeholder:empty', $el).each(function () { - $(this).parent().remove(); - }); - } - - i = that.getMaxId() +1; - - var blocks = 'p, h1, h2, h3, h4, h5, h6, ol, ul, blockquote'; - $el.children(blocks).each(function () { - if ($(this).next().hasClass('mediumInsert') === false) { - $(this).after(insertBlock); - $(this).next('.mediumInsert').attr('id', 'mediumInsert-'+ i); - } - i++; - }); - - }).keyup(); - }, - - - /** - * Set events on placeholders - * - * @return {void} - */ - - setEvents: function () { - var that = this, - $el = $.fn.mediumInsert.insert.$el; - - $el.on('selectstart', '.mediumInsert', function (e) { - e.preventDefault(); - return false; - }); - - $el.on('blur', function () { - var $clone = $(this).clone(), - cloneHtml; - - $clone.find('.mediumInsert').remove(); - cloneHtml = $clone.html().replace(/^\s+|\s+$/g, ''); - - if (cloneHtml === '' || cloneHtml === '


') { - $(this).addClass('medium-editor-placeholder'); - } - }); - - - // Fix #29 - // Sometimes in Firefox when you hit enter,
appears instead of


- // If it happens, force to wrap the
into a paragraph - $el.on('keypress', function (e) { - if (that.isFirefox) { - if (e.keyCode === 13) { - //wrap content text in p to avoid firefox problems - $el.contents().each((function() { - return function(index, field) { - if (field.nodeName === '#text') { - document.execCommand('insertHTML', false, "

" + field.data + "

"); - return field.remove(); - } - }; - })(this)); - //Firefox add extra br tag inside p tag - var latestPTag = $el.find('p').last(); - if (latestPTag.text().length > 0) { - latestPTag.find('br').remove(); - } - } - } - }); - - // Fix #39 - // For some reason Chrome doesn't "select-all", when the last placeholder is visible. - // So it's needed to hide it when the user "selects all", and show it again when they presses any other key. - $el.on('keydown', function (e) { - // Fix Select-all using (ctrl + a) in chrome - if (navigator.userAgent.match(/chrome/i)) { - $el.children().last().removeClass('hide'); - if ( (e.ctrlKey || e.metaKey) && e.which === 65) { - e.preventDefault(); - if($el.find('p').text().trim().length === 0) { - return false; - } - - $el.children().last().addClass('hide'); - return document.execCommand('selectAll', false, null); - } - } - }); - - $el.on('click', '.mediumInsert-buttons a.mediumInsert-buttonsShow', function () { - var $options = $(this).siblings('.mediumInsert-buttonsOptions'), - $placeholder = $(this).parent().siblings('.mediumInsert-placeholder'); - - if ($(this).hasClass('active')) { - $(this).removeClass('active'); - $options.hide(); - - $('a', $options).show(); - } else { - $(this).addClass('active'); - $options.show(); - - $('a', $options).each(function () { - var aClass = $(this).attr('class').split('action-')[1], - plugin = aClass.split('-')[0]; - if ($('.mediumInsert-'+ plugin, $placeholder).length > 0) { - $('a:not(.action-'+ aClass +')', $options).hide(); - } - }); - } - - that.deselect(); - }); - - $el.on('mouseleave', '.mediumInsert', function () { - $('a.mediumInsert-buttonsShow', this).removeClass('active'); - $('.mediumInsert-buttonsOptions', this).hide(); - }); - - $el.on('click', '.mediumInsert-buttons .mediumInsert-action', function (e) { - e.preventDefault(); - - var addon = $(this).data('addon'), - action = $(this).data('action'), - $placeholder = $(this).parents('.mediumInsert-buttons').siblings('.mediumInsert-placeholder'); - - if (addons[addon] && addons[addon][action]) { - addons[addon][action]($placeholder); - } - - $(this).parents('.mediumInsert').mouseleave(); - }); - } - - }; - -}(jQuery)); diff --git a/dist/js/addons/medium-editor-insert-plugin.min.js b/dist/js/addons/medium-editor-insert-plugin.min.js index 076f34809..c8efdf19f 100644 --- a/dist/js/addons/medium-editor-insert-plugin.min.js +++ b/dist/js/addons/medium-editor-insert-plugin.min.js @@ -1,11 +1,10 @@ -/*! - * medium-editor-insert-plugin v0.2.6 - jQuery insert plugin for MediumEditor - * - * Addon Initialization +/*! + * medium-editor-insert-plugin v0.2.7 - jQuery insert plugin for MediumEditor * * https://github.com/orthes/medium-editor-insert-plugin - * - * Copyright (c) 2013 Pavel Linkesch (http://linkesch.sk) + * + * Copyright (c) 2014 Pavel Linkesch (http://linkesch.sk) * Released under the MIT license */ + !function(a){var b={};MediumEditor&&"function"==typeof MediumEditor&&(MediumEditor.prototype.serialize=function(){var b,c,d,e,f,g,h,i,j={};for(b=0;bb&&(b=c)}),b},getButtons:function(c){var d=a.fn.mediumInsert.settings.editor,e=d&&d.options?d.options.buttonLabels:"",f='
+
    ';return 0===Object.keys(a.fn.mediumInsert.settings.addons).length?!1:("undefined"==typeof c?a.each(a.fn.mediumInsert.settings.addons,function(a){f+="
  • "+b[a].insertButton(e)+"
  • "}):f+="
  • "+b[c].insertButton(e)+"
  • ",f+="
")},setPlaceholders:function(){var b=this,c=a.fn.mediumInsert.insert.$el,d=a.fn.mediumInsert.settings.editor,e=(d&&d.options?d.options.buttonLabels:"",this.getButtons());return e===!1?!1:(e='
'+e+'
',c.is(":empty")&&c.html("


"),void c.keyup(function(){var d,f=c.children(":last");(""===c.html()||"
"===c.html())&&c.html("


"),f.hasClass("mediumInsert")&&f.find(".mediumInsert-placeholder").children().length>0&&c.append("


"),this.isFirefox&&a(".mediumInsert .mediumInsert-placeholder:empty",c).each(function(){a(this).parent().remove()}),d=b.getMaxId()+1;var g="p, h1, h2, h3, h4, h5, h6, ol, ul, blockquote";c.children(g).each(function(){a(this).next().hasClass("mediumInsert")===!1&&(a(this).after(e),a(this).next(".mediumInsert").attr("id","mediumInsert-"+d)),d++})}).keyup())},setEvents:function(){var c=this,d=a.fn.mediumInsert.insert.$el;d.on("selectstart",".mediumInsert",function(a){return a.preventDefault(),!1}),d.on("blur",function(){var b,c=a(this).clone();c.find(".mediumInsert").remove(),b=c.html().replace(/^\s+|\s+$/g,""),(""===b||"


"===b)&&a(this).addClass("medium-editor-placeholder")}),d.on("keypress",function(a){if(c.isFirefox&&13===a.keyCode){d.contents().each(function(){return function(a,b){return"#text"===b.nodeName?(document.execCommand("insertHTML",!1,"

"+b.data+"

"),b.remove()):void 0}}(this));var b=d.find("p").last();b.text().length>0&&b.find("br").remove()}}),d.on("keydown",function(a){return navigator.userAgent.match(/chrome/i)&&(d.children().last().removeClass("hide"),(a.ctrlKey||a.metaKey)&&65===a.which)?(a.preventDefault(),0===d.find("p").text().trim().length?!1:(d.children().last().addClass("hide"),document.execCommand("selectAll",!1,null))):void 0}),d.on("click",".mediumInsert-buttons a.mediumInsert-buttonsShow",function(){var b=a(this).siblings(".mediumInsert-buttonsOptions"),d=a(this).parent().siblings(".mediumInsert-placeholder");a(this).hasClass("active")?(a(this).removeClass("active"),b.hide(),a("a",b).show()):(a(this).addClass("active"),b.show(),a("a",b).each(function(){var c=a(this).attr("class").split("action-")[1],e=c.split("-")[0];a(".mediumInsert-"+e,d).length>0&&a("a:not(.action-"+c+")",b).hide()})),c.deselect()}),d.on("mouseleave",".mediumInsert",function(){a("a.mediumInsert-buttonsShow",this).removeClass("active"),a(".mediumInsert-buttonsOptions",this).hide()}),d.on("click",".mediumInsert-buttons .mediumInsert-action",function(c){c.preventDefault();var d=a(this).data("addon"),e=a(this).data("action"),f=a(this).parents(".mediumInsert-buttons").siblings(".mediumInsert-placeholder");b[d]&&b[d][e]&&b[d][e](f),a(this).parents(".mediumInsert").mouseleave()})}}}(jQuery); \ No newline at end of file diff --git a/dist/js/addons/medium-editor-insert-tables.js b/dist/js/addons/medium-editor-insert-tables.js deleted file mode 100644 index 6458b73c2..000000000 --- a/dist/js/addons/medium-editor-insert-tables.js +++ /dev/null @@ -1,129 +0,0 @@ -/*! - * medium-editor-insert-plugin v0.2.6 - jQuery insert plugin for MediumEditor - * - * Tables Addon - * - * https://github.com/orthes/medium-editor-insert-plugin - * - * Copyright (c) 2014 Vexus2 (https://github.com/vexus2) - * Released under the MIT license - */ - -(function ($) { - - $.fn.mediumInsert.registerAddon('tables', { - - /** - * Table default options - */ - - default: { - defaultRows: 2, - defaultCols: 2 - }, - - /** - * Tables initial function - * @return {void} - */ - init : function (options) { - this.options = $.extend(this.default, options); - this.$el = $.fn.mediumInsert.insert.$el; - this.setTableButtonEvents(); - }, - - insertButton : function (buttonLabels) { - var label = 'Table'; - if (buttonLabels == 'fontawesome' || typeof buttonLabels === 'object' && !!(buttonLabels.fontawesome)) { - label = ''; - } - 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 = $(''); - for (j = 0; j < dimensions.cols; j++) { - $row.append(''); - } - $table.append($row); - } - }, - - updateDemoTable : function () { - var $demoTable = $('table.mediumInsert-demoTable'); - - $demoTable.empty(); - this.buildTable($demoTable); - }, - - setEnterActionEvents : function () { - var that = this; - if ($.fn.mediumInsert.settings.enabled === false) { - return false; - } - - var $table = $(''); - that.buildTable($table); - - that.currentPlaceholder.parent().after($table); - that.currentPlaceholder.closest('[data-medium-element]').trigger('keyup').trigger('input'); - }, - - removeToolbar : function () { - $(".mediumInsert-tableDemoBox").remove(); - } - - }); - -}(jQuery)); diff --git a/dist/js/addons/medium-editor-insert-tables.min.js b/dist/js/addons/medium-editor-insert-tables.min.js index 2c8cf837f..425866f60 100644 --- a/dist/js/addons/medium-editor-insert-tables.min.js +++ b/dist/js/addons/medium-editor-insert-tables.min.js @@ -1,11 +1,10 @@ -/*! - * medium-editor-insert-plugin v0.2.6 - jQuery insert plugin for MediumEditor - * - * Tables Addon +/*! + * medium-editor-insert-plugin v0.2.7 - jQuery insert plugin for MediumEditor * * https://github.com/orthes/medium-editor-insert-plugin - * - * Copyright (c) 2014 Vexus2 (https://github.com/vexus2) + * + * Copyright (c) 2014 Pavel Linkesch (http://linkesch.sk) * Released under the MIT license */ + !function(a){a.fn.mediumInsert.registerAddon("tables",{"default":{defaultRows:2,defaultCols:2},init:function(b){this.options=a.extend(this.default,b),this.$el=a.fn.mediumInsert.insert.$el,this.setTableButtonEvents()},insertButton:function(a){var b="Table";return("fontawesome"==a||"object"==typeof a&&a.fontawesome)&&(b=''),'"},add:function(b){a.fn.mediumInsert.insert.deselect();var c='
';a(c).appendTo(b.prev()),this.updateDemoTable(),setTimeout(function(){b.prev().find("input").focus()},50),a.fn.mediumInsert.insert.deselect(),this.currentPlaceholder=b},setTableButtonEvents:function(){var b=this;a(document).on("keyup","input.mediumInsert-tableRows, input.mediumInsert-tableCols",function(){b.updateDemoTable()}),a(document).on("click",function(c){0===a(c.target).parents(".mediumInsert-buttons").length&&b.removeToolbar()}),a(document).on("click","button.mediumInsert-tableReadyButton",function(){b.setEnterActionEvents(),b.removeToolbar()})},getDimensions:function(){return{rows:parseFloat(a("input.mediumInsert-tableRows").val())||1,cols:parseFloat(a("input.mediumInsert-tableCols").val())||1}},buildTable:function(b){var c,d,e,f=this.getDimensions(),g=a(b);for(c=0;c"),d=0;d");g.append(e)}},updateDemoTable:function(){var b=a("table.mediumInsert-demoTable");b.empty(),this.buildTable(b)},setEnterActionEvents:function(){var b=this;if(a.fn.mediumInsert.settings.enabled===!1)return!1;var c=a('');b.buildTable(c),b.currentPlaceholder.parent().after(c),b.currentPlaceholder.closest("[data-medium-element]").trigger("keyup").trigger("input")},removeToolbar:function(){a(".mediumInsert-tableDemoBox").remove()}})}(jQuery); \ No newline at end of file diff --git a/dist/js/medium-editor-insert-plugin.all.js b/dist/js/medium-editor-insert-plugin.all.js deleted file mode 100644 index 1f621c402..000000000 --- a/dist/js/medium-editor-insert-plugin.all.js +++ /dev/null @@ -1,1278 +0,0 @@ -/*! - * medium-editor-insert-plugin v0.2.6 - jQuery insert plugin for MediumEditor - * - * Addon Initialization - * - * https://github.com/orthes/medium-editor-insert-plugin - * - * Copyright (c) 2013 Pavel Linkesch (http://linkesch.sk) - * Released under the MIT license - */ - -/* global MediumEditor */ - -(function ($) { - /* - * Private storage of registered addons - */ - var addons = {}; - - /** - * Extend MediumEditor functions if the editor exists - */ - if (MediumEditor && typeof(MediumEditor) === "function") { - /** - * Extend MediumEditor's serialize function to get rid of unnecesarry Medium Editor Insert Plugin stuff - * - * @return {object} content Object containing HTML content of each element - */ - - MediumEditor.prototype.serialize = function () { - var i, j, - elementid, - content = {}, - $clone, $inserts, $insert, $insertData, html; - for (i = 0; i < this.elements.length; i += 1) { - elementid = (this.elements[i].id !== '') ? this.elements[i].id : 'element-' + i; - - $clone = $(this.elements[i]).clone(); - $inserts = $('.mediumInsert', $clone); - for (j = 0; j < $inserts.length; j++) { - $insert = $($inserts[j]); - $insertData = $('.mediumInsert-placeholder', $insert).children(); - if ($insertData.length === 0) { - $insert.remove(); - } else { - $insert.removeAttr('contenteditable'); - $('img[draggable]', $insert).removeAttr('draggable'); - if ($insert.hasClass('small')) { - $insertData.addClass('small'); - } - $('.mediumInsert-buttons', $insert).remove(); - $insertData.unwrap(); - } - } - - html = $clone.html().trim(); - content[elementid] = { - value: html - }; - } - return content; - }; - - /** - * Extend MediumEditor's deactivate function to call $.fn.mediumInsert.insert.disable function - * - * @return {void} - */ - - MediumEditor.prototype.deactivate = function () { - var i; - if (!this.isActive) { - return false; - } - this.isActive = false; - - if (this.toolbar !== undefined) { - this.toolbar.style.display = 'none'; - } - - document.documentElement.removeEventListener('mouseup', this.checkSelectionWrapper); - - for (i = 0; i < this.elements.length; i += 1) { - this.elements[i].removeEventListener('keyup', this.checkSelectionWrapper); - this.elements[i].removeEventListener('blur', this.checkSelectionWrapper); - this.elements[i].removeAttribute('contentEditable'); - } - - $.fn.mediumInsert.insert.$el.mediumInsert('disable'); - }; - - /** - * Extend MediumEditor's activate function to call $.fn.mediumInsert.insert.enable function - * - * @return {void} - */ - - MediumEditor.prototype.activate = function () { - var i; - if (this.isActive) { - return false; - } - - if (this.toolbar !== undefined) { - this.toolbar.style.display = 'block'; - } - - this.isActive = true; - for (i = 0; i < this.elements.length; i += 1) { - this.elements[i].setAttribute('contentEditable', true); - } - this.bindSelect(); - - $.fn.mediumInsert.insert.$el.mediumInsert('enable'); - }; - } - - /** - * Medium Editor Insert Plugin - * - * @param {object} options Options for the plugin - * @param {void} - */ - - $.fn.mediumInsert = function (options) { - - if (typeof options === 'string' && $.fn.mediumInsert.insert[options]) { - $.fn.mediumInsert.insert[options](); - } else { - $.fn.mediumInsert.settings = $.extend($.fn.mediumInsert.settings, options); - - - - /** - * Initial plugin loop - */ - - return this.each(function () { - $(this).addClass('medium-editor-insert-plugin'); - - var blocks = 'p, h1, h2, h3, h4, h5, h6, ol, ul, blockquote'; - $(this).on('dragover drop', blocks, function (e) { - e.preventDefault(); - return false; - }); - - $.fn.mediumInsert.insert.init($(this)); - - $.each($.fn.mediumInsert.settings.addons, function (i) { - var addonOptions = $.fn.mediumInsert.settings.addons[i]; - addonOptions.$el = $.fn.mediumInsert.insert.$el; - addons[i].init(addonOptions); - }); - }); - } - }; - - - /** - * Settings - */ - $.fn.mediumInsert.settings = { - enabled: true, - addons: { - images: {}, - embeds: {} - } - }; - - /** - * Register new addon - */ - $.fn.mediumInsert.registerAddon = function(name, addon){ - addons[name] = addon; - }; - - /** - * Get registered addon - */ - $.fn.mediumInsert.getAddon = function(name){ - return addons[name]; - }; - - - /** - * Addon Initialization - */ - - $.fn.mediumInsert.insert = { - - /** - * Insert initial function - * - * @param {element} el Parent container element - * @return {void} - */ - - init: function ($el) { - this.$el = $el; - this.isFirefox = navigator.userAgent.match(/firefox/i); - this.setPlaceholders(); - this.setEvents(); - }, - - /** - * Deselect selected text - * - * @return {void} - */ - - deselect: function () { - document.getSelection().removeAllRanges(); - }, - - /** - * Disable the plugin - * - * @return {void} - */ - - disable: function () { - $.fn.mediumInsert.settings.enabled = false; - - $.fn.mediumInsert.insert.$el.find('.mediumInsert-buttons').addClass('hide'); - }, - - /** - * Enable the plugin - * - * @return {void} - */ - - enable: function () { - $.fn.mediumInsert.settings.enabled = true; - - $.fn.mediumInsert.insert.$el.find('.mediumInsert-buttons').removeClass('hide'); - }, - - /** - * Return max id in #mediumInsert-* - * - * @return {int} max (Max number, -1 if no placeholders exist) - */ - getMaxId: function () { - var max = -1; - - $('div[id^="mediumInsert-"]').each(function () { - var id = parseInt($(this).attr('id').split('-')[1], 10); - if (id > max) { - max = id; - } - }); - - return max; - }, - - /** - * Return insert buttons optionally filtered by addon name - * - * @param {string} addon Addon name of addon to display only - * @return {void} - */ - getButtons: function (addon) { - var editor = $.fn.mediumInsert.settings.editor, - buttonLabels = (editor && editor.options) ? editor.options.buttonLabels : '', - buttons = '
'+ - '+'+ - '
    '; - - if (Object.keys($.fn.mediumInsert.settings.addons).length === 0) { - return false; - } - - if (typeof addon === 'undefined') { - $.each($.fn.mediumInsert.settings.addons, function (i) { - buttons += '
  • ' + addons[i].insertButton(buttonLabels) + '
  • '; - }); - } else { - buttons += '
  • ' + addons[addon].insertButton(buttonLabels) + '
  • '; - } - - buttons += '
'; - - return buttons; - }, - - /** - * Method setting placeholders - * - * @return {void} - */ - - setPlaceholders: function () { - var that = this, - $el = $.fn.mediumInsert.insert.$el, - editor = $.fn.mediumInsert.settings.editor, - buttonLabels = (editor && editor.options) ? editor.options.buttonLabels : '', - insertBlock = this.getButtons(); - - if (insertBlock === false) { - return false; - } - - insertBlock = '
'+ - insertBlock + - '
'+ - '
'; - - if ($el.is(':empty')) { - $el.html('


'); - } - - $el.keyup(function () { - var $lastChild = $el.children(':last'), - i; - - // Fix #39 - // After deleting all content (ctrl+A and delete) in Firefox, all content is deleted and only
appears - // To force placeholder to appear, set


as content of the $el - if ($el.html() === '' || $el.html() === '
') { - $el.html('


'); - } - - if ($lastChild.hasClass('mediumInsert') && $lastChild.find('.mediumInsert-placeholder').children().length > 0) { - $el.append('


'); - } - - // Fix not deleting placeholder in Firefox - // by removing all empty placeholders - if (this.isFirefox){ - $('.mediumInsert .mediumInsert-placeholder:empty', $el).each(function () { - $(this).parent().remove(); - }); - } - - i = that.getMaxId() +1; - - var blocks = 'p, h1, h2, h3, h4, h5, h6, ol, ul, blockquote'; - $el.children(blocks).each(function () { - if ($(this).next().hasClass('mediumInsert') === false) { - $(this).after(insertBlock); - $(this).next('.mediumInsert').attr('id', 'mediumInsert-'+ i); - } - i++; - }); - - }).keyup(); - }, - - - /** - * Set events on placeholders - * - * @return {void} - */ - - setEvents: function () { - var that = this, - $el = $.fn.mediumInsert.insert.$el; - - $el.on('selectstart', '.mediumInsert', function (e) { - e.preventDefault(); - return false; - }); - - $el.on('blur', function () { - var $clone = $(this).clone(), - cloneHtml; - - $clone.find('.mediumInsert').remove(); - cloneHtml = $clone.html().replace(/^\s+|\s+$/g, ''); - - if (cloneHtml === '' || cloneHtml === '


') { - $(this).addClass('medium-editor-placeholder'); - } - }); - - - // Fix #29 - // Sometimes in Firefox when you hit enter,
appears instead of


- // If it happens, force to wrap the
into a paragraph - $el.on('keypress', function (e) { - if (that.isFirefox) { - if (e.keyCode === 13) { - //wrap content text in p to avoid firefox problems - $el.contents().each((function() { - return function(index, field) { - if (field.nodeName === '#text') { - document.execCommand('insertHTML', false, "

" + field.data + "

"); - return field.remove(); - } - }; - })(this)); - //Firefox add extra br tag inside p tag - var latestPTag = $el.find('p').last(); - if (latestPTag.text().length > 0) { - latestPTag.find('br').remove(); - } - } - } - }); - - // Fix #39 - // For some reason Chrome doesn't "select-all", when the last placeholder is visible. - // So it's needed to hide it when the user "selects all", and show it again when they presses any other key. - $el.on('keydown', function (e) { - // Fix Select-all using (ctrl + a) in chrome - if (navigator.userAgent.match(/chrome/i)) { - $el.children().last().removeClass('hide'); - if ( (e.ctrlKey || e.metaKey) && e.which === 65) { - e.preventDefault(); - if($el.find('p').text().trim().length === 0) { - return false; - } - - $el.children().last().addClass('hide'); - return document.execCommand('selectAll', false, null); - } - } - }); - - $el.on('click', '.mediumInsert-buttons a.mediumInsert-buttonsShow', function () { - var $options = $(this).siblings('.mediumInsert-buttonsOptions'), - $placeholder = $(this).parent().siblings('.mediumInsert-placeholder'); - - if ($(this).hasClass('active')) { - $(this).removeClass('active'); - $options.hide(); - - $('a', $options).show(); - } else { - $(this).addClass('active'); - $options.show(); - - $('a', $options).each(function () { - var aClass = $(this).attr('class').split('action-')[1], - plugin = aClass.split('-')[0]; - if ($('.mediumInsert-'+ plugin, $placeholder).length > 0) { - $('a:not(.action-'+ aClass +')', $options).hide(); - } - }); - } - - that.deselect(); - }); - - $el.on('mouseleave', '.mediumInsert', function () { - $('a.mediumInsert-buttonsShow', this).removeClass('active'); - $('.mediumInsert-buttonsOptions', this).hide(); - }); - - $el.on('click', '.mediumInsert-buttons .mediumInsert-action', function (e) { - e.preventDefault(); - - var addon = $(this).data('addon'), - action = $(this).data('action'), - $placeholder = $(this).parents('.mediumInsert-buttons').siblings('.mediumInsert-placeholder'); - - if (addons[addon] && addons[addon][action]) { - addons[addon][action]($placeholder); - } - - $(this).parents('.mediumInsert').mouseleave(); - }); - } - - }; - -}(jQuery)); - -/*! - * medium-editor-insert-plugin v0.2.6 - jQuery insert plugin for MediumEditor - * - * Images Addon - * - * https://github.com/orthes/medium-editor-insert-plugin - * - * Copyright (c) 2013 Pavel Linkesch (http://linkesch.sk) - * Released under the MIT license - */ - -(function ($) { - - $.fn.mediumInsert.registerAddon('images', { - - /** - * Images default options - */ - - default: { - /** - * Active or inactive image's drag and drop - */ - useDragAndDrop: true, - - /** - * Relative path to a script that handles file uploads - */ - imagesUploadScript: 'upload.php', - - /** - * Relative path to a script that handles file deleting - */ - imagesDeleteScript: 'delete.php', - - /** - * Format data before sending them to server while uploading an image - * - * @param {File} file File to upload - * @return {object} formData FormData instance - */ - formatData: function (file) { - var formData = new FormData(); - formData.append('file', file); - return formData; - }, - - /** - * Upload single file - * - * @param {element} $placeholder Placeholder to add image to - * @param {File} file File to upload - * @param {object} that Context - * @param {void} - */ - uploadFile: function ($placeholder, file, that) { - $.ajax({ - type: "post", - url: that.options.imagesUploadScript, - xhr: function () { - var xhr = new XMLHttpRequest(); - xhr.upload.onprogress = that.updateProgressBar; - return xhr; - }, - cache: false, - contentType: false, - complete: function (jqxhr) { - that.uploadCompleted(jqxhr, $placeholder); - }, - processData: false, - data: that.options.formatData(file) - }); - }, - - /** - * Makes ajax call for deleting a file on a server - * - * @param {string} file File name - * @param {object} that Context - * @return {void} - */ - deleteFile: function (file, that) { - $.ajax({ - type: "post", - url: that.options.imagesDeleteScript, - data: { - file: file - } - }); - } - }, - - - /** - * Images initial function - * - * @param {object} options Options to overide defaults - * @return {void} - */ - - init: function (options) { - if (options && options.$el) { - this.$el = options.$el; - } - this.options = $.extend(this.default, options); - - this.setImageEvents(); - - if (this.options.useDragAndDrop === true){ - this.setDragAndDropEvents(); - } - - this.preparePreviousImages(); - - }, - - - /** - * Returns insert button - * - * @param {string} buttonLabels - * @return {string} - */ - - insertButton: function(buttonLabels){ - var label = 'Img'; - if (buttonLabels == 'fontawesome' || typeof buttonLabels === 'object' && !!(buttonLabels.fontawesome)) { - label = ''; - } - return ''; - }, - - /** - * Make existing images interactive - * - * @return {void} - */ - - preparePreviousImages: function () { - this.$el.find('.mediumInsert-images').each(function() { - var $parent = $(this).parent(); - $parent.html($.fn.mediumInsert.insert.getButtons('images') + - '
' + $parent.html() + '
' - ); - }); - }, - - /** - * Add image to placeholder - * - * @param {element} $placeholder Placeholder to add image to - * @return {element} $selectFile element - */ - - add: function ($placeholder) { - var that = this, - $selectFile, files; - - $selectFile = $('').click(); - $selectFile.change(function () { - files = this.files; - that.uploadFiles($placeholder, files, that); - }); - - $.fn.mediumInsert.insert.deselect(); - - return $selectFile; - }, - - /** - * Update progressbar while upload - * - * @param {event} e XMLHttpRequest.upload.onprogress event - * @return {void} - */ - - updateProgressBar: function (e) { - var $progress = $('.progress:first', this.$el), - complete; - - if (e.lengthComputable) { - complete = e.loaded / e.total * 100; - complete = complete ? complete : 0; - $progress.attr('value', complete); - $progress.html(complete); - } - }, - - /** - * Show uploaded image after upload completed - * - * @param {jqXHR} jqxhr jqXHR object - * @return {void} - */ - - uploadCompleted: function (jqxhr, $placeholder) { - var $progress = $('.progress:first', $placeholder), - $img; - - $progress.attr('value', 100); - $progress.html(100); - - if (jqxhr.responseText) { - $progress.before('
'); - $img = $progress.siblings('img'); - - $img.load(function () { - $img.parent().mouseleave().mouseenter(); - }); - } else { - $progress.before('
There was a problem uploading the file.
'); - - setTimeout(function () { - $('.mediumInsert-error:first', $placeholder).fadeOut(function () { - $(this).remove(); - }); - }, 3000); - } - - $progress.remove(); - - $placeholder.closest('[data-medium-element]').trigger('keyup').trigger('input'); - }, - - /** - * Upload single file - * - * @param {element} $placeholder Placeholder to add image to - * @param {File} file File to upload - * @param {object} that Context - * @param {void} - */ - - uploadFile: function ($placeholder, file, that) { - return that.options.uploadFile($placeholder, file, that); - }, - - /** - * Lopp though files, check file types and call uploadFile() function on each file that passes - * - * @param {element} placeholder Placeholder to add image to - * @param {FileList} files Files to upload - * @param {object} that Context - * @return {void} - */ - - uploadFiles: function ($placeholder, files, that) { - var acceptedTypes = { - 'image/png': true, - 'image/jpeg': true, - 'image/gif': true - }; - - for (var i = 0; i < files.length; i++) { - var file = files[i]; - - if (acceptedTypes[file.type] === true) { - $placeholder.append('0'); - - that.uploadFile($placeholder, file, that); - } - } - }, - - /** - * Makes ajax call for deleting a file on a server - * - * @param {string} file File name - * @param {object} that Context - * @return {void} - */ - - deleteFile: function (file, that) { - return that.options.deleteFile(file, that); - }, - - /** - * Set image events displaying remove and resize buttons - * - * @return {void} - */ - - setImageEvents: function () { - var that = this; - - this.$el.on('mouseenter', '.mediumInsert-images', function () { - var $img = $('img', this), - positionTop, - positionLeft; - - if ($.fn.mediumInsert.settings.enabled === false) { - return; - } - - if ($img.length > 0) { - $(this).append(''); - - if ($(this).parent().parent().hasClass('small')) { - $(this).append(''); - } else { - $(this).append(''); - } - - positionTop = $img.position().top + parseInt($img.css('margin-top'), 10); - positionLeft = $img.position().left + $img.width() -30; - $('.mediumInsert-imageRemove', this).css({ - 'right': 'auto', - 'top': positionTop, - 'left': positionLeft - }); - $('.mediumInsert-imageResizeBigger, .mediumInsert-imageResizeSmaller', this).css({ - 'right': 'auto', - 'top': positionTop, - 'left': positionLeft-31 - }); - } - }); - - this.$el.on('mouseleave', '.mediumInsert-images', function () { - $('.mediumInsert-imageRemove, .mediumInsert-imageResizeSmaller, .mediumInsert-imageResizeBigger', this).remove(); - }); - - this.$el.on('click', '.mediumInsert-imageResizeSmaller', function () { - $(this).parent().parent().parent().addClass('small'); - $(this).parent().mouseleave().mouseleave(); - - $.fn.mediumInsert.insert.deselect(); - that.$el.closest('[data-medium-element]').trigger('keyup').trigger('input'); - }); - - this.$el.on('click', '.mediumInsert-imageResizeBigger', function () { - $(this).parent().parent().parent().removeClass('small'); - $(this).parent().mouseleave().mouseleave(); - - $.fn.mediumInsert.insert.deselect(); - that.$el.closest('[data-medium-element]').trigger('keyup').trigger('input'); - }); - - this.$el.on('click', '.mediumInsert-imageRemove', function () { - var img = $(this).siblings('img').attr('src'); - - if ($(this).parent().siblings().length === 0) { - $(this).parent().parent().parent().removeClass('small'); - } - $(this).parent().remove(); - - that.deleteFile(img, that); - - $.fn.mediumInsert.insert.deselect(); - that.$el.closest('[data-medium-element]').trigger('keyup').trigger('input'); - }); - }, - - /** - * Set drag and drop events - * - * @return {void} - */ - - setDragAndDropEvents: function () { - var that = this, - dropSuccessful = false, - dropSort = false, - dropSortIndex, dropSortParent; - - $(document).on('dragover', 'body', function () { - if ($.fn.mediumInsert.settings.enabled === false) { - return; - } - - that.$el.addClass('hover'); - }); - - $(document).on('dragend', 'body', function () { - if ($.fn.mediumInsert.settings.enabled === false) { - return; - } - - that.$el.removeClass('hover'); - }); - - this.$el.on('dragover', '.mediumInsert', function () { - if ($.fn.mediumInsert.settings.enabled === false) { - return; - } - - $(this).addClass('hover'); - $(this).attr('contenteditable', true); - }); - - this.$el.on('dragleave', '.mediumInsert', function () { - if ($.fn.mediumInsert.settings.enabled === false) { - return; - } - - $(this).removeClass('hover'); - $(this).attr('contenteditable', false); - }); - - this.$el.on('dragstart', '.mediumInsert .mediumInsert-images img', function () { - if ($.fn.mediumInsert.settings.enabled === false) { - return; - } - - dropSortIndex = $(this).parent().index(); - dropSortParent = $(this).parent().parent().parent().attr('id'); - }); - - this.$el.on('dragend', '.mediumInsert .mediumInsert-images img', function (e) { - if ($.fn.mediumInsert.settings.enabled === false) { - return; - } - - if (dropSuccessful === true) { - if ($(e.originalEvent.target.parentNode).siblings().length === 0) { - $(e.originalEvent.target.parentNode).parent().parent().removeClass('small'); - } - $(e.originalEvent.target.parentNode).mouseleave(); - $(e.originalEvent.target.parentNode).remove(); - dropSuccessful = false; - dropSort = false; - - that.$el.closest('[data-medium-element]').trigger('keyup').trigger('input'); - } - }); - - this.$el.on('dragover', '.mediumInsert .mediumInsert-images img', function (e) { - if ($.fn.mediumInsert.settings.enabled === false) { - return; - } - - e.preventDefault(); - }); - - this.$el.on('drop', '.mediumInsert .mediumInsert-images img', function () { - var index, $dragged, finalIndex; - - if ($.fn.mediumInsert.settings.enabled === false) { - return; - } - - - if (dropSortParent !== $(this).parent().parent().parent().attr('id')) { - dropSort = false; - dropSortIndex = dropSortParent = null; - return; - } - - index = parseInt(dropSortIndex, 10); - - // Sort - $dragged = $(this).parent().parent().find('.mediumInsert-images:nth-child('+ (index+1) +')'); - finalIndex = $(this).parent().index(); - if(index < finalIndex) { - $dragged.insertAfter($(this).parent()); - } else if(index > finalIndex) { - $dragged.insertBefore($(this).parent()); - } - - $dragged.mouseleave(); - - dropSort = true; - dropSortIndex = null; - - that.$el.closest('[data-medium-element]').trigger('keyup').trigger('input'); - }); - - this.$el.on('drop', '.mediumInsert', function (e) { - var files; - - e.preventDefault(); - - if ($.fn.mediumInsert.settings.enabled === false) { - return; - } - - $(this).removeClass('hover'); - that.$el.removeClass('hover'); - $(this).attr('contenteditable', false); - - files = e.originalEvent.dataTransfer.files; - if (files.length > 0) { - // File upload - that.uploadFiles($('.mediumInsert-placeholder', this), files, that); - } else if (dropSort === true) { - dropSort = false; - } else { - // Image move from block to block - $('.mediumInsert-placeholder', this).append('
'+ e.originalEvent.dataTransfer.getData('text/html') +'
'); - $('meta', this).remove(); - dropSuccessful = true; - } - }); - } - }); -}(jQuery)); - -/*! - * medium-editor-insert-plugin v0.2.6 - jQuery insert plugin for MediumEditor - * - * Maps Addon - * - * https://github.com/orthes/medium-editor-insert-plugin - * - * Copyright (c) 2013 Pavel Linkesch (http://linkesch.sk) - * Released under the MIT license - */ - -(function ($) { - - $.fn.mediumInsert.registerAddon('maps', { - - /** - * Maps initial function - * @return {void} - */ - - init: function () { - this.$el = $.fn.mediumInsert.insert.$el; - }, - - insertButton: function(buttonLabels){ - var label = 'Map'; - if (buttonLabels == 'fontawesome' || typeof buttonLabels === 'object' && !!(buttonLabels.fontawesome)) { - label = ''; - } - return ''; - }, - - /** - * Add map to placeholder - * @param {element} placeholder Placeholder to add map to - * @return {void} - */ - - add: function (placeholder) { - $.fn.mediumInsert.insert.deselect(); - - placeholder.append('
Map - Coming soon...
'); - } - - }); - -}(jQuery)); - -/*! - * medium-editor-insert-plugin v0.2.6 - jQuery insert plugin for MediumEditor - * - * Tables Addon - * - * https://github.com/orthes/medium-editor-insert-plugin - * - * Copyright (c) 2014 Vexus2 (https://github.com/vexus2) - * Released under the MIT license - */ - -(function ($) { - - $.fn.mediumInsert.registerAddon('tables', { - - /** - * Table default options - */ - - default: { - defaultRows: 2, - defaultCols: 2 - }, - - /** - * Tables initial function - * @return {void} - */ - init : function (options) { - this.options = $.extend(this.default, options); - this.$el = $.fn.mediumInsert.insert.$el; - this.setTableButtonEvents(); - }, - - insertButton : function (buttonLabels) { - var label = 'Table'; - if (buttonLabels == 'fontawesome' || typeof buttonLabels === 'object' && !!(buttonLabels.fontawesome)) { - label = ''; - } - 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 = $(''); - for (j = 0; j < dimensions.cols; j++) { - $row.append(''); - } - $table.append($row); - } - }, - - updateDemoTable : function () { - var $demoTable = $('table.mediumInsert-demoTable'); - - $demoTable.empty(); - this.buildTable($demoTable); - }, - - setEnterActionEvents : function () { - var that = this; - if ($.fn.mediumInsert.settings.enabled === false) { - return false; - } - - var $table = $(''); - that.buildTable($table); - - that.currentPlaceholder.parent().after($table); - that.currentPlaceholder.closest('[data-medium-element]').trigger('keyup').trigger('input'); - }, - - removeToolbar : function () { - $(".mediumInsert-tableDemoBox").remove(); - } - - }); - -}(jQuery)); - -/*! - * medium-editor-insert-plugin v0.2.6 - jQuery insert plugin for MediumEditor - * - * Embeds Addon - * - * https://github.com/orthes/medium-editor-insert-plugin - * - * Copyright (c) 2014 Vexus2 (https://github.com/vexus2) - * Released under the MIT license - */ - -(function ($) { - - $.fn.mediumInsert.registerAddon('embeds', { - - /** - * Embed default options - */ - - default: { - urlPlaceholder: 'type or paste url here' - }, - - /** - * Embeds initial function - * @return {void} - */ - init : function (options) { - this.options = $.extend(this.default, options); - this.$el = $.fn.mediumInsert.insert.$el; - this.setEmbedButtonEvents(); - this.preparePreviousEmbeds(); - }, - - insertButton : function (buttonLabels) { - var label = 'Embed'; - if (buttonLabels == 'fontawesome' || typeof buttonLabels === 'object' && !!(buttonLabels.fontawesome)) { - label = ''; - } - return ''; - }, - - /** - * Add embed 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()); - setTimeout(function () { - $placeholder.prev().find('input').focus(); - }, 50); - - $.fn.mediumInsert.insert.deselect(); - - this.currentPlaceholder = $placeholder; - $(".mediumInsert-embedsText").focus(); - }, - - /** - * Make existing embeds interactive - * - * @return {void} - */ - - preparePreviousEmbeds: function () { - this.$el.find('.mediumInsert-embeds').each(function() { - var $parent = $(this).parent(); - $parent.html('
' + $parent.html() + '
'); - }); - }, - - setEmbedButtonEvents : function () { - var that = this; - $(document).on('keypress', 'input.mediumInsert-embedsText', function (e) { - if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) { - that.setEnterActionEvents(); - that.removeToolbar(); - } - }); - - this.$el.on('blur', '.mediumInsert-embedsText', function () { - that.removeToolbar(); - }); - - }, - setEnterActionEvents : function () { - var that = this; - if ($.fn.mediumInsert.settings.enabled === false) { - return false; - } - - var url = $("input.mediumInsert-embedsText").val(); - if (!url) { - return false; - } - var embed_tag = that.convertUrlToEmbedTag(url); - if (!embed_tag) { - alert('Incorrect URL format specified'); - return false; - } else { - embed_tag = $('
').append(embed_tag); - that.currentPlaceholder.append(embed_tag); - - that.currentPlaceholder.closest('[data-medium-element]').trigger('keyup').trigger('input'); - } - }, - - removeToolbar : function () { - $(".mediumInsert-embedsWire").remove(); - }, - - convertUrlToEmbedTag : function (url) { - var embed_tag = url.replace(/\n?/g, '').replace(/^((http(s)?:\/\/)?(www\.)?(youtube\.com|youtu\.be)\/(watch\?v=|v\/)?)([a-zA-Z0-9-_]+)(.*)?$/, '
') - .replace(/http:\/\/vimeo\.com\/(\d+)$/, '') - - // TWITTER EMBEDDING NEEDS REWORK! Serialized version of embeded Twitter status is unusable because the Twitter script complitely removes blockquote element and replaces it with iframe - //.replace(/https:\/\/twitter\.com\/(\w+)\/status\/(\d+)\/?$/, '') - - // FACEBOOK EMBEDDING NEEDS REWORK! Similarly to Twitter, FB script removes .fb-post element and replaces it with iframe, which is unusable after serializing editor's content - //.replace(/https:\/\/www\.facebook\.com\/(\w+)\/posts\/(\d+)$/, '
') - - .replace(/http:\/\/instagram\.com\/p\/(.+)\/?$/, ''); - return /<("[^"]*"|'[^']*'|[^'">])*>/.test(embed_tag) ? embed_tag : false; - } - - }); - -}(jQuery)); diff --git a/dist/js/medium-editor-insert-plugin.all.min.js b/dist/js/medium-editor-insert-plugin.all.min.js index 8e578cb1a..610f8390e 100644 --- a/dist/js/medium-editor-insert-plugin.all.min.js +++ b/dist/js/medium-editor-insert-plugin.all.min.js @@ -1,5 +1,5 @@ /*! - * medium-editor-insert-plugin v0.2.6 - jQuery insert plugin for MediumEditor + * medium-editor-insert-plugin v0.2.7 - jQuery insert plugin for MediumEditor * * https://github.com/orthes/medium-editor-insert-plugin * diff --git a/package.json b/package.json index 54765ff95..6c5317a53 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "medium-editor-insert-plugin", - "version": "0.2.6", + "version": "0.2.7", "description": "jQuery insert plugin for MediumEditor", "license": "MIT", "homepage": "https://github.com/orthes/medium-editor-insert-plugin", @@ -19,8 +19,6 @@ "grunt-contrib-qunit": "~0.4.0", "grunt-contrib-compass": "~0.7.2", "grunt-contrib-watch": "~0.6.1", - "grunt-contrib-copy": "~0.5.0", - "grunt-contrib-concat": "^0.4.0", "grunt-autoprefixer": "^0.8.0", "grunt-sass": "~0.14.0", "grunt-csso": "^0.6.2" diff --git a/src/js/medium-editor-insert-embeds.js b/src/js/medium-editor-insert-embeds.js index 7fde24cb8..485c29bf7 100644 --- a/src/js/medium-editor-insert-embeds.js +++ b/src/js/medium-editor-insert-embeds.js @@ -1,14 +1,3 @@ -/*! - * medium-editor-insert-plugin v0.2.6 - jQuery insert plugin for MediumEditor - * - * Embeds Addon - * - * https://github.com/orthes/medium-editor-insert-plugin - * - * Copyright (c) 2014 Vexus2 (https://github.com/vexus2) - * Released under the MIT license - */ - (function ($) { $.fn.mediumInsert.registerAddon('embeds', { diff --git a/src/js/medium-editor-insert-images.js b/src/js/medium-editor-insert-images.js index 8dc6fe1a9..66e4b327d 100644 --- a/src/js/medium-editor-insert-images.js +++ b/src/js/medium-editor-insert-images.js @@ -1,14 +1,3 @@ -/*! - * medium-editor-insert-plugin v0.2.6 - jQuery insert plugin for MediumEditor - * - * Images Addon - * - * https://github.com/orthes/medium-editor-insert-plugin - * - * Copyright (c) 2013 Pavel Linkesch (http://linkesch.sk) - * Released under the MIT license - */ - (function ($) { $.fn.mediumInsert.registerAddon('images', { diff --git a/src/js/medium-editor-insert-maps.js b/src/js/medium-editor-insert-maps.js index 521dfcb12..7d9ddbc96 100644 --- a/src/js/medium-editor-insert-maps.js +++ b/src/js/medium-editor-insert-maps.js @@ -1,14 +1,3 @@ -/*! - * medium-editor-insert-plugin v0.2.6 - jQuery insert plugin for MediumEditor - * - * Maps Addon - * - * https://github.com/orthes/medium-editor-insert-plugin - * - * Copyright (c) 2013 Pavel Linkesch (http://linkesch.sk) - * Released under the MIT license - */ - (function ($) { $.fn.mediumInsert.registerAddon('maps', { diff --git a/src/js/medium-editor-insert-plugin.js b/src/js/medium-editor-insert-plugin.js index fc064beff..3e2fe8ece 100644 --- a/src/js/medium-editor-insert-plugin.js +++ b/src/js/medium-editor-insert-plugin.js @@ -1,14 +1,3 @@ -/*! - * medium-editor-insert-plugin v0.2.6 - jQuery insert plugin for MediumEditor - * - * Addon Initialization - * - * https://github.com/orthes/medium-editor-insert-plugin - * - * Copyright (c) 2013 Pavel Linkesch (http://linkesch.sk) - * Released under the MIT license - */ - /* global MediumEditor */ (function ($) { diff --git a/src/js/medium-editor-insert-tables.js b/src/js/medium-editor-insert-tables.js index 6458b73c2..c163790b9 100644 --- a/src/js/medium-editor-insert-tables.js +++ b/src/js/medium-editor-insert-tables.js @@ -1,14 +1,3 @@ -/*! - * medium-editor-insert-plugin v0.2.6 - jQuery insert plugin for MediumEditor - * - * Tables Addon - * - * https://github.com/orthes/medium-editor-insert-plugin - * - * Copyright (c) 2014 Vexus2 (https://github.com/vexus2) - * Released under the MIT license - */ - (function ($) { $.fn.mediumInsert.registerAddon('tables', {