From 43dc0f77aa8f1cf3a2ea4777904b6659bde23fef Mon Sep 17 00:00:00 2001 From: Roy van Kaathoven Date: Tue, 25 Oct 2016 18:55:39 +0200 Subject: [PATCH 01/32] started dev 3 branch --- README.md | 4 ++-- package.json | 8 +------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 3ea67e9..14e173b 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Inline Attachment 2.0.3 [![Master Branch Build Status](https://api.travis-ci.org/Rovak/InlineAttachment.png?branch=master)](http://travis-ci.org/Rovak/InlineAttachment) +# Inline Attachment 2.0.0 [![Master Branch Build Status](https://api.travis-ci.org/Rovak/InlineAttachment.png?branch=master)](http://travis-ci.org/Rovak/InlineAttachment) Adds upload functionality to a textarea or CodeMirror instance by either drag-dropping or pasting (only in chrome) an image inside it. @@ -36,7 +36,7 @@ Go to the project folder and run the following: ```sh npm install -grunt +gulp ``` This should build the project and the files will appear in the `dist/` folder diff --git a/package.json b/package.json index 2377a7d..82b259e 100644 --- a/package.json +++ b/package.json @@ -7,16 +7,10 @@ "authors": [ "Roy van Kaathoven @razko (https://github.com/rovak)" ], - "version": "2.0.3", + "version": "3.0.0", "dependencies": {}, "devDependencies": { - "grunt": "~0.4.0", - "grunt-contrib-jshint": "0.10.0", - "grunt-contrib-concat": "0.5.0", - "grunt-contrib-uglify": "0.6.0", - "grunt-casperjs": "*" }, "scripts": { - "test": "grunt test" } } From 5affaf3710f84784c12b7b13b3e7e7fb5efe5643 Mon Sep 17 00:00:00 2001 From: Roy van Kaathoven Date: Tue, 25 Oct 2016 18:58:36 +0200 Subject: [PATCH 02/32] update node js version on travis --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 65929f8..7880691 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: node_js node_js: - - 0.10 + - 6.1.x before_script: - npm install -g grunt-cli script: From 5fa5893f300bdbf3c39ecc633220f941adea8f6c Mon Sep 17 00:00:00 2001 From: Roy van Kaathoven Date: Tue, 25 Oct 2016 19:02:58 +0200 Subject: [PATCH 03/32] update readme to v3 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 14e173b..a344484 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Inline Attachment 2.0.0 [![Master Branch Build Status](https://api.travis-ci.org/Rovak/InlineAttachment.png?branch=master)](http://travis-ci.org/Rovak/InlineAttachment) +# Inline Attachment 3.0.0 [![Master Branch Build Status](https://api.travis-ci.org/Rovak/InlineAttachment.png?branch=master)](http://travis-ci.org/Rovak/InlineAttachment) Adds upload functionality to a textarea or CodeMirror instance by either drag-dropping or pasting (only in chrome) an image inside it. From b65217b260ffc8761eb1ecd51c8afec6ff35a348 Mon Sep 17 00:00:00 2001 From: Roy van Kaathoven Date: Tue, 25 Oct 2016 19:14:46 +0200 Subject: [PATCH 04/32] added webpack --- Gruntfile.js | 96 ----------------------------------------------- Gulpfile.js | 51 +++++++++++++++++++++++++ package.json | 19 ++++++---- webpack.config.js | 3 ++ 4 files changed, 66 insertions(+), 103 deletions(-) delete mode 100644 Gruntfile.js create mode 100644 Gulpfile.js create mode 100644 webpack.config.js diff --git a/Gruntfile.js b/Gruntfile.js deleted file mode 100644 index 0b27ea8..0000000 --- a/Gruntfile.js +++ /dev/null @@ -1,96 +0,0 @@ -/** - * Grunt Build File - */ -module.exports = function(grunt) { - - var banner = '/*! <%= pkg.name %> - v<%= pkg.version %> - ' + - '<%= grunt.template.today("yyyy-mm-dd") %> */\n'; - - // Project configuration. - grunt.initConfig({ - pkg: require('./package.json'), - concat: { - options: { - banner: banner - }, - normal: { - src: ['', 'src/inline-attachment.js', 'src/input.inline-attachment.js'], - dest: 'dist/inline-attachment.js' - }, - jquery: { - src: ['', 'src/inline-attachment.js', 'src/jquery.inline-attachment.js'], - dest: 'dist/jquery.inline-attachment.js' - }, - codemirror3: { - src: ['', 'src/inline-attachment.js', 'src/codemirror-3.inline-attachment.js'], - dest: 'dist/codemirror-3.inline-attachment.js' - }, - codemirror4: { - src: ['', 'src/inline-attachment.js', 'src/codemirror-4.inline-attachment.js'], - dest: 'dist/codemirror-4.inline-attachment.js' - }, - angularjs: { - src: ['', 'src/inline-attachment.js', 'src/input.inline-attachment.js', 'src/angularjs.inline-attachment.js'], - dest: 'dist/angularjs.inline-attachment.js' - } - }, - // Lists of files to be minified with UglifyJS. - uglify: { - options: { - banner: banner - }, - normal: { - src: ['', 'dist/inline-attachment.js'], - dest: 'dist/inline-attachment.min.js', - separator: ';' - }, - jquery: { - src: ['', 'dist/jquery.inline-attachment.js'], - dest: 'dist/jquery.inline-attachment.min.js', - separator: ';' - }, - codemirror3: { - src: ['', 'dist/codemirror-3.inline-attachment.js'], - dest: 'dist/codemirror-3.inline-attachment.min.js', - separator: ';' - }, - codemirror4: { - src: ['', 'dist/codemirror-4.inline-attachment.js'], - dest: 'dist/codemirror-4.inline-attachment.min.js', - separator: ';' - }, - angularjs: { - src: ['', 'dist/angularjs.inline-attachment.js'], - dest: 'dist/angularjs.inline-attachment.min.js', - separator: ';' - } - }, - jshint: { - all: ['src/*.js'], - options: { - curly: true, - eqeqeq: true, - eqnull: true, - browser: true, - undef: true, - unused: true, - strict: true, - trailing: true, - indent: 2 - } - }, - casperjs: { - options: { - }, - files: ['tests/*.js'] - } - }); - - grunt.loadNpmTasks('grunt-contrib-jshint'); - grunt.loadNpmTasks('grunt-contrib-concat'); - grunt.loadNpmTasks('grunt-contrib-uglify'); - grunt.loadNpmTasks('grunt-casperjs'); - - grunt.registerTask('qa', ['jshint']); - grunt.registerTask('default', ['qa', 'concat', 'uglify']); -}; diff --git a/Gulpfile.js b/Gulpfile.js new file mode 100644 index 0000000..1cba6ef --- /dev/null +++ b/Gulpfile.js @@ -0,0 +1,51 @@ +const gulp = require("gulp"); +const gutil = require("gulp-util"); +const webpack = require("webpack"); +var path = require("path"); + +function webpackOptions(options) { + return { + watch: options.watch, + entry: { + vanilla: './src/inline-attachment.js', + angular: './src/angularjs.inline-attachment.js', + input: './src/input.inline-attachment.js', + jquery: './src/jquery.inline-attachment.js' + }, + devtool: options.debug ? 'inline-source-map' : '', + debug: options.debug, + output: { + path: __dirname + "/dist", + filename: "[name].js", + publicPath: options.publicPath + }, + resolve: { + root: [path.join(__dirname, "packages")], + extensions: ['', '.js'] + }, + module: { + loaders: [ + { + test: /\.js$/, + exclude: /(node_modules)/, + loader: 'babel-loader', + query: { + presets: ['es2015'] + } + } + ] + } + }; +} + + +gulp.task("default", function(callback) { + webpack(webpackOptions({ + watch: false, + debug: false + }), function(err, stats) { + if(err) throw new gutil.PluginError("webpack", err); + gutil.log("[webpack]", stats.toString()); + callback(); + }); +}); \ No newline at end of file diff --git a/package.json b/package.json index 82b259e..755f1e4 100644 --- a/package.json +++ b/package.json @@ -1,16 +1,21 @@ { "name": "inline-attachment", - "repository" : { - "type" : "git", - "url" : "https://github.com/Rovak/InlineAttachment.git" + "repository": { + "type": "git", + "url": "https://github.com/Rovak/InlineAttachment.git" }, "authors": [ "Roy van Kaathoven @razko (https://github.com/rovak)" ], "version": "3.0.0", - "dependencies": {}, - "devDependencies": { + "dependencies": { + "babel-core": "^6.18.0", + "babel-loader": "^6.2.5", + "babel-preset-es2015": "^6.18.0", + "gulp": "^3.9.1", + "gulp-util": "^3.0.7", + "webpack": "^1.13.2" }, - "scripts": { - } + "devDependencies": {}, + "scripts": {} } diff --git a/webpack.config.js b/webpack.config.js new file mode 100644 index 0000000..591e816 --- /dev/null +++ b/webpack.config.js @@ -0,0 +1,3 @@ +module.exports = function(options) { + +}; From f51a0147a6dbcb6f6b896feeb24dbf91424a8223 Mon Sep 17 00:00:00 2001 From: Roy van Kaathoven Date: Tue, 25 Oct 2016 19:21:56 +0200 Subject: [PATCH 05/32] added watch command for building sources --- Gulpfile.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Gulpfile.js b/Gulpfile.js index 1cba6ef..e511ed3 100644 --- a/Gulpfile.js +++ b/Gulpfile.js @@ -48,4 +48,15 @@ gulp.task("default", function(callback) { gutil.log("[webpack]", stats.toString()); callback(); }); +}); + +gulp.task("watch", function(callback) { + webpack(webpackOptions({ + watch: true, + debug: true + }), function(err, stats) { + if(err) throw new gutil.PluginError("webpack", err); + gutil.log("[webpack]", stats.toString()); + callback(); + }); }); \ No newline at end of file From cc161da1aabf37b677b0da41fe0a5e5ef3d050b9 Mon Sep 17 00:00:00 2001 From: Roy van Kaathoven Date: Tue, 25 Oct 2016 19:22:45 +0200 Subject: [PATCH 06/32] removed callback from watch command --- Gulpfile.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Gulpfile.js b/Gulpfile.js index e511ed3..f3fc447 100644 --- a/Gulpfile.js +++ b/Gulpfile.js @@ -50,13 +50,12 @@ gulp.task("default", function(callback) { }); }); -gulp.task("watch", function(callback) { +gulp.task("watch", function() { webpack(webpackOptions({ watch: true, debug: true }), function(err, stats) { if(err) throw new gutil.PluginError("webpack", err); gutil.log("[webpack]", stats.toString()); - callback(); }); }); \ No newline at end of file From 5ccabb745aa4c068b51f91ef7ef152b879455266 Mon Sep 17 00:00:00 2001 From: Roy van Kaathoven Date: Tue, 25 Oct 2016 19:26:18 +0200 Subject: [PATCH 07/32] moved Utils to separate class --- src/inline-attachment.js | 88 ++------------------------------- src/input.inline-attachment.js | 5 +- src/jquery.inline-attachment.js | 4 +- src/utils.js | 78 +++++++++++++++++++++++++++++ 4 files changed, 89 insertions(+), 86 deletions(-) create mode 100644 src/utils.js diff --git a/src/inline-attachment.js b/src/inline-attachment.js index b2902c1..004dee1 100644 --- a/src/inline-attachment.js +++ b/src/inline-attachment.js @@ -1,3 +1,6 @@ + +import Utils from "./utils"; + /*jslint newcap: true */ /*global XMLHttpRequest: false, FormData: false */ /* @@ -10,7 +13,7 @@ 'use strict'; var inlineAttachment = function(options, instance) { - this.settings = inlineAttachment.util.merge(options, inlineAttachment.defaults); + this.settings = Utils.merge(options, inlineAttachment.defaults); this.editor = instance; this.filenameTag = '{filename}'; this.lastValue = null; @@ -23,89 +26,6 @@ */ inlineAttachment.editors = {}; - /** - * Utility functions - */ - inlineAttachment.util = { - - /** - * Simple function to merge the given objects - * - * @param {Object[]} object Multiple object parameters - * @returns {Object} - */ - merge: function() { - var result = {}; - for (var i = arguments.length - 1; i >= 0; i--) { - var obj = arguments[i]; - for (var k in obj) { - if (obj.hasOwnProperty(k)) { - result[k] = obj[k]; - } - } - } - return result; - }, - - /** - * Append a line of text at the bottom, ensuring there aren't unnecessary newlines - * - * @param {String} appended Current content - * @param {String} previous Value which should be appended after the current content - */ - appendInItsOwnLine: function(previous, appended) { - return (previous + "\n\n[[D]]" + appended) - .replace(/(\n{2,})\[\[D\]\]/, "\n\n") - .replace(/^(\n*)/, ""); - }, - - /** - * Inserts the given value at the current cursor position of the textarea element - * - * @param {HtmlElement} el - * @param {String} value Text which will be inserted at the cursor position - */ - insertTextAtCursor: function(el, text) { - var scrollPos = el.scrollTop, - strPos = 0, - browser = false, - range; - - if ((el.selectionStart || el.selectionStart === '0')) { - browser = "ff"; - } else if (document.selection) { - browser = "ie"; - } - - if (browser === "ie") { - el.focus(); - range = document.selection.createRange(); - range.moveStart('character', -el.value.length); - strPos = range.text.length; - } else if (browser === "ff") { - strPos = el.selectionStart; - } - - var front = (el.value).substring(0, strPos); - var back = (el.value).substring(strPos, el.value.length); - el.value = front + text + back; - strPos = strPos + text.length; - if (browser === "ie") { - el.focus(); - range = document.selection.createRange(); - range.moveStart('character', -el.value.length); - range.moveStart('character', strPos); - range.moveEnd('character', 0); - range.select(); - } else if (browser === "ff") { - el.selectionStart = strPos; - el.selectionEnd = strPos; - el.focus(); - } - el.scrollTop = scrollPos; - } - }; - /** * Default configuration options * diff --git a/src/input.inline-attachment.js b/src/input.inline-attachment.js index 8fdd52f..9b910d4 100644 --- a/src/input.inline-attachment.js +++ b/src/input.inline-attachment.js @@ -1,5 +1,8 @@ /*jslint newcap: true */ /*global inlineAttachment: false */ + +import Utils from "./utils"; + (function() { 'use strict'; @@ -13,7 +16,7 @@ return input.value; }, insertValue: function(val) { - inlineAttachment.util.insertTextAtCursor(input, val); + Utils.insertTextAtCursor(input, val); }, setValue: function(val) { input.value = val; diff --git a/src/jquery.inline-attachment.js b/src/jquery.inline-attachment.js index 29e0e41..4ffdea5 100644 --- a/src/jquery.inline-attachment.js +++ b/src/jquery.inline-attachment.js @@ -1,3 +1,5 @@ +import Utils from "./utils"; + /*jslint newcap: true */ /*global inlineAttachment: false, jQuery: false */ /** @@ -24,7 +26,7 @@ return $this.val(); }, insertValue: function(val) { - inlineAttachment.util.insertTextAtCursor($this[0], val); + Utils.insertTextAtCursor($this[0], val); }, setValue: function(val) { $this.val(val); diff --git a/src/utils.js b/src/utils.js new file mode 100644 index 0000000..cd91f24 --- /dev/null +++ b/src/utils.js @@ -0,0 +1,78 @@ +export default class Utils { + + /** + * Simple function to merge the given objects + * + * @returns {Object} + */ + static merge(...objects) { + var result = {}; + for (var i = objects.length - 1; i >= 0; i--) { + var obj = objects[i]; + for (var k in obj) { + if (obj.hasOwnProperty(k)) { + result[k] = obj[k]; + } + } + } + return result; + } + + /** + * Append a line of text at the bottom, ensuring there aren't unnecessary newlines + * + * @param {String} appended Current content + * @param {String} previous Value which should be appended after the current content + */ + static appendInItsOwnLine(previous, appended) { + return (previous + "\n\n[[D]]" + appended) + .replace(/(\n{2,})\[\[D\]\]/, "\n\n") + .replace(/^(\n*)/, ""); + } + + /** + * Inserts the given value at the current cursor position of the textarea element + * + * @param {HtmlElement} el + * @param {String} text Text which will be inserted at the cursor position + */ + static insertTextAtCursor(el, text) { + var scrollPos = el.scrollTop, + strPos = 0, + browser = false, + range; + + if ((el.selectionStart || el.selectionStart === '0')) { + browser = "ff"; + } else if (document.selection) { + browser = "ie"; + } + + if (browser === "ie") { + el.focus(); + range = document.selection.createRange(); + range.moveStart('character', -el.value.length); + strPos = range.text.length; + } else if (browser === "ff") { + strPos = el.selectionStart; + } + + var front = (el.value).substring(0, strPos); + var back = (el.value).substring(strPos, el.value.length); + el.value = front + text + back; + strPos = strPos + text.length; + if (browser === "ie") { + el.focus(); + range = document.selection.createRange(); + range.moveStart('character', -el.value.length); + range.moveStart('character', strPos); + range.moveEnd('character', 0); + range.select(); + } else if (browser === "ff") { + el.selectionStart = strPos; + el.selectionEnd = strPos; + el.focus(); + } + el.scrollTop = scrollPos; + } +} \ No newline at end of file From f32c06a81a13aef2fa482bc080d253c92f9d05eb Mon Sep 17 00:00:00 2001 From: Roy van Kaathoven Date: Tue, 25 Oct 2016 19:51:18 +0200 Subject: [PATCH 08/32] changed classes to es6 syntax --- Gulpfile.js | 5 +- src/angularjs.inline-attachment.js | 78 +++++------ src/codemirror-3.inline-attachment.js | 47 +++++++ src/codemirror-4.inline-attachment.js | 92 ++++--------- src/defaults.js | 104 ++++++++++++++ src/inline-attachment.js | 188 +++++--------------------- src/input.inline-attachment.js | 91 ++++++------- src/jquery.inline-attachment.js | 93 ++++++------- src/utils.js | 8 ++ 9 files changed, 340 insertions(+), 366 deletions(-) create mode 100644 src/defaults.js diff --git a/Gulpfile.js b/Gulpfile.js index f3fc447..3e69587 100644 --- a/Gulpfile.js +++ b/Gulpfile.js @@ -7,10 +7,11 @@ function webpackOptions(options) { return { watch: options.watch, entry: { - vanilla: './src/inline-attachment.js', angular: './src/angularjs.inline-attachment.js', input: './src/input.inline-attachment.js', - jquery: './src/jquery.inline-attachment.js' + jquery: './src/jquery.inline-attachment.js', + codemirror3: './src/codemirror-3.inline-attachment.js', + codemirror4: './src/codemirror-4.inline-attachment.js', }, devtool: options.debug ? 'inline-source-map' : '', debug: options.debug, diff --git a/src/angularjs.inline-attachment.js b/src/angularjs.inline-attachment.js index cd16129..39fa34b 100644 --- a/src/angularjs.inline-attachment.js +++ b/src/angularjs.inline-attachment.js @@ -1,54 +1,44 @@ /*jslint newcap: true */ /*global inlineAttachment: false, angular: false */ -/** - * AngularJS plugin for inline attachment - * - * @param {document} document - * @param {window} window - * @param {Object} ng - */ -(function(document, window, ng) { - 'use strict'; - inlineAttachment.editors.angular = {}; +import Utils from "./utils"; +import InputInlineAttachment from "./input.inline-attachment"; - var module = ng.module('inlineattachment', []), - attrName = 'inlineattachment'; +let module = ng.module('inlineattachment', []); +let directiveName = 'inlineattachment'; - function lcfirst(str) { - return str.charAt(0).toLowerCase() + str.substr(1); - } - - /** - * Read all parameters from the given attributes object - * - * @param {Object} obj attributes - * @return {Object} - */ - function readParameters(obj, scope) { - var result = {}, - attrs = obj.$attr, - option, value; +/** + * Read all parameters from the given attributes object + * + * @param {Object} obj attributes + * @param scope Angular Scope + * @return {Object} + */ +function readParameters(obj, scope) { + var result = {}, + attrs = obj.$attr, + option, value; - for (var key in attrs) { - option = lcfirst(key.substr(attrName.length)); - value = obj[key]; - // Check if the given key is a valid string type, not empty and starts with the attribute name - if ((option.length > 0) && (key.substring(0, attrName.length) === attrName)) { - result[option] = value; - if (typeof scope[value] === 'function') { - result[option] = scope[value]; - } + for (let key of attrs) { + option = Utils.lcfirst(key.substr(directiveName.length)); + value = obj[key]; + // Check if the given key is a valid string type, not empty and starts with the attribute name + if ((option.length > 0) && (key.substring(0, directiveName.length) === directiveName)) { + result[option] = value; + if (typeof scope[value] === 'function') { + result[option] = scope[value]; } } - - return result; } - module.directive(attrName, function() { - return function(scope, element, attrs) { - var options = readParameters(attrs, scope); - inlineAttachment.editors.input.attachToInput(element.context, options); - }; - }); -})(document, window, angular); + return result; +} + +module.directive(directiveName, function() { + return function(scope, element, attrs) { + var options = readParameters(attrs, scope); + new InputInlineAttachment(element.context, options); + }; +}); + +export default module; \ No newline at end of file diff --git a/src/codemirror-3.inline-attachment.js b/src/codemirror-3.inline-attachment.js index 91fed57..edba3e5 100644 --- a/src/codemirror-3.inline-attachment.js +++ b/src/codemirror-3.inline-attachment.js @@ -1,5 +1,52 @@ /*jslint newcap: true */ /*global inlineAttachment: false */ + +import InlineAttachment from "./inline-attachment"; + +export default class CodeMirror3InlineAttachment { + + constructor(instance, options) { + if (!instance.getWrapperElement) { + throw "Invalid CodeMirror object given"; + } + + this.instance = instance; + this.options = options; + } + + getValue() { + return this.instance.getValue(); + } + + insertValue(value) { + this.instance.replaceSelection(value); + } + + setValue(value) { + let cursor = this.instance.getCursor(); + this.instance.setValue(value); + this.instance.setCursor(cursor); + } + + bind() { + + let inlineAttachment = new InlineAttachment(this, this.options); + let el = this.instance.getWrapperElement(); + + el.addEventListener('paste', function(e) { + inlineAttachment.onPaste(e); + }, false); + + this.instance.setOption('onDragEvent', function(data, e) { + if (e.type === "drop") { + e.stopPropagation(); + e.preventDefault(); + return inlineAttachment.onDrop(e); + } + }); + } +} + /** * CodeMirror version for inlineAttachment * diff --git a/src/codemirror-4.inline-attachment.js b/src/codemirror-4.inline-attachment.js index fd8b764..698717c 100644 --- a/src/codemirror-4.inline-attachment.js +++ b/src/codemirror-4.inline-attachment.js @@ -1,80 +1,44 @@ /*jslint newcap: true */ /*global inlineAttachment: false */ -/** - * CodeMirror version for inlineAttachment - * - * Call inlineAttachment.attach(editor) to attach to a codemirror instance - */ -(function() { - 'use strict'; - var codeMirrorEditor = function(instance) { +import InlineAttachment from "./inline-attachment"; +export default class CodeMirror4InlineAttachment { + + constructor(instance, options) { if (!instance.getWrapperElement) { throw "Invalid CodeMirror object given"; } - this.codeMirror = instance; - }; - - codeMirrorEditor.prototype.getValue = function() { - return this.codeMirror.getValue(); - }; - - codeMirrorEditor.prototype.insertValue = function(val) { - this.codeMirror.replaceSelection(val); - }; - - codeMirrorEditor.prototype.setValue = function(val) { - var cursor = this.codeMirror.getCursor(); - this.codeMirror.setValue(val); - this.codeMirror.setCursor(cursor); - }; - - /** - * Attach InlineAttachment to CodeMirror - * - * @param {CodeMirror} codeMirror - */ - codeMirrorEditor.attach = function(codeMirror, options) { - - options = options || {}; - - var editor = new codeMirrorEditor(codeMirror), - inlineattach = new inlineAttachment(options, editor), - el = codeMirror.getWrapperElement(); + this.instance = instance; + this.options = options; + } - el.addEventListener('paste', function(e) { - inlineattach.onPaste(e); - }, false); + getValue() { + return this.instance.getValue(); + } - codeMirror.setOption('onDragEvent', function(data, e) { - if (e.type === "drop") { - e.stopPropagation(); - e.preventDefault(); - return inlineattach.onDrop(e); - } - }); - }; - - var codeMirrorEditor4 = function(instance) { - codeMirrorEditor.call(this, instance); - }; + insertValue(value) { + this.instance.replaceSelection(value); + } - codeMirrorEditor4.attach = function(codeMirror, options) { + setValue(value) { + let cursor = this.instance.getCursor(); + this.instance.setValue(value); + this.instance.setCursor(cursor); + } - options = options || {}; + bind() { - var editor = new codeMirrorEditor(codeMirror), - inlineattach = new inlineAttachment(options, editor), - el = codeMirror.getWrapperElement(); + let inlineAttachment = new InlineAttachment(options, editor); + let el = this.instance.getWrapperElement(); - el.addEventListener('paste', function(e) { - inlineattach.onPaste(e); + el.addEventListener('paste', function (e) { + inlineAttachment.onPaste(e); }, false); - codeMirror.on('drop', function(data, e) { - if (inlineattach.onDrop(e)) { + this.instance.on('drop', function (data, e) { + if (inlineAttachment.onDrop(e)) { e.stopPropagation(); e.preventDefault(); return true; @@ -82,8 +46,6 @@ return false; } }); - }; - - inlineAttachment.editors.codemirror4 = codeMirrorEditor4; + } -})(); \ No newline at end of file +} \ No newline at end of file diff --git a/src/defaults.js b/src/defaults.js new file mode 100644 index 0000000..a68ed28 --- /dev/null +++ b/src/defaults.js @@ -0,0 +1,104 @@ +/** + * Default Options + */ +export default { + /** + * URL where the file will be send + */ + uploadUrl: 'upload_attachment.php', + + /** + * Which method will be used to send the file to the upload URL + */ + uploadMethod: 'POST', + + /** + * Name in which the file will be placed + */ + uploadFieldName: 'file', + + /** + * Extension which will be used when a file extension could not + * be detected + */ + defaultExtension: 'png', + + /** + * JSON field which refers to the uploaded file URL + */ + jsonFieldName: 'filename', + + /** + * Allowed MIME types + */ + allowedTypes: [ + 'image/jpeg', + 'image/png', + 'image/jpg', + 'image/gif' + ], + + /** + * Text which will be inserted when dropping or pasting a file. + * Acts as a placeholder which will be replaced when the file is done with uploading + */ + progressText: '![Uploading file...]()', + + /** + * When a file has successfully been uploaded the progressText + * will be replaced by the urlText, the {filename} tag will be replaced + * by the filename that has been returned by the server + */ + urlText: "![file]({filename})", + + /** + * Text which will be used when uploading has failed + */ + errorText: "Error uploading file", + + /** + * Extra parameters which will be send when uploading a file + */ + extraParams: {}, + + /** + * Extra headers which will be send when uploading a file + */ + extraHeaders: {}, + + /** + * Before the file is send + */ + beforeFileUpload: function() { + return true; + }, + + /** + * Triggers when a file is dropped or pasted + */ + onFileReceived: function() {}, + + /** + * Custom upload handler + * + * @return {Boolean} when false is returned it will prevent default upload behavior + */ + onFileUploadResponse: function() { + return true; + }, + + /** + * Custom error handler. Runs after removing the placeholder text and before the alert(). + * Return false from this function to prevent the alert dialog. + * + * @return {Boolean} when false is returned it will prevent default error behavior + */ + onFileUploadError: function() { + return true; + }, + + /** + * When a file has succesfully been uploaded + */ + onFileUploaded: function() {} +} \ No newline at end of file diff --git a/src/inline-attachment.js b/src/inline-attachment.js index 004dee1..353cd78 100644 --- a/src/inline-attachment.js +++ b/src/inline-attachment.js @@ -1,137 +1,15 @@ import Utils from "./utils"; +import defaultOptions from "./defaults"; -/*jslint newcap: true */ -/*global XMLHttpRequest: false, FormData: false */ -/* - * Inline Text Attachment - * - * Author: Roy van Kaathoven - * Contact: ik@royvankaathoven.nl - */ -(function(document, window) { - 'use strict'; +export default class InlineAttachment { - var inlineAttachment = function(options, instance) { - this.settings = Utils.merge(options, inlineAttachment.defaults); + constructor(instance, options) { + this.settings = Utils.merge(options, defaultOptions); this.editor = instance; this.filenameTag = '{filename}'; this.lastValue = null; - }; - - /** - * Will holds the available editors - * - * @type {Object} - */ - inlineAttachment.editors = {}; - - /** - * Default configuration options - * - * @type {Object} - */ - inlineAttachment.defaults = { - /** - * URL where the file will be send - */ - uploadUrl: 'upload_attachment.php', - - /** - * Which method will be used to send the file to the upload URL - */ - uploadMethod: 'POST', - - /** - * Name in which the file will be placed - */ - uploadFieldName: 'file', - - /** - * Extension which will be used when a file extension could not - * be detected - */ - defaultExtension: 'png', - - /** - * JSON field which refers to the uploaded file URL - */ - jsonFieldName: 'filename', - - /** - * Allowed MIME types - */ - allowedTypes: [ - 'image/jpeg', - 'image/png', - 'image/jpg', - 'image/gif' - ], - - /** - * Text which will be inserted when dropping or pasting a file. - * Acts as a placeholder which will be replaced when the file is done with uploading - */ - progressText: '![Uploading file...]()', - - /** - * When a file has successfully been uploaded the progressText - * will be replaced by the urlText, the {filename} tag will be replaced - * by the filename that has been returned by the server - */ - urlText: "![file]({filename})", - - /** - * Text which will be used when uploading has failed - */ - errorText: "Error uploading file", - - /** - * Extra parameters which will be send when uploading a file - */ - extraParams: {}, - - /** - * Extra headers which will be send when uploading a file - */ - extraHeaders: {}, - - /** - * Before the file is send - */ - beforeFileUpload: function() { - return true; - }, - - /** - * Triggers when a file is dropped or pasted - */ - onFileReceived: function() {}, - - /** - * Custom upload handler - * - * @return {Boolean} when false is returned it will prevent default upload behavior - */ - onFileUploadResponse: function() { - return true; - }, - - /** - * Custom error handler. Runs after removing the placeholder text and before the alert(). - * Return false from this function to prevent the alert dialog. - * - * @return {Boolean} when false is returned it will prevent default error behavior - */ - onFileUploadError: function() { - return true; - }, - - /** - * When a file has succesfully been uploaded - */ - onFileUploaded: function() {} - }; + } /** * Uploads the blob @@ -139,7 +17,7 @@ import Utils from "./utils"; * @param {Blob} file blob data received from event.dataTransfer object * @return {XMLHttpRequest} request object which sends the file */ - inlineAttachment.prototype.uploadFile = function(file) { + uploadFile(file) { var me = this, formData = new FormData(), xhr = new XMLHttpRequest(), @@ -179,14 +57,14 @@ import Utils from "./utils"; // Add any available extra headers if (typeof settings.extraHeaders === "object") { - for (var header in settings.extraHeaders) { - if (settings.extraHeaders.hasOwnProperty(header)) { - xhr.setRequestHeader(header, settings.extraHeaders[header]); - } + for (var header in settings.extraHeaders) { + if (settings.extraHeaders.hasOwnProperty(header)) { + xhr.setRequestHeader(header, settings.extraHeaders[header]); } + } } - xhr.onload = function() { + xhr.onload = function () { // If HTTP status is OK or Created if (xhr.status === 200 || xhr.status === 201) { me.onFileUploadResponse(xhr); @@ -198,21 +76,23 @@ import Utils from "./utils"; xhr.send(formData); } return xhr; - }; + } /** * Returns if the given file is allowed to handle * - * @param {File} clipboard data file + * @param {File} file clipboard data file */ - inlineAttachment.prototype.isFileAllowed = function(file) { - if (file.kind === 'string') { return false; } - if (this.settings.allowedTypes.indexOf('*') === 0){ + isFileAllowed(file) { + if (file.kind === 'string') { + return false; + } + if (this.settings.allowedTypes.indexOf('*') === 0) { return true; } else { return this.settings.allowedTypes.indexOf(file.type) >= 0; } - }; + } /** * Handles upload response @@ -220,7 +100,8 @@ import Utils from "./utils"; * @param {XMLHttpRequest} xhr * @return {Void} */ - inlineAttachment.prototype.onFileUploadResponse = function(xhr) { + + onFileUploadResponse(xhr) { if (this.settings.onFileUploadResponse.call(this, xhr) !== false) { var result = JSON.parse(xhr.responseText), filename = result[this.settings.jsonFieldName]; @@ -237,7 +118,7 @@ import Utils from "./utils"; this.settings.onFileUploaded.call(this, filename); } } - }; + } /** @@ -246,12 +127,12 @@ import Utils from "./utils"; * @param {XMLHttpRequest} xhr * @return {Void} */ - inlineAttachment.prototype.onFileUploadError = function(xhr) { + onFileUploadError(xhr) { if (this.settings.onFileUploadError.call(this, xhr) !== false) { var text = this.editor.getValue().replace(this.lastValue, ""); this.editor.setValue(text); } - }; + } /** * Called when a file has been inserted, either by drop or paste @@ -259,12 +140,12 @@ import Utils from "./utils"; * @param {File} file * @return {Void} */ - inlineAttachment.prototype.onFileInserted = function(file) { + onFileInserted(file) { if (this.settings.onFileReceived.call(this, file) !== false) { this.lastValue = this.settings.progressText; this.editor.insertValue(this.lastValue); } - }; + } /** @@ -272,7 +153,7 @@ import Utils from "./utils"; * @param {Event} e * @return {Boolean} if the event was handled */ - inlineAttachment.prototype.onPaste = function(e) { + onPaste(e) { var result = false, clipboardData = e.clipboardData, items; @@ -290,17 +171,19 @@ import Utils from "./utils"; } } - if (result) { e.preventDefault(); } + if (result) { + e.preventDefault(); + } return result; - }; + } /** * Called when a drop event occures * @param {Event} e * @return {Boolean} if the event was handled */ - inlineAttachment.prototype.onDrop = function(e) { + onDrop(e) { var result = false; for (var i = 0; i < e.dataTransfer.files.length; i++) { var file = e.dataTransfer.files[i]; @@ -312,8 +195,5 @@ import Utils from "./utils"; } return result; - }; - - window.inlineAttachment = inlineAttachment; - -})(document, window); + } +} diff --git a/src/input.inline-attachment.js b/src/input.inline-attachment.js index 9b910d4..2a38102 100644 --- a/src/input.inline-attachment.js +++ b/src/input.inline-attachment.js @@ -2,50 +2,47 @@ /*global inlineAttachment: false */ import Utils from "./utils"; - -(function() { - 'use strict'; - - inlineAttachment.editors.input = { - Editor: function(instance) { - - var input = instance; - - return { - getValue: function() { - return input.value; - }, - insertValue: function(val) { - Utils.insertTextAtCursor(input, val); - }, - setValue: function(val) { - input.value = val; - } - }; - }, - attachToInput: function(input, options) { - options = options || {}; - - var editor = new inlineAttachment.editors.input.Editor(input), - inlineattach = new inlineAttachment(options, editor); - - input.addEventListener('paste', function(e) { - inlineattach.onPaste(e); - }, false); - input.addEventListener('drop', function(e) { - e.stopPropagation(); - e.preventDefault(); - inlineattach.onDrop(e); - }, false); - input.addEventListener('dragenter', function(e) { - e.stopPropagation(); - e.preventDefault(); - }, false); - input.addEventListener('dragover', function(e) { - e.stopPropagation(); - e.preventDefault(); - }, false); - } - }; - -})(); \ No newline at end of file +import InlineAttachment from "./inline-attachment"; + + +export default class InputInlineAttachment { + + constructor(instance, options) { + this.instance = instance; + this.options = options; + } + + getValue() { + return this.instance.value; + } + + insertValue(val) { + Utils.insertTextAtCursor(this.instance, val); + } + + setValue(val) { + this.instance.value = val; + } + + bind() { + let inlineAttachment = new InlineAttachment(this, this.options); + + this.instance.addEventListener('paste', function (e) { + inlineAttachment.onPaste(e); + }, false); + this.instance.addEventListener('drop', function (e) { + e.stopPropagation(); + e.preventDefault(); + inlineAttachment.onDrop(e); + }, false); + this.instance.addEventListener('dragenter', function (e) { + e.stopPropagation(); + e.preventDefault(); + }, false); + this.instance.addEventListener('dragover', function (e) { + e.stopPropagation(); + e.preventDefault(); + }, false); + } + +} \ No newline at end of file diff --git a/src/jquery.inline-attachment.js b/src/jquery.inline-attachment.js index 4ffdea5..287ba56 100644 --- a/src/jquery.inline-attachment.js +++ b/src/jquery.inline-attachment.js @@ -1,68 +1,53 @@ -import Utils from "./utils"; - /*jslint newcap: true */ /*global inlineAttachment: false, jQuery: false */ -/** - * jQuery plugin for inline attach - * - * @param {document} document - * @param {window} window - * @param {jQuery} $ - */ -(function(document, window, $) { - 'use strict'; - - inlineAttachment.editors.jquery = {}; - /** - * Creates a new editor using jQuery - */ - var editor = function(instance) { +import InlineAttachment from "./inline-attachment"; +import Utils from "./utils"; - var $this = $(instance); +export default class jQueryInlineAttachment { - return { - getValue: function() { - return $this.val(); - }, - insertValue: function(val) { - Utils.insertTextAtCursor($this[0], val); - }, - setValue: function(val) { - $this.val(val); - } - }; - }; + constructor(instance, options) { + this.instance = $(instance); + this.options = options; + } - $.fn.inlineattachment = function(options) { + getValue() { + return this.instance.val(); + } - var set = $(this); + insertValue(val) { + Utils.insertTextAtCursor($this[0], val); + } - set.each(function() { + setValue(val) { + this.instance.val(val); + } - var $this = $(this), - ed = new editor($this), - inlineattach = new inlineAttachment(options, ed); + bind() { + var inlineAttachment = new InlineAttachment(this, this.options); - $this.bind({ - 'paste': function(e) { - inlineattach.onPaste(e.originalEvent); - }, - 'drop': function(e) { - e.stopPropagation(); - e.preventDefault(); - inlineattach.onDrop(e.originalEvent); - }, - 'dragenter dragover': function(e) { - e.stopPropagation(); - e.preventDefault(); - } - }); + this.instance.bind({ + 'paste': function(e) { + inlineAttachment.onPaste(e.originalEvent); + }, + 'drop': function(e) { + e.stopPropagation(); + e.preventDefault(); + inlineAttachment.onDrop(e.originalEvent); + }, + 'dragenter dragover': function(e) { + e.stopPropagation(); + e.preventDefault(); + } }); + } +} - return this; - }; +$.fn.inlineattachment = function(options) { - inlineAttachment.editors.jquery.Editor = editor; + $(this).each(function() { + new jQueryInlineAttachment(this, options); + }); -})(document, window, jQuery); \ No newline at end of file + return this; +}; diff --git a/src/utils.js b/src/utils.js index cd91f24..6014ec7 100644 --- a/src/utils.js +++ b/src/utils.js @@ -18,6 +18,14 @@ export default class Utils { return result; } + /** + * @param str + * @returns {string} Returns the string with the first letter as lowercase + */ + static lcfirst(str) { + return str.charAt(0).toLowerCase() + str.substr(1); + } + /** * Append a line of text at the bottom, ensuring there aren't unnecessary newlines * From f898853d59ad341d1a0774423bcfd8760be3a8ca Mon Sep 17 00:00:00 2001 From: Roy van Kaathoven Date: Tue, 25 Oct 2016 19:53:07 +0200 Subject: [PATCH 09/32] cleanup --- ...ularjs.inline-attachment.js => angular.js} | 2 +- src/codemirror-3.inline-attachment.js | 108 ------------------ src/codemirror-3.js | 48 ++++++++ ...4.inline-attachment.js => codemirror-4.js} | 0 src/{input.inline-attachment.js => input.js} | 0 ...{jquery.inline-attachment.js => jquery.js} | 0 6 files changed, 49 insertions(+), 109 deletions(-) rename src/{angularjs.inline-attachment.js => angular.js} (92%) delete mode 100644 src/codemirror-3.inline-attachment.js create mode 100644 src/codemirror-3.js rename src/{codemirror-4.inline-attachment.js => codemirror-4.js} (100%) rename src/{input.inline-attachment.js => input.js} (100%) rename src/{jquery.inline-attachment.js => jquery.js} (100%) diff --git a/src/angularjs.inline-attachment.js b/src/angular.js similarity index 92% rename from src/angularjs.inline-attachment.js rename to src/angular.js index 39fa34b..f875ed0 100644 --- a/src/angularjs.inline-attachment.js +++ b/src/angular.js @@ -2,7 +2,7 @@ /*global inlineAttachment: false, angular: false */ import Utils from "./utils"; -import InputInlineAttachment from "./input.inline-attachment"; +import InputInlineAttachment from "./input"; let module = ng.module('inlineattachment', []); let directiveName = 'inlineattachment'; diff --git a/src/codemirror-3.inline-attachment.js b/src/codemirror-3.inline-attachment.js deleted file mode 100644 index edba3e5..0000000 --- a/src/codemirror-3.inline-attachment.js +++ /dev/null @@ -1,108 +0,0 @@ -/*jslint newcap: true */ -/*global inlineAttachment: false */ - -import InlineAttachment from "./inline-attachment"; - -export default class CodeMirror3InlineAttachment { - - constructor(instance, options) { - if (!instance.getWrapperElement) { - throw "Invalid CodeMirror object given"; - } - - this.instance = instance; - this.options = options; - } - - getValue() { - return this.instance.getValue(); - } - - insertValue(value) { - this.instance.replaceSelection(value); - } - - setValue(value) { - let cursor = this.instance.getCursor(); - this.instance.setValue(value); - this.instance.setCursor(cursor); - } - - bind() { - - let inlineAttachment = new InlineAttachment(this, this.options); - let el = this.instance.getWrapperElement(); - - el.addEventListener('paste', function(e) { - inlineAttachment.onPaste(e); - }, false); - - this.instance.setOption('onDragEvent', function(data, e) { - if (e.type === "drop") { - e.stopPropagation(); - e.preventDefault(); - return inlineAttachment.onDrop(e); - } - }); - } -} - -/** - * CodeMirror version for inlineAttachment - * - * Call inlineAttachment.attach(editor) to attach to a codemirror instance - */ -(function() { - 'use strict'; - - var codeMirrorEditor = function(instance) { - - if (!instance.getWrapperElement) { - throw "Invalid CodeMirror object given"; - } - - this.codeMirror = instance; - }; - - codeMirrorEditor.prototype.getValue = function() { - return this.codeMirror.getValue(); - }; - - codeMirrorEditor.prototype.insertValue = function(val) { - this.codeMirror.replaceSelection(val); - }; - - codeMirrorEditor.prototype.setValue = function(val) { - var cursor = this.codeMirror.getCursor(); - this.codeMirror.setValue(val); - this.codeMirror.setCursor(cursor); - }; - - /** - * Attach InlineAttachment to CodeMirror - * - * @param {CodeMirror} codeMirror - */ - codeMirrorEditor.attach = function(codeMirror, options) { - - options = options || {}; - - var editor = new codeMirrorEditor(codeMirror), - inlineattach = new inlineAttachment(options, editor), - el = codeMirror.getWrapperElement(); - - el.addEventListener('paste', function(e) { - inlineattach.onPaste(e); - }, false); - - codeMirror.setOption('onDragEvent', function(data, e) { - if (e.type === "drop") { - e.stopPropagation(); - e.preventDefault(); - return inlineattach.onDrop(e); - } - }); - }; - - inlineAttachment.editors.codemirror3 = codeMirrorEditor; -})(); \ No newline at end of file diff --git a/src/codemirror-3.js b/src/codemirror-3.js new file mode 100644 index 0000000..036c63d --- /dev/null +++ b/src/codemirror-3.js @@ -0,0 +1,48 @@ +/*jslint newcap: true */ +/*global inlineAttachment: false */ + +import InlineAttachment from "./inline-attachment"; + +export default class CodeMirror3InlineAttachment { + + constructor(instance, options) { + if (!instance.getWrapperElement) { + throw "Invalid CodeMirror object given"; + } + + this.instance = instance; + this.options = options; + } + + getValue() { + return this.instance.getValue(); + } + + insertValue(value) { + this.instance.replaceSelection(value); + } + + setValue(value) { + let cursor = this.instance.getCursor(); + this.instance.setValue(value); + this.instance.setCursor(cursor); + } + + bind() { + + let inlineAttachment = new InlineAttachment(this, this.options); + let el = this.instance.getWrapperElement(); + + el.addEventListener('paste', function(e) { + inlineAttachment.onPaste(e); + }, false); + + this.instance.setOption('onDragEvent', function(data, e) { + if (e.type === "drop") { + e.stopPropagation(); + e.preventDefault(); + return inlineAttachment.onDrop(e); + } + }); + } +} \ No newline at end of file diff --git a/src/codemirror-4.inline-attachment.js b/src/codemirror-4.js similarity index 100% rename from src/codemirror-4.inline-attachment.js rename to src/codemirror-4.js diff --git a/src/input.inline-attachment.js b/src/input.js similarity index 100% rename from src/input.inline-attachment.js rename to src/input.js diff --git a/src/jquery.inline-attachment.js b/src/jquery.js similarity index 100% rename from src/jquery.inline-attachment.js rename to src/jquery.js From acee22263c9fc6a8795e2b40394b4d65754f693c Mon Sep 17 00:00:00 2001 From: Roy van Kaathoven Date: Tue, 25 Oct 2016 19:55:49 +0200 Subject: [PATCH 10/32] changed nodejs version in travis --- .travis.yml | 2 +- Gulpfile.js | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7880691..1e80f32 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: node_js node_js: - - 6.1.x + - 6.1 before_script: - npm install -g grunt-cli script: diff --git a/Gulpfile.js b/Gulpfile.js index 3e69587..4adaed2 100644 --- a/Gulpfile.js +++ b/Gulpfile.js @@ -7,11 +7,11 @@ function webpackOptions(options) { return { watch: options.watch, entry: { - angular: './src/angularjs.inline-attachment.js', - input: './src/input.inline-attachment.js', - jquery: './src/jquery.inline-attachment.js', - codemirror3: './src/codemirror-3.inline-attachment.js', - codemirror4: './src/codemirror-4.inline-attachment.js', + angular: './src/angularjs.js', + input: './src/input.js', + jquery: './src/jquery.js', + codemirror3: './src/codemirror-3.js', + codemirror4: './src/codemirror-4.js', }, devtool: options.debug ? 'inline-source-map' : '', debug: options.debug, From 4330b94a5112285e50fc454ca8f7628c2bcc4978 Mon Sep 17 00:00:00 2001 From: Roy van Kaathoven Date: Tue, 25 Oct 2016 19:56:33 +0200 Subject: [PATCH 11/32] updated travis ci to gulp --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1e80f32..6e1a6c5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,6 @@ language: node_js node_js: - 6.1 before_script: - - npm install -g grunt-cli + - npm install -g gulp script: - - grunt qa + - gulp From 4e63c50448e595483a820f4805af5e065ba61a0b Mon Sep 17 00:00:00 2001 From: Roy van Kaathoven Date: Tue, 25 Oct 2016 19:57:26 +0200 Subject: [PATCH 12/32] removed tests for now --- tests/drag-drop.js | 17 ----------------- tests/page/drag-drop.html | 21 --------------------- tests/page/pacman.jpg | Bin 13224 -> 0 bytes 3 files changed, 38 deletions(-) delete mode 100644 tests/drag-drop.js delete mode 100644 tests/page/drag-drop.html delete mode 100644 tests/page/pacman.jpg diff --git a/tests/drag-drop.js b/tests/drag-drop.js deleted file mode 100644 index 3803860..0000000 --- a/tests/drag-drop.js +++ /dev/null @@ -1,17 +0,0 @@ -casper.start(); -casper.userAgent('Mozilla/5.0 (Macintosh; Intel Mac OS X)'); -casper.viewport(1024, 768); - -casper.start('./tests/page/drag-drop.html'); - -casper.then(function(){ - this.capture('capture/step-1.jpg'); - this.mouse.down(200, 300); - this.capture('capture/step-2.jpg'); - this.mouse.move(100, 100); - this.capture('capture/step-3.jpg'); - this.mouse.up(100, 100); - this.capture('capture/step-4.jpg'); -}); - -casper.run(); \ No newline at end of file diff --git a/tests/page/drag-drop.html b/tests/page/drag-drop.html deleted file mode 100644 index 166d91f..0000000 --- a/tests/page/drag-drop.html +++ /dev/null @@ -1,21 +0,0 @@ - - - - - Textarea Inline Attachment Demo - - - - - -
- - - - - - - - \ No newline at end of file diff --git a/tests/page/pacman.jpg b/tests/page/pacman.jpg deleted file mode 100644 index 8f57acc8481f006520e866efea752d3c3f2b280b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 13224 zcmb7q1yEc;m+k-of&_v?7$CvjU4uIW8C-+AJA(!ZZUe!C!(hSP-CZWQ1b25{cDHu- z|9AiQs@}a-x4Qb=I^BIwpT6Ju&UsyYT?f3ElaiGJz`?-*Wd7cO*Cl{B;4KmoG7{oj zWMpI%l((qpxbM)>(9nsnaWHX7K9G@;d;kJJQZmzgBxj@m0%>{Z7+KjkIXTH__=I@b z1(`WG+5b%m9102wIvP6RyLW`_pMam(|G%%-P5{ z8V(WZuSPiJzd~*-06aWA90D97GQt~pgnye6++P_MBK9XXQKY|vP2rMLusg-)hy_;R z;dh;>Zg7gLz5WKEBm7m0g@6SR0i5oI2auBk!o%UoKfe8cG|R^^IhnhsxD1*TmNc2_ zmvHpeSF$;7ZBX`*)$W-z^-=TYxa|tRuL(yixY#zY+TBDLyfhcY^Zcao@W!xMuPyOW z>K%U&$~lSTwaKQniS0o~Q;46#n?tIo_oB&MUi&mIBnaOqC5Y!ik(TaVTFtn)OroOO z(!%`;IM3vHdG`uf_CMCdn4zM1MiXzW6xqAWzIz2QE-n35 zYaAf?8M^BX>*Bp2T(P@J|AV-h-IkwOG0@smljhsK&HOcAIW5_JLYZL`(wfy1g#YAc zJ;%~}65|_#kveeJ!qFIn!N)LPmCtf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W>SdmrEj5PxDsukJRMVgee3Lp&2tN$fF2`+n<3cl6eI|F_}qMlhuSKf6v0MfT?wO b@|8C!LG*`ZHTn+ba^#F-|KdD=dxiZUi(5O+ From 49aec77ef47d262dd2c35dd29e43a6ba45a5ac0b Mon Sep 17 00:00:00 2001 From: Roy van Kaathoven Date: Wed, 26 Oct 2016 20:13:38 +0200 Subject: [PATCH 13/32] remove old dist files --- Gulpfile.js | 2 +- dist/angularjs.inline-attachment.js | 503 --------------------- dist/angularjs.inline-attachment.min.js | 2 - dist/codemirror-3.inline-attachment.js | 462 ------------------- dist/codemirror-3.inline-attachment.min.js | 2 - dist/codemirror-4.inline-attachment.js | 490 -------------------- dist/codemirror-4.inline-attachment.min.js | 2 - dist/inline-attachment.js | 449 ------------------ dist/inline-attachment.min.js | 2 - dist/jquery.inline-attachment.js | 467 ------------------- dist/jquery.inline-attachment.min.js | 2 - 11 files changed, 1 insertion(+), 2382 deletions(-) delete mode 100644 dist/angularjs.inline-attachment.js delete mode 100644 dist/angularjs.inline-attachment.min.js delete mode 100644 dist/codemirror-3.inline-attachment.js delete mode 100644 dist/codemirror-3.inline-attachment.min.js delete mode 100644 dist/codemirror-4.inline-attachment.js delete mode 100644 dist/codemirror-4.inline-attachment.min.js delete mode 100644 dist/inline-attachment.js delete mode 100644 dist/inline-attachment.min.js delete mode 100644 dist/jquery.inline-attachment.js delete mode 100644 dist/jquery.inline-attachment.min.js diff --git a/Gulpfile.js b/Gulpfile.js index 4adaed2..dfc925e 100644 --- a/Gulpfile.js +++ b/Gulpfile.js @@ -7,7 +7,7 @@ function webpackOptions(options) { return { watch: options.watch, entry: { - angular: './src/angularjs.js', + angular: './src/angular.js', input: './src/input.js', jquery: './src/jquery.js', codemirror3: './src/codemirror-3.js', diff --git a/dist/angularjs.inline-attachment.js b/dist/angularjs.inline-attachment.js deleted file mode 100644 index 7caf98e..0000000 --- a/dist/angularjs.inline-attachment.js +++ /dev/null @@ -1,503 +0,0 @@ -/*! inline-attachment - v2.0.3 - 2016-08-20 */ -/*jslint newcap: true */ -/*global XMLHttpRequest: false, FormData: false */ -/* - * Inline Text Attachment - * - * Author: Roy van Kaathoven - * Contact: ik@royvankaathoven.nl - */ -(function(document, window) { - 'use strict'; - - var inlineAttachment = function(options, instance) { - this.settings = inlineAttachment.util.merge(options, inlineAttachment.defaults); - this.editor = instance; - this.filenameTag = '{filename}'; - this.lastValue = null; - }; - - /** - * Will holds the available editors - * - * @type {Object} - */ - inlineAttachment.editors = {}; - - /** - * Utility functions - */ - inlineAttachment.util = { - - /** - * Simple function to merge the given objects - * - * @param {Object[]} object Multiple object parameters - * @returns {Object} - */ - merge: function() { - var result = {}; - for (var i = arguments.length - 1; i >= 0; i--) { - var obj = arguments[i]; - for (var k in obj) { - if (obj.hasOwnProperty(k)) { - result[k] = obj[k]; - } - } - } - return result; - }, - - /** - * Append a line of text at the bottom, ensuring there aren't unnecessary newlines - * - * @param {String} appended Current content - * @param {String} previous Value which should be appended after the current content - */ - appendInItsOwnLine: function(previous, appended) { - return (previous + "\n\n[[D]]" + appended) - .replace(/(\n{2,})\[\[D\]\]/, "\n\n") - .replace(/^(\n*)/, ""); - }, - - /** - * Inserts the given value at the current cursor position of the textarea element - * - * @param {HtmlElement} el - * @param {String} value Text which will be inserted at the cursor position - */ - insertTextAtCursor: function(el, text) { - var scrollPos = el.scrollTop, - strPos = 0, - browser = false, - range; - - if ((el.selectionStart || el.selectionStart === '0')) { - browser = "ff"; - } else if (document.selection) { - browser = "ie"; - } - - if (browser === "ie") { - el.focus(); - range = document.selection.createRange(); - range.moveStart('character', -el.value.length); - strPos = range.text.length; - } else if (browser === "ff") { - strPos = el.selectionStart; - } - - var front = (el.value).substring(0, strPos); - var back = (el.value).substring(strPos, el.value.length); - el.value = front + text + back; - strPos = strPos + text.length; - if (browser === "ie") { - el.focus(); - range = document.selection.createRange(); - range.moveStart('character', -el.value.length); - range.moveStart('character', strPos); - range.moveEnd('character', 0); - range.select(); - } else if (browser === "ff") { - el.selectionStart = strPos; - el.selectionEnd = strPos; - el.focus(); - } - el.scrollTop = scrollPos; - } - }; - - /** - * Default configuration options - * - * @type {Object} - */ - inlineAttachment.defaults = { - /** - * URL where the file will be send - */ - uploadUrl: 'upload_attachment.php', - - /** - * Which method will be used to send the file to the upload URL - */ - uploadMethod: 'POST', - - /** - * Name in which the file will be placed - */ - uploadFieldName: 'file', - - /** - * Extension which will be used when a file extension could not - * be detected - */ - defaultExtension: 'png', - - /** - * JSON field which refers to the uploaded file URL - */ - jsonFieldName: 'filename', - - /** - * Allowed MIME types - */ - allowedTypes: [ - 'image/jpeg', - 'image/png', - 'image/jpg', - 'image/gif' - ], - - /** - * Text which will be inserted when dropping or pasting a file. - * Acts as a placeholder which will be replaced when the file is done with uploading - */ - progressText: '![Uploading file...]()', - - /** - * When a file has successfully been uploaded the progressText - * will be replaced by the urlText, the {filename} tag will be replaced - * by the filename that has been returned by the server - */ - urlText: "![file]({filename})", - - /** - * Text which will be used when uploading has failed - */ - errorText: "Error uploading file", - - /** - * Extra parameters which will be send when uploading a file - */ - extraParams: {}, - - /** - * Extra headers which will be send when uploading a file - */ - extraHeaders: {}, - - /** - * Before the file is send - */ - beforeFileUpload: function() { - return true; - }, - - /** - * Triggers when a file is dropped or pasted - */ - onFileReceived: function() {}, - - /** - * Custom upload handler - * - * @return {Boolean} when false is returned it will prevent default upload behavior - */ - onFileUploadResponse: function() { - return true; - }, - - /** - * Custom error handler. Runs after removing the placeholder text and before the alert(). - * Return false from this function to prevent the alert dialog. - * - * @return {Boolean} when false is returned it will prevent default error behavior - */ - onFileUploadError: function() { - return true; - }, - - /** - * When a file has succesfully been uploaded - */ - onFileUploaded: function() {} - }; - - /** - * Uploads the blob - * - * @param {Blob} file blob data received from event.dataTransfer object - * @return {XMLHttpRequest} request object which sends the file - */ - inlineAttachment.prototype.uploadFile = function(file) { - var me = this, - formData = new FormData(), - xhr = new XMLHttpRequest(), - settings = this.settings, - extension = settings.defaultExtension || settings.defualtExtension; - - if (typeof settings.setupFormData === 'function') { - settings.setupFormData(formData, file); - } - - // Attach the file. If coming from clipboard, add a default filename (only works in Chrome for now) - // http://stackoverflow.com/questions/6664967/how-to-give-a-blob-uploaded-as-formdata-a-file-name - if (file.name) { - var fileNameMatches = file.name.match(/\.(.+)$/); - if (fileNameMatches) { - extension = fileNameMatches[1]; - } - } - - var remoteFilename = "image-" + Date.now() + "." + extension; - if (typeof settings.remoteFilename === 'function') { - remoteFilename = settings.remoteFilename(file); - } - - formData.append(settings.uploadFieldName, file, remoteFilename); - - // Append the extra parameters to the formdata - if (typeof settings.extraParams === "object") { - for (var key in settings.extraParams) { - if (settings.extraParams.hasOwnProperty(key)) { - formData.append(key, settings.extraParams[key]); - } - } - } - - xhr.open('POST', settings.uploadUrl); - - // Add any available extra headers - if (typeof settings.extraHeaders === "object") { - for (var header in settings.extraHeaders) { - if (settings.extraHeaders.hasOwnProperty(header)) { - xhr.setRequestHeader(header, settings.extraHeaders[header]); - } - } - } - - xhr.onload = function() { - // If HTTP status is OK or Created - if (xhr.status === 200 || xhr.status === 201) { - me.onFileUploadResponse(xhr); - } else { - me.onFileUploadError(xhr); - } - }; - if (settings.beforeFileUpload(xhr) !== false) { - xhr.send(formData); - } - return xhr; - }; - - /** - * Returns if the given file is allowed to handle - * - * @param {File} clipboard data file - */ - inlineAttachment.prototype.isFileAllowed = function(file) { - if (file.kind === 'string') { return false; } - if (this.settings.allowedTypes.indexOf('*') === 0){ - return true; - } else { - return this.settings.allowedTypes.indexOf(file.type) >= 0; - } - }; - - /** - * Handles upload response - * - * @param {XMLHttpRequest} xhr - * @return {Void} - */ - inlineAttachment.prototype.onFileUploadResponse = function(xhr) { - if (this.settings.onFileUploadResponse.call(this, xhr) !== false) { - var result = JSON.parse(xhr.responseText), - filename = result[this.settings.jsonFieldName]; - - if (result && filename) { - var newValue; - if (typeof this.settings.urlText === 'function') { - newValue = this.settings.urlText.call(this, filename, result); - } else { - newValue = this.settings.urlText.replace(this.filenameTag, filename); - } - var text = this.editor.getValue().replace(this.lastValue, newValue); - this.editor.setValue(text); - this.settings.onFileUploaded.call(this, filename); - } - } - }; - - - /** - * Called when a file has failed to upload - * - * @param {XMLHttpRequest} xhr - * @return {Void} - */ - inlineAttachment.prototype.onFileUploadError = function(xhr) { - if (this.settings.onFileUploadError.call(this, xhr) !== false) { - var text = this.editor.getValue().replace(this.lastValue, ""); - this.editor.setValue(text); - } - }; - - /** - * Called when a file has been inserted, either by drop or paste - * - * @param {File} file - * @return {Void} - */ - inlineAttachment.prototype.onFileInserted = function(file) { - if (this.settings.onFileReceived.call(this, file) !== false) { - this.lastValue = this.settings.progressText; - this.editor.insertValue(this.lastValue); - } - }; - - - /** - * Called when a paste event occured - * @param {Event} e - * @return {Boolean} if the event was handled - */ - inlineAttachment.prototype.onPaste = function(e) { - var result = false, - clipboardData = e.clipboardData, - items; - - if (typeof clipboardData === "object") { - items = clipboardData.items || clipboardData.files || []; - - for (var i = 0; i < items.length; i++) { - var item = items[i]; - if (this.isFileAllowed(item)) { - result = true; - this.onFileInserted(item.getAsFile()); - this.uploadFile(item.getAsFile()); - } - } - } - - if (result) { e.preventDefault(); } - - return result; - }; - - /** - * Called when a drop event occures - * @param {Event} e - * @return {Boolean} if the event was handled - */ - inlineAttachment.prototype.onDrop = function(e) { - var result = false; - for (var i = 0; i < e.dataTransfer.files.length; i++) { - var file = e.dataTransfer.files[i]; - if (this.isFileAllowed(file)) { - result = true; - this.onFileInserted(file); - this.uploadFile(file); - } - } - - return result; - }; - - window.inlineAttachment = inlineAttachment; - -})(document, window); - -/*jslint newcap: true */ -/*global inlineAttachment: false */ -(function() { - 'use strict'; - - inlineAttachment.editors.input = { - Editor: function(instance) { - - var input = instance; - - return { - getValue: function() { - return input.value; - }, - insertValue: function(val) { - inlineAttachment.util.insertTextAtCursor(input, val); - }, - setValue: function(val) { - input.value = val; - } - }; - }, - attachToInput: function(input, options) { - options = options || {}; - - var editor = new inlineAttachment.editors.input.Editor(input), - inlineattach = new inlineAttachment(options, editor); - - input.addEventListener('paste', function(e) { - inlineattach.onPaste(e); - }, false); - input.addEventListener('drop', function(e) { - e.stopPropagation(); - e.preventDefault(); - inlineattach.onDrop(e); - }, false); - input.addEventListener('dragenter', function(e) { - e.stopPropagation(); - e.preventDefault(); - }, false); - input.addEventListener('dragover', function(e) { - e.stopPropagation(); - e.preventDefault(); - }, false); - } - }; - -})(); -/*jslint newcap: true */ -/*global inlineAttachment: false, angular: false */ -/** - * AngularJS plugin for inline attachment - * - * @param {document} document - * @param {window} window - * @param {Object} ng - */ -(function(document, window, ng) { - 'use strict'; - - inlineAttachment.editors.angular = {}; - - var module = ng.module('inlineattachment', []), - attrName = 'inlineattachment'; - - function lcfirst(str) { - return str.charAt(0).toLowerCase() + str.substr(1); - } - - /** - * Read all parameters from the given attributes object - * - * @param {Object} obj attributes - * @return {Object} - */ - function readParameters(obj, scope) { - var result = {}, - attrs = obj.$attr, - option, value; - - for (var key in attrs) { - option = lcfirst(key.substr(attrName.length)); - value = obj[key]; - // Check if the given key is a valid string type, not empty and starts with the attribute name - if ((option.length > 0) && (key.substring(0, attrName.length) === attrName)) { - result[option] = value; - if (typeof scope[value] === 'function') { - result[option] = scope[value]; - } - } - } - - return result; - } - - module.directive(attrName, function() { - return function(scope, element, attrs) { - var options = readParameters(attrs, scope); - inlineAttachment.editors.input.attachToInput(element.context, options); - }; - }); -})(document, window, angular); diff --git a/dist/angularjs.inline-attachment.min.js b/dist/angularjs.inline-attachment.min.js deleted file mode 100644 index 1b0cdbc..0000000 --- a/dist/angularjs.inline-attachment.min.js +++ /dev/null @@ -1,2 +0,0 @@ -/*! inline-attachment - v2.0.3 - 2016-08-20 */ -!function(a,b){"use strict";var c=function(a,b){this.settings=c.util.merge(a,c.defaults),this.editor=b,this.filenameTag="{filename}",this.lastValue=null};c.editors={},c.util={merge:function(){for(var a={},b=arguments.length-1;b>=0;b--){var c=arguments[b];for(var d in c)c.hasOwnProperty(d)&&(a[d]=c[d])}return a},appendInItsOwnLine:function(a,b){return(a+"\n\n[[D]]"+b).replace(/(\n{2,})\[\[D\]\]/,"\n\n").replace(/^(\n*)/,"")},insertTextAtCursor:function(b,c){var d,e=b.scrollTop,f=0,g=!1;b.selectionStart||"0"===b.selectionStart?g="ff":a.selection&&(g="ie"),"ie"===g?(b.focus(),d=a.selection.createRange(),d.moveStart("character",-b.value.length),f=d.text.length):"ff"===g&&(f=b.selectionStart);var h=b.value.substring(0,f),i=b.value.substring(f,b.value.length);b.value=h+c+i,f+=c.length,"ie"===g?(b.focus(),d=a.selection.createRange(),d.moveStart("character",-b.value.length),d.moveStart("character",f),d.moveEnd("character",0),d.select()):"ff"===g&&(b.selectionStart=f,b.selectionEnd=f,b.focus()),b.scrollTop=e}},c.defaults={uploadUrl:"upload_attachment.php",uploadMethod:"POST",uploadFieldName:"file",defaultExtension:"png",jsonFieldName:"filename",allowedTypes:["image/jpeg","image/png","image/jpg","image/gif"],progressText:"![Uploading file...]()",urlText:"![file]({filename})",errorText:"Error uploading file",extraParams:{},extraHeaders:{},beforeFileUpload:function(){return!0},onFileReceived:function(){},onFileUploadResponse:function(){return!0},onFileUploadError:function(){return!0},onFileUploaded:function(){}},c.prototype.uploadFile=function(a){var b=this,c=new FormData,d=new XMLHttpRequest,e=this.settings,f=e.defaultExtension||e.defualtExtension;if("function"==typeof e.setupFormData&&e.setupFormData(c,a),a.name){var g=a.name.match(/\.(.+)$/);g&&(f=g[1])}var h="image-"+Date.now()+"."+f;if("function"==typeof e.remoteFilename&&(h=e.remoteFilename(a)),c.append(e.uploadFieldName,a,h),"object"==typeof e.extraParams)for(var i in e.extraParams)e.extraParams.hasOwnProperty(i)&&c.append(i,e.extraParams[i]);if(d.open("POST",e.uploadUrl),"object"==typeof e.extraHeaders)for(var j in e.extraHeaders)e.extraHeaders.hasOwnProperty(j)&&d.setRequestHeader(j,e.extraHeaders[j]);return d.onload=function(){200===d.status||201===d.status?b.onFileUploadResponse(d):b.onFileUploadError(d)},e.beforeFileUpload(d)!==!1&&d.send(c),d},c.prototype.isFileAllowed=function(a){return"string"===a.kind?!1:0===this.settings.allowedTypes.indexOf("*")?!0:this.settings.allowedTypes.indexOf(a.type)>=0},c.prototype.onFileUploadResponse=function(a){if(this.settings.onFileUploadResponse.call(this,a)!==!1){var b=JSON.parse(a.responseText),c=b[this.settings.jsonFieldName];if(b&&c){var d;d="function"==typeof this.settings.urlText?this.settings.urlText.call(this,c,b):this.settings.urlText.replace(this.filenameTag,c);var e=this.editor.getValue().replace(this.lastValue,d);this.editor.setValue(e),this.settings.onFileUploaded.call(this,c)}}},c.prototype.onFileUploadError=function(a){if(this.settings.onFileUploadError.call(this,a)!==!1){var b=this.editor.getValue().replace(this.lastValue,"");this.editor.setValue(b)}},c.prototype.onFileInserted=function(a){this.settings.onFileReceived.call(this,a)!==!1&&(this.lastValue=this.settings.progressText,this.editor.insertValue(this.lastValue))},c.prototype.onPaste=function(a){var b,c=!1,d=a.clipboardData;if("object"==typeof d){b=d.items||d.files||[];for(var e=0;e0&&i.substring(0,g.length)===g&&(f[c]=e,"function"==typeof b[e]&&(f[c]=b[e]));return f}inlineAttachment.editors.angular={};var f=c.module("inlineattachment",[]),g="inlineattachment";f.directive(g,function(){return function(a,b,c){var d=e(c,a);inlineAttachment.editors.input.attachToInput(b.context,d)}})}(document,window,angular); \ No newline at end of file diff --git a/dist/codemirror-3.inline-attachment.js b/dist/codemirror-3.inline-attachment.js deleted file mode 100644 index f794e51..0000000 --- a/dist/codemirror-3.inline-attachment.js +++ /dev/null @@ -1,462 +0,0 @@ -/*! inline-attachment - v2.0.3 - 2016-08-20 */ -/*jslint newcap: true */ -/*global XMLHttpRequest: false, FormData: false */ -/* - * Inline Text Attachment - * - * Author: Roy van Kaathoven - * Contact: ik@royvankaathoven.nl - */ -(function(document, window) { - 'use strict'; - - var inlineAttachment = function(options, instance) { - this.settings = inlineAttachment.util.merge(options, inlineAttachment.defaults); - this.editor = instance; - this.filenameTag = '{filename}'; - this.lastValue = null; - }; - - /** - * Will holds the available editors - * - * @type {Object} - */ - inlineAttachment.editors = {}; - - /** - * Utility functions - */ - inlineAttachment.util = { - - /** - * Simple function to merge the given objects - * - * @param {Object[]} object Multiple object parameters - * @returns {Object} - */ - merge: function() { - var result = {}; - for (var i = arguments.length - 1; i >= 0; i--) { - var obj = arguments[i]; - for (var k in obj) { - if (obj.hasOwnProperty(k)) { - result[k] = obj[k]; - } - } - } - return result; - }, - - /** - * Append a line of text at the bottom, ensuring there aren't unnecessary newlines - * - * @param {String} appended Current content - * @param {String} previous Value which should be appended after the current content - */ - appendInItsOwnLine: function(previous, appended) { - return (previous + "\n\n[[D]]" + appended) - .replace(/(\n{2,})\[\[D\]\]/, "\n\n") - .replace(/^(\n*)/, ""); - }, - - /** - * Inserts the given value at the current cursor position of the textarea element - * - * @param {HtmlElement} el - * @param {String} value Text which will be inserted at the cursor position - */ - insertTextAtCursor: function(el, text) { - var scrollPos = el.scrollTop, - strPos = 0, - browser = false, - range; - - if ((el.selectionStart || el.selectionStart === '0')) { - browser = "ff"; - } else if (document.selection) { - browser = "ie"; - } - - if (browser === "ie") { - el.focus(); - range = document.selection.createRange(); - range.moveStart('character', -el.value.length); - strPos = range.text.length; - } else if (browser === "ff") { - strPos = el.selectionStart; - } - - var front = (el.value).substring(0, strPos); - var back = (el.value).substring(strPos, el.value.length); - el.value = front + text + back; - strPos = strPos + text.length; - if (browser === "ie") { - el.focus(); - range = document.selection.createRange(); - range.moveStart('character', -el.value.length); - range.moveStart('character', strPos); - range.moveEnd('character', 0); - range.select(); - } else if (browser === "ff") { - el.selectionStart = strPos; - el.selectionEnd = strPos; - el.focus(); - } - el.scrollTop = scrollPos; - } - }; - - /** - * Default configuration options - * - * @type {Object} - */ - inlineAttachment.defaults = { - /** - * URL where the file will be send - */ - uploadUrl: 'upload_attachment.php', - - /** - * Which method will be used to send the file to the upload URL - */ - uploadMethod: 'POST', - - /** - * Name in which the file will be placed - */ - uploadFieldName: 'file', - - /** - * Extension which will be used when a file extension could not - * be detected - */ - defaultExtension: 'png', - - /** - * JSON field which refers to the uploaded file URL - */ - jsonFieldName: 'filename', - - /** - * Allowed MIME types - */ - allowedTypes: [ - 'image/jpeg', - 'image/png', - 'image/jpg', - 'image/gif' - ], - - /** - * Text which will be inserted when dropping or pasting a file. - * Acts as a placeholder which will be replaced when the file is done with uploading - */ - progressText: '![Uploading file...]()', - - /** - * When a file has successfully been uploaded the progressText - * will be replaced by the urlText, the {filename} tag will be replaced - * by the filename that has been returned by the server - */ - urlText: "![file]({filename})", - - /** - * Text which will be used when uploading has failed - */ - errorText: "Error uploading file", - - /** - * Extra parameters which will be send when uploading a file - */ - extraParams: {}, - - /** - * Extra headers which will be send when uploading a file - */ - extraHeaders: {}, - - /** - * Before the file is send - */ - beforeFileUpload: function() { - return true; - }, - - /** - * Triggers when a file is dropped or pasted - */ - onFileReceived: function() {}, - - /** - * Custom upload handler - * - * @return {Boolean} when false is returned it will prevent default upload behavior - */ - onFileUploadResponse: function() { - return true; - }, - - /** - * Custom error handler. Runs after removing the placeholder text and before the alert(). - * Return false from this function to prevent the alert dialog. - * - * @return {Boolean} when false is returned it will prevent default error behavior - */ - onFileUploadError: function() { - return true; - }, - - /** - * When a file has succesfully been uploaded - */ - onFileUploaded: function() {} - }; - - /** - * Uploads the blob - * - * @param {Blob} file blob data received from event.dataTransfer object - * @return {XMLHttpRequest} request object which sends the file - */ - inlineAttachment.prototype.uploadFile = function(file) { - var me = this, - formData = new FormData(), - xhr = new XMLHttpRequest(), - settings = this.settings, - extension = settings.defaultExtension || settings.defualtExtension; - - if (typeof settings.setupFormData === 'function') { - settings.setupFormData(formData, file); - } - - // Attach the file. If coming from clipboard, add a default filename (only works in Chrome for now) - // http://stackoverflow.com/questions/6664967/how-to-give-a-blob-uploaded-as-formdata-a-file-name - if (file.name) { - var fileNameMatches = file.name.match(/\.(.+)$/); - if (fileNameMatches) { - extension = fileNameMatches[1]; - } - } - - var remoteFilename = "image-" + Date.now() + "." + extension; - if (typeof settings.remoteFilename === 'function') { - remoteFilename = settings.remoteFilename(file); - } - - formData.append(settings.uploadFieldName, file, remoteFilename); - - // Append the extra parameters to the formdata - if (typeof settings.extraParams === "object") { - for (var key in settings.extraParams) { - if (settings.extraParams.hasOwnProperty(key)) { - formData.append(key, settings.extraParams[key]); - } - } - } - - xhr.open('POST', settings.uploadUrl); - - // Add any available extra headers - if (typeof settings.extraHeaders === "object") { - for (var header in settings.extraHeaders) { - if (settings.extraHeaders.hasOwnProperty(header)) { - xhr.setRequestHeader(header, settings.extraHeaders[header]); - } - } - } - - xhr.onload = function() { - // If HTTP status is OK or Created - if (xhr.status === 200 || xhr.status === 201) { - me.onFileUploadResponse(xhr); - } else { - me.onFileUploadError(xhr); - } - }; - if (settings.beforeFileUpload(xhr) !== false) { - xhr.send(formData); - } - return xhr; - }; - - /** - * Returns if the given file is allowed to handle - * - * @param {File} clipboard data file - */ - inlineAttachment.prototype.isFileAllowed = function(file) { - if (file.kind === 'string') { return false; } - if (this.settings.allowedTypes.indexOf('*') === 0){ - return true; - } else { - return this.settings.allowedTypes.indexOf(file.type) >= 0; - } - }; - - /** - * Handles upload response - * - * @param {XMLHttpRequest} xhr - * @return {Void} - */ - inlineAttachment.prototype.onFileUploadResponse = function(xhr) { - if (this.settings.onFileUploadResponse.call(this, xhr) !== false) { - var result = JSON.parse(xhr.responseText), - filename = result[this.settings.jsonFieldName]; - - if (result && filename) { - var newValue; - if (typeof this.settings.urlText === 'function') { - newValue = this.settings.urlText.call(this, filename, result); - } else { - newValue = this.settings.urlText.replace(this.filenameTag, filename); - } - var text = this.editor.getValue().replace(this.lastValue, newValue); - this.editor.setValue(text); - this.settings.onFileUploaded.call(this, filename); - } - } - }; - - - /** - * Called when a file has failed to upload - * - * @param {XMLHttpRequest} xhr - * @return {Void} - */ - inlineAttachment.prototype.onFileUploadError = function(xhr) { - if (this.settings.onFileUploadError.call(this, xhr) !== false) { - var text = this.editor.getValue().replace(this.lastValue, ""); - this.editor.setValue(text); - } - }; - - /** - * Called when a file has been inserted, either by drop or paste - * - * @param {File} file - * @return {Void} - */ - inlineAttachment.prototype.onFileInserted = function(file) { - if (this.settings.onFileReceived.call(this, file) !== false) { - this.lastValue = this.settings.progressText; - this.editor.insertValue(this.lastValue); - } - }; - - - /** - * Called when a paste event occured - * @param {Event} e - * @return {Boolean} if the event was handled - */ - inlineAttachment.prototype.onPaste = function(e) { - var result = false, - clipboardData = e.clipboardData, - items; - - if (typeof clipboardData === "object") { - items = clipboardData.items || clipboardData.files || []; - - for (var i = 0; i < items.length; i++) { - var item = items[i]; - if (this.isFileAllowed(item)) { - result = true; - this.onFileInserted(item.getAsFile()); - this.uploadFile(item.getAsFile()); - } - } - } - - if (result) { e.preventDefault(); } - - return result; - }; - - /** - * Called when a drop event occures - * @param {Event} e - * @return {Boolean} if the event was handled - */ - inlineAttachment.prototype.onDrop = function(e) { - var result = false; - for (var i = 0; i < e.dataTransfer.files.length; i++) { - var file = e.dataTransfer.files[i]; - if (this.isFileAllowed(file)) { - result = true; - this.onFileInserted(file); - this.uploadFile(file); - } - } - - return result; - }; - - window.inlineAttachment = inlineAttachment; - -})(document, window); - -/*jslint newcap: true */ -/*global inlineAttachment: false */ -/** - * CodeMirror version for inlineAttachment - * - * Call inlineAttachment.attach(editor) to attach to a codemirror instance - */ -(function() { - 'use strict'; - - var codeMirrorEditor = function(instance) { - - if (!instance.getWrapperElement) { - throw "Invalid CodeMirror object given"; - } - - this.codeMirror = instance; - }; - - codeMirrorEditor.prototype.getValue = function() { - return this.codeMirror.getValue(); - }; - - codeMirrorEditor.prototype.insertValue = function(val) { - this.codeMirror.replaceSelection(val); - }; - - codeMirrorEditor.prototype.setValue = function(val) { - var cursor = this.codeMirror.getCursor(); - this.codeMirror.setValue(val); - this.codeMirror.setCursor(cursor); - }; - - /** - * Attach InlineAttachment to CodeMirror - * - * @param {CodeMirror} codeMirror - */ - codeMirrorEditor.attach = function(codeMirror, options) { - - options = options || {}; - - var editor = new codeMirrorEditor(codeMirror), - inlineattach = new inlineAttachment(options, editor), - el = codeMirror.getWrapperElement(); - - el.addEventListener('paste', function(e) { - inlineattach.onPaste(e); - }, false); - - codeMirror.setOption('onDragEvent', function(data, e) { - if (e.type === "drop") { - e.stopPropagation(); - e.preventDefault(); - return inlineattach.onDrop(e); - } - }); - }; - - inlineAttachment.editors.codemirror3 = codeMirrorEditor; -})(); \ No newline at end of file diff --git a/dist/codemirror-3.inline-attachment.min.js b/dist/codemirror-3.inline-attachment.min.js deleted file mode 100644 index 3d2d625..0000000 --- a/dist/codemirror-3.inline-attachment.min.js +++ /dev/null @@ -1,2 +0,0 @@ -/*! inline-attachment - v2.0.3 - 2016-08-20 */ -!function(a,b){"use strict";var c=function(a,b){this.settings=c.util.merge(a,c.defaults),this.editor=b,this.filenameTag="{filename}",this.lastValue=null};c.editors={},c.util={merge:function(){for(var a={},b=arguments.length-1;b>=0;b--){var c=arguments[b];for(var d in c)c.hasOwnProperty(d)&&(a[d]=c[d])}return a},appendInItsOwnLine:function(a,b){return(a+"\n\n[[D]]"+b).replace(/(\n{2,})\[\[D\]\]/,"\n\n").replace(/^(\n*)/,"")},insertTextAtCursor:function(b,c){var d,e=b.scrollTop,f=0,g=!1;b.selectionStart||"0"===b.selectionStart?g="ff":a.selection&&(g="ie"),"ie"===g?(b.focus(),d=a.selection.createRange(),d.moveStart("character",-b.value.length),f=d.text.length):"ff"===g&&(f=b.selectionStart);var h=b.value.substring(0,f),i=b.value.substring(f,b.value.length);b.value=h+c+i,f+=c.length,"ie"===g?(b.focus(),d=a.selection.createRange(),d.moveStart("character",-b.value.length),d.moveStart("character",f),d.moveEnd("character",0),d.select()):"ff"===g&&(b.selectionStart=f,b.selectionEnd=f,b.focus()),b.scrollTop=e}},c.defaults={uploadUrl:"upload_attachment.php",uploadMethod:"POST",uploadFieldName:"file",defaultExtension:"png",jsonFieldName:"filename",allowedTypes:["image/jpeg","image/png","image/jpg","image/gif"],progressText:"![Uploading file...]()",urlText:"![file]({filename})",errorText:"Error uploading file",extraParams:{},extraHeaders:{},beforeFileUpload:function(){return!0},onFileReceived:function(){},onFileUploadResponse:function(){return!0},onFileUploadError:function(){return!0},onFileUploaded:function(){}},c.prototype.uploadFile=function(a){var b=this,c=new FormData,d=new XMLHttpRequest,e=this.settings,f=e.defaultExtension||e.defualtExtension;if("function"==typeof e.setupFormData&&e.setupFormData(c,a),a.name){var g=a.name.match(/\.(.+)$/);g&&(f=g[1])}var h="image-"+Date.now()+"."+f;if("function"==typeof e.remoteFilename&&(h=e.remoteFilename(a)),c.append(e.uploadFieldName,a,h),"object"==typeof e.extraParams)for(var i in e.extraParams)e.extraParams.hasOwnProperty(i)&&c.append(i,e.extraParams[i]);if(d.open("POST",e.uploadUrl),"object"==typeof e.extraHeaders)for(var j in e.extraHeaders)e.extraHeaders.hasOwnProperty(j)&&d.setRequestHeader(j,e.extraHeaders[j]);return d.onload=function(){200===d.status||201===d.status?b.onFileUploadResponse(d):b.onFileUploadError(d)},e.beforeFileUpload(d)!==!1&&d.send(c),d},c.prototype.isFileAllowed=function(a){return"string"===a.kind?!1:0===this.settings.allowedTypes.indexOf("*")?!0:this.settings.allowedTypes.indexOf(a.type)>=0},c.prototype.onFileUploadResponse=function(a){if(this.settings.onFileUploadResponse.call(this,a)!==!1){var b=JSON.parse(a.responseText),c=b[this.settings.jsonFieldName];if(b&&c){var d;d="function"==typeof this.settings.urlText?this.settings.urlText.call(this,c,b):this.settings.urlText.replace(this.filenameTag,c);var e=this.editor.getValue().replace(this.lastValue,d);this.editor.setValue(e),this.settings.onFileUploaded.call(this,c)}}},c.prototype.onFileUploadError=function(a){if(this.settings.onFileUploadError.call(this,a)!==!1){var b=this.editor.getValue().replace(this.lastValue,"");this.editor.setValue(b)}},c.prototype.onFileInserted=function(a){this.settings.onFileReceived.call(this,a)!==!1&&(this.lastValue=this.settings.progressText,this.editor.insertValue(this.lastValue))},c.prototype.onPaste=function(a){var b,c=!1,d=a.clipboardData;if("object"==typeof d){b=d.items||d.files||[];for(var e=0;e= 0; i--) { - var obj = arguments[i]; - for (var k in obj) { - if (obj.hasOwnProperty(k)) { - result[k] = obj[k]; - } - } - } - return result; - }, - - /** - * Append a line of text at the bottom, ensuring there aren't unnecessary newlines - * - * @param {String} appended Current content - * @param {String} previous Value which should be appended after the current content - */ - appendInItsOwnLine: function(previous, appended) { - return (previous + "\n\n[[D]]" + appended) - .replace(/(\n{2,})\[\[D\]\]/, "\n\n") - .replace(/^(\n*)/, ""); - }, - - /** - * Inserts the given value at the current cursor position of the textarea element - * - * @param {HtmlElement} el - * @param {String} value Text which will be inserted at the cursor position - */ - insertTextAtCursor: function(el, text) { - var scrollPos = el.scrollTop, - strPos = 0, - browser = false, - range; - - if ((el.selectionStart || el.selectionStart === '0')) { - browser = "ff"; - } else if (document.selection) { - browser = "ie"; - } - - if (browser === "ie") { - el.focus(); - range = document.selection.createRange(); - range.moveStart('character', -el.value.length); - strPos = range.text.length; - } else if (browser === "ff") { - strPos = el.selectionStart; - } - - var front = (el.value).substring(0, strPos); - var back = (el.value).substring(strPos, el.value.length); - el.value = front + text + back; - strPos = strPos + text.length; - if (browser === "ie") { - el.focus(); - range = document.selection.createRange(); - range.moveStart('character', -el.value.length); - range.moveStart('character', strPos); - range.moveEnd('character', 0); - range.select(); - } else if (browser === "ff") { - el.selectionStart = strPos; - el.selectionEnd = strPos; - el.focus(); - } - el.scrollTop = scrollPos; - } - }; - - /** - * Default configuration options - * - * @type {Object} - */ - inlineAttachment.defaults = { - /** - * URL where the file will be send - */ - uploadUrl: 'upload_attachment.php', - - /** - * Which method will be used to send the file to the upload URL - */ - uploadMethod: 'POST', - - /** - * Name in which the file will be placed - */ - uploadFieldName: 'file', - - /** - * Extension which will be used when a file extension could not - * be detected - */ - defaultExtension: 'png', - - /** - * JSON field which refers to the uploaded file URL - */ - jsonFieldName: 'filename', - - /** - * Allowed MIME types - */ - allowedTypes: [ - 'image/jpeg', - 'image/png', - 'image/jpg', - 'image/gif' - ], - - /** - * Text which will be inserted when dropping or pasting a file. - * Acts as a placeholder which will be replaced when the file is done with uploading - */ - progressText: '![Uploading file...]()', - - /** - * When a file has successfully been uploaded the progressText - * will be replaced by the urlText, the {filename} tag will be replaced - * by the filename that has been returned by the server - */ - urlText: "![file]({filename})", - - /** - * Text which will be used when uploading has failed - */ - errorText: "Error uploading file", - - /** - * Extra parameters which will be send when uploading a file - */ - extraParams: {}, - - /** - * Extra headers which will be send when uploading a file - */ - extraHeaders: {}, - - /** - * Before the file is send - */ - beforeFileUpload: function() { - return true; - }, - - /** - * Triggers when a file is dropped or pasted - */ - onFileReceived: function() {}, - - /** - * Custom upload handler - * - * @return {Boolean} when false is returned it will prevent default upload behavior - */ - onFileUploadResponse: function() { - return true; - }, - - /** - * Custom error handler. Runs after removing the placeholder text and before the alert(). - * Return false from this function to prevent the alert dialog. - * - * @return {Boolean} when false is returned it will prevent default error behavior - */ - onFileUploadError: function() { - return true; - }, - - /** - * When a file has succesfully been uploaded - */ - onFileUploaded: function() {} - }; - - /** - * Uploads the blob - * - * @param {Blob} file blob data received from event.dataTransfer object - * @return {XMLHttpRequest} request object which sends the file - */ - inlineAttachment.prototype.uploadFile = function(file) { - var me = this, - formData = new FormData(), - xhr = new XMLHttpRequest(), - settings = this.settings, - extension = settings.defaultExtension || settings.defualtExtension; - - if (typeof settings.setupFormData === 'function') { - settings.setupFormData(formData, file); - } - - // Attach the file. If coming from clipboard, add a default filename (only works in Chrome for now) - // http://stackoverflow.com/questions/6664967/how-to-give-a-blob-uploaded-as-formdata-a-file-name - if (file.name) { - var fileNameMatches = file.name.match(/\.(.+)$/); - if (fileNameMatches) { - extension = fileNameMatches[1]; - } - } - - var remoteFilename = "image-" + Date.now() + "." + extension; - if (typeof settings.remoteFilename === 'function') { - remoteFilename = settings.remoteFilename(file); - } - - formData.append(settings.uploadFieldName, file, remoteFilename); - - // Append the extra parameters to the formdata - if (typeof settings.extraParams === "object") { - for (var key in settings.extraParams) { - if (settings.extraParams.hasOwnProperty(key)) { - formData.append(key, settings.extraParams[key]); - } - } - } - - xhr.open('POST', settings.uploadUrl); - - // Add any available extra headers - if (typeof settings.extraHeaders === "object") { - for (var header in settings.extraHeaders) { - if (settings.extraHeaders.hasOwnProperty(header)) { - xhr.setRequestHeader(header, settings.extraHeaders[header]); - } - } - } - - xhr.onload = function() { - // If HTTP status is OK or Created - if (xhr.status === 200 || xhr.status === 201) { - me.onFileUploadResponse(xhr); - } else { - me.onFileUploadError(xhr); - } - }; - if (settings.beforeFileUpload(xhr) !== false) { - xhr.send(formData); - } - return xhr; - }; - - /** - * Returns if the given file is allowed to handle - * - * @param {File} clipboard data file - */ - inlineAttachment.prototype.isFileAllowed = function(file) { - if (file.kind === 'string') { return false; } - if (this.settings.allowedTypes.indexOf('*') === 0){ - return true; - } else { - return this.settings.allowedTypes.indexOf(file.type) >= 0; - } - }; - - /** - * Handles upload response - * - * @param {XMLHttpRequest} xhr - * @return {Void} - */ - inlineAttachment.prototype.onFileUploadResponse = function(xhr) { - if (this.settings.onFileUploadResponse.call(this, xhr) !== false) { - var result = JSON.parse(xhr.responseText), - filename = result[this.settings.jsonFieldName]; - - if (result && filename) { - var newValue; - if (typeof this.settings.urlText === 'function') { - newValue = this.settings.urlText.call(this, filename, result); - } else { - newValue = this.settings.urlText.replace(this.filenameTag, filename); - } - var text = this.editor.getValue().replace(this.lastValue, newValue); - this.editor.setValue(text); - this.settings.onFileUploaded.call(this, filename); - } - } - }; - - - /** - * Called when a file has failed to upload - * - * @param {XMLHttpRequest} xhr - * @return {Void} - */ - inlineAttachment.prototype.onFileUploadError = function(xhr) { - if (this.settings.onFileUploadError.call(this, xhr) !== false) { - var text = this.editor.getValue().replace(this.lastValue, ""); - this.editor.setValue(text); - } - }; - - /** - * Called when a file has been inserted, either by drop or paste - * - * @param {File} file - * @return {Void} - */ - inlineAttachment.prototype.onFileInserted = function(file) { - if (this.settings.onFileReceived.call(this, file) !== false) { - this.lastValue = this.settings.progressText; - this.editor.insertValue(this.lastValue); - } - }; - - - /** - * Called when a paste event occured - * @param {Event} e - * @return {Boolean} if the event was handled - */ - inlineAttachment.prototype.onPaste = function(e) { - var result = false, - clipboardData = e.clipboardData, - items; - - if (typeof clipboardData === "object") { - items = clipboardData.items || clipboardData.files || []; - - for (var i = 0; i < items.length; i++) { - var item = items[i]; - if (this.isFileAllowed(item)) { - result = true; - this.onFileInserted(item.getAsFile()); - this.uploadFile(item.getAsFile()); - } - } - } - - if (result) { e.preventDefault(); } - - return result; - }; - - /** - * Called when a drop event occures - * @param {Event} e - * @return {Boolean} if the event was handled - */ - inlineAttachment.prototype.onDrop = function(e) { - var result = false; - for (var i = 0; i < e.dataTransfer.files.length; i++) { - var file = e.dataTransfer.files[i]; - if (this.isFileAllowed(file)) { - result = true; - this.onFileInserted(file); - this.uploadFile(file); - } - } - - return result; - }; - - window.inlineAttachment = inlineAttachment; - -})(document, window); - -/*jslint newcap: true */ -/*global inlineAttachment: false */ -/** - * CodeMirror version for inlineAttachment - * - * Call inlineAttachment.attach(editor) to attach to a codemirror instance - */ -(function() { - 'use strict'; - - var codeMirrorEditor = function(instance) { - - if (!instance.getWrapperElement) { - throw "Invalid CodeMirror object given"; - } - - this.codeMirror = instance; - }; - - codeMirrorEditor.prototype.getValue = function() { - return this.codeMirror.getValue(); - }; - - codeMirrorEditor.prototype.insertValue = function(val) { - this.codeMirror.replaceSelection(val); - }; - - codeMirrorEditor.prototype.setValue = function(val) { - var cursor = this.codeMirror.getCursor(); - this.codeMirror.setValue(val); - this.codeMirror.setCursor(cursor); - }; - - /** - * Attach InlineAttachment to CodeMirror - * - * @param {CodeMirror} codeMirror - */ - codeMirrorEditor.attach = function(codeMirror, options) { - - options = options || {}; - - var editor = new codeMirrorEditor(codeMirror), - inlineattach = new inlineAttachment(options, editor), - el = codeMirror.getWrapperElement(); - - el.addEventListener('paste', function(e) { - inlineattach.onPaste(e); - }, false); - - codeMirror.setOption('onDragEvent', function(data, e) { - if (e.type === "drop") { - e.stopPropagation(); - e.preventDefault(); - return inlineattach.onDrop(e); - } - }); - }; - - var codeMirrorEditor4 = function(instance) { - codeMirrorEditor.call(this, instance); - }; - - codeMirrorEditor4.attach = function(codeMirror, options) { - - options = options || {}; - - var editor = new codeMirrorEditor(codeMirror), - inlineattach = new inlineAttachment(options, editor), - el = codeMirror.getWrapperElement(); - - el.addEventListener('paste', function(e) { - inlineattach.onPaste(e); - }, false); - - codeMirror.on('drop', function(data, e) { - if (inlineattach.onDrop(e)) { - e.stopPropagation(); - e.preventDefault(); - return true; - } else { - return false; - } - }); - }; - - inlineAttachment.editors.codemirror4 = codeMirrorEditor4; - -})(); \ No newline at end of file diff --git a/dist/codemirror-4.inline-attachment.min.js b/dist/codemirror-4.inline-attachment.min.js deleted file mode 100644 index 689904a..0000000 --- a/dist/codemirror-4.inline-attachment.min.js +++ /dev/null @@ -1,2 +0,0 @@ -/*! inline-attachment - v2.0.3 - 2016-08-20 */ -!function(a,b){"use strict";var c=function(a,b){this.settings=c.util.merge(a,c.defaults),this.editor=b,this.filenameTag="{filename}",this.lastValue=null};c.editors={},c.util={merge:function(){for(var a={},b=arguments.length-1;b>=0;b--){var c=arguments[b];for(var d in c)c.hasOwnProperty(d)&&(a[d]=c[d])}return a},appendInItsOwnLine:function(a,b){return(a+"\n\n[[D]]"+b).replace(/(\n{2,})\[\[D\]\]/,"\n\n").replace(/^(\n*)/,"")},insertTextAtCursor:function(b,c){var d,e=b.scrollTop,f=0,g=!1;b.selectionStart||"0"===b.selectionStart?g="ff":a.selection&&(g="ie"),"ie"===g?(b.focus(),d=a.selection.createRange(),d.moveStart("character",-b.value.length),f=d.text.length):"ff"===g&&(f=b.selectionStart);var h=b.value.substring(0,f),i=b.value.substring(f,b.value.length);b.value=h+c+i,f+=c.length,"ie"===g?(b.focus(),d=a.selection.createRange(),d.moveStart("character",-b.value.length),d.moveStart("character",f),d.moveEnd("character",0),d.select()):"ff"===g&&(b.selectionStart=f,b.selectionEnd=f,b.focus()),b.scrollTop=e}},c.defaults={uploadUrl:"upload_attachment.php",uploadMethod:"POST",uploadFieldName:"file",defaultExtension:"png",jsonFieldName:"filename",allowedTypes:["image/jpeg","image/png","image/jpg","image/gif"],progressText:"![Uploading file...]()",urlText:"![file]({filename})",errorText:"Error uploading file",extraParams:{},extraHeaders:{},beforeFileUpload:function(){return!0},onFileReceived:function(){},onFileUploadResponse:function(){return!0},onFileUploadError:function(){return!0},onFileUploaded:function(){}},c.prototype.uploadFile=function(a){var b=this,c=new FormData,d=new XMLHttpRequest,e=this.settings,f=e.defaultExtension||e.defualtExtension;if("function"==typeof e.setupFormData&&e.setupFormData(c,a),a.name){var g=a.name.match(/\.(.+)$/);g&&(f=g[1])}var h="image-"+Date.now()+"."+f;if("function"==typeof e.remoteFilename&&(h=e.remoteFilename(a)),c.append(e.uploadFieldName,a,h),"object"==typeof e.extraParams)for(var i in e.extraParams)e.extraParams.hasOwnProperty(i)&&c.append(i,e.extraParams[i]);if(d.open("POST",e.uploadUrl),"object"==typeof e.extraHeaders)for(var j in e.extraHeaders)e.extraHeaders.hasOwnProperty(j)&&d.setRequestHeader(j,e.extraHeaders[j]);return d.onload=function(){200===d.status||201===d.status?b.onFileUploadResponse(d):b.onFileUploadError(d)},e.beforeFileUpload(d)!==!1&&d.send(c),d},c.prototype.isFileAllowed=function(a){return"string"===a.kind?!1:0===this.settings.allowedTypes.indexOf("*")?!0:this.settings.allowedTypes.indexOf(a.type)>=0},c.prototype.onFileUploadResponse=function(a){if(this.settings.onFileUploadResponse.call(this,a)!==!1){var b=JSON.parse(a.responseText),c=b[this.settings.jsonFieldName];if(b&&c){var d;d="function"==typeof this.settings.urlText?this.settings.urlText.call(this,c,b):this.settings.urlText.replace(this.filenameTag,c);var e=this.editor.getValue().replace(this.lastValue,d);this.editor.setValue(e),this.settings.onFileUploaded.call(this,c)}}},c.prototype.onFileUploadError=function(a){if(this.settings.onFileUploadError.call(this,a)!==!1){var b=this.editor.getValue().replace(this.lastValue,"");this.editor.setValue(b)}},c.prototype.onFileInserted=function(a){this.settings.onFileReceived.call(this,a)!==!1&&(this.lastValue=this.settings.progressText,this.editor.insertValue(this.lastValue))},c.prototype.onPaste=function(a){var b,c=!1,d=a.clipboardData;if("object"==typeof d){b=d.items||d.files||[];for(var e=0;e= 0; i--) { - var obj = arguments[i]; - for (var k in obj) { - if (obj.hasOwnProperty(k)) { - result[k] = obj[k]; - } - } - } - return result; - }, - - /** - * Append a line of text at the bottom, ensuring there aren't unnecessary newlines - * - * @param {String} appended Current content - * @param {String} previous Value which should be appended after the current content - */ - appendInItsOwnLine: function(previous, appended) { - return (previous + "\n\n[[D]]" + appended) - .replace(/(\n{2,})\[\[D\]\]/, "\n\n") - .replace(/^(\n*)/, ""); - }, - - /** - * Inserts the given value at the current cursor position of the textarea element - * - * @param {HtmlElement} el - * @param {String} value Text which will be inserted at the cursor position - */ - insertTextAtCursor: function(el, text) { - var scrollPos = el.scrollTop, - strPos = 0, - browser = false, - range; - - if ((el.selectionStart || el.selectionStart === '0')) { - browser = "ff"; - } else if (document.selection) { - browser = "ie"; - } - - if (browser === "ie") { - el.focus(); - range = document.selection.createRange(); - range.moveStart('character', -el.value.length); - strPos = range.text.length; - } else if (browser === "ff") { - strPos = el.selectionStart; - } - - var front = (el.value).substring(0, strPos); - var back = (el.value).substring(strPos, el.value.length); - el.value = front + text + back; - strPos = strPos + text.length; - if (browser === "ie") { - el.focus(); - range = document.selection.createRange(); - range.moveStart('character', -el.value.length); - range.moveStart('character', strPos); - range.moveEnd('character', 0); - range.select(); - } else if (browser === "ff") { - el.selectionStart = strPos; - el.selectionEnd = strPos; - el.focus(); - } - el.scrollTop = scrollPos; - } - }; - - /** - * Default configuration options - * - * @type {Object} - */ - inlineAttachment.defaults = { - /** - * URL where the file will be send - */ - uploadUrl: 'upload_attachment.php', - - /** - * Which method will be used to send the file to the upload URL - */ - uploadMethod: 'POST', - - /** - * Name in which the file will be placed - */ - uploadFieldName: 'file', - - /** - * Extension which will be used when a file extension could not - * be detected - */ - defaultExtension: 'png', - - /** - * JSON field which refers to the uploaded file URL - */ - jsonFieldName: 'filename', - - /** - * Allowed MIME types - */ - allowedTypes: [ - 'image/jpeg', - 'image/png', - 'image/jpg', - 'image/gif' - ], - - /** - * Text which will be inserted when dropping or pasting a file. - * Acts as a placeholder which will be replaced when the file is done with uploading - */ - progressText: '![Uploading file...]()', - - /** - * When a file has successfully been uploaded the progressText - * will be replaced by the urlText, the {filename} tag will be replaced - * by the filename that has been returned by the server - */ - urlText: "![file]({filename})", - - /** - * Text which will be used when uploading has failed - */ - errorText: "Error uploading file", - - /** - * Extra parameters which will be send when uploading a file - */ - extraParams: {}, - - /** - * Extra headers which will be send when uploading a file - */ - extraHeaders: {}, - - /** - * Before the file is send - */ - beforeFileUpload: function() { - return true; - }, - - /** - * Triggers when a file is dropped or pasted - */ - onFileReceived: function() {}, - - /** - * Custom upload handler - * - * @return {Boolean} when false is returned it will prevent default upload behavior - */ - onFileUploadResponse: function() { - return true; - }, - - /** - * Custom error handler. Runs after removing the placeholder text and before the alert(). - * Return false from this function to prevent the alert dialog. - * - * @return {Boolean} when false is returned it will prevent default error behavior - */ - onFileUploadError: function() { - return true; - }, - - /** - * When a file has succesfully been uploaded - */ - onFileUploaded: function() {} - }; - - /** - * Uploads the blob - * - * @param {Blob} file blob data received from event.dataTransfer object - * @return {XMLHttpRequest} request object which sends the file - */ - inlineAttachment.prototype.uploadFile = function(file) { - var me = this, - formData = new FormData(), - xhr = new XMLHttpRequest(), - settings = this.settings, - extension = settings.defaultExtension || settings.defualtExtension; - - if (typeof settings.setupFormData === 'function') { - settings.setupFormData(formData, file); - } - - // Attach the file. If coming from clipboard, add a default filename (only works in Chrome for now) - // http://stackoverflow.com/questions/6664967/how-to-give-a-blob-uploaded-as-formdata-a-file-name - if (file.name) { - var fileNameMatches = file.name.match(/\.(.+)$/); - if (fileNameMatches) { - extension = fileNameMatches[1]; - } - } - - var remoteFilename = "image-" + Date.now() + "." + extension; - if (typeof settings.remoteFilename === 'function') { - remoteFilename = settings.remoteFilename(file); - } - - formData.append(settings.uploadFieldName, file, remoteFilename); - - // Append the extra parameters to the formdata - if (typeof settings.extraParams === "object") { - for (var key in settings.extraParams) { - if (settings.extraParams.hasOwnProperty(key)) { - formData.append(key, settings.extraParams[key]); - } - } - } - - xhr.open('POST', settings.uploadUrl); - - // Add any available extra headers - if (typeof settings.extraHeaders === "object") { - for (var header in settings.extraHeaders) { - if (settings.extraHeaders.hasOwnProperty(header)) { - xhr.setRequestHeader(header, settings.extraHeaders[header]); - } - } - } - - xhr.onload = function() { - // If HTTP status is OK or Created - if (xhr.status === 200 || xhr.status === 201) { - me.onFileUploadResponse(xhr); - } else { - me.onFileUploadError(xhr); - } - }; - if (settings.beforeFileUpload(xhr) !== false) { - xhr.send(formData); - } - return xhr; - }; - - /** - * Returns if the given file is allowed to handle - * - * @param {File} clipboard data file - */ - inlineAttachment.prototype.isFileAllowed = function(file) { - if (file.kind === 'string') { return false; } - if (this.settings.allowedTypes.indexOf('*') === 0){ - return true; - } else { - return this.settings.allowedTypes.indexOf(file.type) >= 0; - } - }; - - /** - * Handles upload response - * - * @param {XMLHttpRequest} xhr - * @return {Void} - */ - inlineAttachment.prototype.onFileUploadResponse = function(xhr) { - if (this.settings.onFileUploadResponse.call(this, xhr) !== false) { - var result = JSON.parse(xhr.responseText), - filename = result[this.settings.jsonFieldName]; - - if (result && filename) { - var newValue; - if (typeof this.settings.urlText === 'function') { - newValue = this.settings.urlText.call(this, filename, result); - } else { - newValue = this.settings.urlText.replace(this.filenameTag, filename); - } - var text = this.editor.getValue().replace(this.lastValue, newValue); - this.editor.setValue(text); - this.settings.onFileUploaded.call(this, filename); - } - } - }; - - - /** - * Called when a file has failed to upload - * - * @param {XMLHttpRequest} xhr - * @return {Void} - */ - inlineAttachment.prototype.onFileUploadError = function(xhr) { - if (this.settings.onFileUploadError.call(this, xhr) !== false) { - var text = this.editor.getValue().replace(this.lastValue, ""); - this.editor.setValue(text); - } - }; - - /** - * Called when a file has been inserted, either by drop or paste - * - * @param {File} file - * @return {Void} - */ - inlineAttachment.prototype.onFileInserted = function(file) { - if (this.settings.onFileReceived.call(this, file) !== false) { - this.lastValue = this.settings.progressText; - this.editor.insertValue(this.lastValue); - } - }; - - - /** - * Called when a paste event occured - * @param {Event} e - * @return {Boolean} if the event was handled - */ - inlineAttachment.prototype.onPaste = function(e) { - var result = false, - clipboardData = e.clipboardData, - items; - - if (typeof clipboardData === "object") { - items = clipboardData.items || clipboardData.files || []; - - for (var i = 0; i < items.length; i++) { - var item = items[i]; - if (this.isFileAllowed(item)) { - result = true; - this.onFileInserted(item.getAsFile()); - this.uploadFile(item.getAsFile()); - } - } - } - - if (result) { e.preventDefault(); } - - return result; - }; - - /** - * Called when a drop event occures - * @param {Event} e - * @return {Boolean} if the event was handled - */ - inlineAttachment.prototype.onDrop = function(e) { - var result = false; - for (var i = 0; i < e.dataTransfer.files.length; i++) { - var file = e.dataTransfer.files[i]; - if (this.isFileAllowed(file)) { - result = true; - this.onFileInserted(file); - this.uploadFile(file); - } - } - - return result; - }; - - window.inlineAttachment = inlineAttachment; - -})(document, window); - -/*jslint newcap: true */ -/*global inlineAttachment: false */ -(function() { - 'use strict'; - - inlineAttachment.editors.input = { - Editor: function(instance) { - - var input = instance; - - return { - getValue: function() { - return input.value; - }, - insertValue: function(val) { - inlineAttachment.util.insertTextAtCursor(input, val); - }, - setValue: function(val) { - input.value = val; - } - }; - }, - attachToInput: function(input, options) { - options = options || {}; - - var editor = new inlineAttachment.editors.input.Editor(input), - inlineattach = new inlineAttachment(options, editor); - - input.addEventListener('paste', function(e) { - inlineattach.onPaste(e); - }, false); - input.addEventListener('drop', function(e) { - e.stopPropagation(); - e.preventDefault(); - inlineattach.onDrop(e); - }, false); - input.addEventListener('dragenter', function(e) { - e.stopPropagation(); - e.preventDefault(); - }, false); - input.addEventListener('dragover', function(e) { - e.stopPropagation(); - e.preventDefault(); - }, false); - } - }; - -})(); \ No newline at end of file diff --git a/dist/inline-attachment.min.js b/dist/inline-attachment.min.js deleted file mode 100644 index 6768dee..0000000 --- a/dist/inline-attachment.min.js +++ /dev/null @@ -1,2 +0,0 @@ -/*! inline-attachment - v2.0.3 - 2016-08-20 */ -!function(a,b){"use strict";var c=function(a,b){this.settings=c.util.merge(a,c.defaults),this.editor=b,this.filenameTag="{filename}",this.lastValue=null};c.editors={},c.util={merge:function(){for(var a={},b=arguments.length-1;b>=0;b--){var c=arguments[b];for(var d in c)c.hasOwnProperty(d)&&(a[d]=c[d])}return a},appendInItsOwnLine:function(a,b){return(a+"\n\n[[D]]"+b).replace(/(\n{2,})\[\[D\]\]/,"\n\n").replace(/^(\n*)/,"")},insertTextAtCursor:function(b,c){var d,e=b.scrollTop,f=0,g=!1;b.selectionStart||"0"===b.selectionStart?g="ff":a.selection&&(g="ie"),"ie"===g?(b.focus(),d=a.selection.createRange(),d.moveStart("character",-b.value.length),f=d.text.length):"ff"===g&&(f=b.selectionStart);var h=b.value.substring(0,f),i=b.value.substring(f,b.value.length);b.value=h+c+i,f+=c.length,"ie"===g?(b.focus(),d=a.selection.createRange(),d.moveStart("character",-b.value.length),d.moveStart("character",f),d.moveEnd("character",0),d.select()):"ff"===g&&(b.selectionStart=f,b.selectionEnd=f,b.focus()),b.scrollTop=e}},c.defaults={uploadUrl:"upload_attachment.php",uploadMethod:"POST",uploadFieldName:"file",defaultExtension:"png",jsonFieldName:"filename",allowedTypes:["image/jpeg","image/png","image/jpg","image/gif"],progressText:"![Uploading file...]()",urlText:"![file]({filename})",errorText:"Error uploading file",extraParams:{},extraHeaders:{},beforeFileUpload:function(){return!0},onFileReceived:function(){},onFileUploadResponse:function(){return!0},onFileUploadError:function(){return!0},onFileUploaded:function(){}},c.prototype.uploadFile=function(a){var b=this,c=new FormData,d=new XMLHttpRequest,e=this.settings,f=e.defaultExtension||e.defualtExtension;if("function"==typeof e.setupFormData&&e.setupFormData(c,a),a.name){var g=a.name.match(/\.(.+)$/);g&&(f=g[1])}var h="image-"+Date.now()+"."+f;if("function"==typeof e.remoteFilename&&(h=e.remoteFilename(a)),c.append(e.uploadFieldName,a,h),"object"==typeof e.extraParams)for(var i in e.extraParams)e.extraParams.hasOwnProperty(i)&&c.append(i,e.extraParams[i]);if(d.open("POST",e.uploadUrl),"object"==typeof e.extraHeaders)for(var j in e.extraHeaders)e.extraHeaders.hasOwnProperty(j)&&d.setRequestHeader(j,e.extraHeaders[j]);return d.onload=function(){200===d.status||201===d.status?b.onFileUploadResponse(d):b.onFileUploadError(d)},e.beforeFileUpload(d)!==!1&&d.send(c),d},c.prototype.isFileAllowed=function(a){return"string"===a.kind?!1:0===this.settings.allowedTypes.indexOf("*")?!0:this.settings.allowedTypes.indexOf(a.type)>=0},c.prototype.onFileUploadResponse=function(a){if(this.settings.onFileUploadResponse.call(this,a)!==!1){var b=JSON.parse(a.responseText),c=b[this.settings.jsonFieldName];if(b&&c){var d;d="function"==typeof this.settings.urlText?this.settings.urlText.call(this,c,b):this.settings.urlText.replace(this.filenameTag,c);var e=this.editor.getValue().replace(this.lastValue,d);this.editor.setValue(e),this.settings.onFileUploaded.call(this,c)}}},c.prototype.onFileUploadError=function(a){if(this.settings.onFileUploadError.call(this,a)!==!1){var b=this.editor.getValue().replace(this.lastValue,"");this.editor.setValue(b)}},c.prototype.onFileInserted=function(a){this.settings.onFileReceived.call(this,a)!==!1&&(this.lastValue=this.settings.progressText,this.editor.insertValue(this.lastValue))},c.prototype.onPaste=function(a){var b,c=!1,d=a.clipboardData;if("object"==typeof d){b=d.items||d.files||[];for(var e=0;e= 0; i--) { - var obj = arguments[i]; - for (var k in obj) { - if (obj.hasOwnProperty(k)) { - result[k] = obj[k]; - } - } - } - return result; - }, - - /** - * Append a line of text at the bottom, ensuring there aren't unnecessary newlines - * - * @param {String} appended Current content - * @param {String} previous Value which should be appended after the current content - */ - appendInItsOwnLine: function(previous, appended) { - return (previous + "\n\n[[D]]" + appended) - .replace(/(\n{2,})\[\[D\]\]/, "\n\n") - .replace(/^(\n*)/, ""); - }, - - /** - * Inserts the given value at the current cursor position of the textarea element - * - * @param {HtmlElement} el - * @param {String} value Text which will be inserted at the cursor position - */ - insertTextAtCursor: function(el, text) { - var scrollPos = el.scrollTop, - strPos = 0, - browser = false, - range; - - if ((el.selectionStart || el.selectionStart === '0')) { - browser = "ff"; - } else if (document.selection) { - browser = "ie"; - } - - if (browser === "ie") { - el.focus(); - range = document.selection.createRange(); - range.moveStart('character', -el.value.length); - strPos = range.text.length; - } else if (browser === "ff") { - strPos = el.selectionStart; - } - - var front = (el.value).substring(0, strPos); - var back = (el.value).substring(strPos, el.value.length); - el.value = front + text + back; - strPos = strPos + text.length; - if (browser === "ie") { - el.focus(); - range = document.selection.createRange(); - range.moveStart('character', -el.value.length); - range.moveStart('character', strPos); - range.moveEnd('character', 0); - range.select(); - } else if (browser === "ff") { - el.selectionStart = strPos; - el.selectionEnd = strPos; - el.focus(); - } - el.scrollTop = scrollPos; - } - }; - - /** - * Default configuration options - * - * @type {Object} - */ - inlineAttachment.defaults = { - /** - * URL where the file will be send - */ - uploadUrl: 'upload_attachment.php', - - /** - * Which method will be used to send the file to the upload URL - */ - uploadMethod: 'POST', - - /** - * Name in which the file will be placed - */ - uploadFieldName: 'file', - - /** - * Extension which will be used when a file extension could not - * be detected - */ - defaultExtension: 'png', - - /** - * JSON field which refers to the uploaded file URL - */ - jsonFieldName: 'filename', - - /** - * Allowed MIME types - */ - allowedTypes: [ - 'image/jpeg', - 'image/png', - 'image/jpg', - 'image/gif' - ], - - /** - * Text which will be inserted when dropping or pasting a file. - * Acts as a placeholder which will be replaced when the file is done with uploading - */ - progressText: '![Uploading file...]()', - - /** - * When a file has successfully been uploaded the progressText - * will be replaced by the urlText, the {filename} tag will be replaced - * by the filename that has been returned by the server - */ - urlText: "![file]({filename})", - - /** - * Text which will be used when uploading has failed - */ - errorText: "Error uploading file", - - /** - * Extra parameters which will be send when uploading a file - */ - extraParams: {}, - - /** - * Extra headers which will be send when uploading a file - */ - extraHeaders: {}, - - /** - * Before the file is send - */ - beforeFileUpload: function() { - return true; - }, - - /** - * Triggers when a file is dropped or pasted - */ - onFileReceived: function() {}, - - /** - * Custom upload handler - * - * @return {Boolean} when false is returned it will prevent default upload behavior - */ - onFileUploadResponse: function() { - return true; - }, - - /** - * Custom error handler. Runs after removing the placeholder text and before the alert(). - * Return false from this function to prevent the alert dialog. - * - * @return {Boolean} when false is returned it will prevent default error behavior - */ - onFileUploadError: function() { - return true; - }, - - /** - * When a file has succesfully been uploaded - */ - onFileUploaded: function() {} - }; - - /** - * Uploads the blob - * - * @param {Blob} file blob data received from event.dataTransfer object - * @return {XMLHttpRequest} request object which sends the file - */ - inlineAttachment.prototype.uploadFile = function(file) { - var me = this, - formData = new FormData(), - xhr = new XMLHttpRequest(), - settings = this.settings, - extension = settings.defaultExtension || settings.defualtExtension; - - if (typeof settings.setupFormData === 'function') { - settings.setupFormData(formData, file); - } - - // Attach the file. If coming from clipboard, add a default filename (only works in Chrome for now) - // http://stackoverflow.com/questions/6664967/how-to-give-a-blob-uploaded-as-formdata-a-file-name - if (file.name) { - var fileNameMatches = file.name.match(/\.(.+)$/); - if (fileNameMatches) { - extension = fileNameMatches[1]; - } - } - - var remoteFilename = "image-" + Date.now() + "." + extension; - if (typeof settings.remoteFilename === 'function') { - remoteFilename = settings.remoteFilename(file); - } - - formData.append(settings.uploadFieldName, file, remoteFilename); - - // Append the extra parameters to the formdata - if (typeof settings.extraParams === "object") { - for (var key in settings.extraParams) { - if (settings.extraParams.hasOwnProperty(key)) { - formData.append(key, settings.extraParams[key]); - } - } - } - - xhr.open('POST', settings.uploadUrl); - - // Add any available extra headers - if (typeof settings.extraHeaders === "object") { - for (var header in settings.extraHeaders) { - if (settings.extraHeaders.hasOwnProperty(header)) { - xhr.setRequestHeader(header, settings.extraHeaders[header]); - } - } - } - - xhr.onload = function() { - // If HTTP status is OK or Created - if (xhr.status === 200 || xhr.status === 201) { - me.onFileUploadResponse(xhr); - } else { - me.onFileUploadError(xhr); - } - }; - if (settings.beforeFileUpload(xhr) !== false) { - xhr.send(formData); - } - return xhr; - }; - - /** - * Returns if the given file is allowed to handle - * - * @param {File} clipboard data file - */ - inlineAttachment.prototype.isFileAllowed = function(file) { - if (file.kind === 'string') { return false; } - if (this.settings.allowedTypes.indexOf('*') === 0){ - return true; - } else { - return this.settings.allowedTypes.indexOf(file.type) >= 0; - } - }; - - /** - * Handles upload response - * - * @param {XMLHttpRequest} xhr - * @return {Void} - */ - inlineAttachment.prototype.onFileUploadResponse = function(xhr) { - if (this.settings.onFileUploadResponse.call(this, xhr) !== false) { - var result = JSON.parse(xhr.responseText), - filename = result[this.settings.jsonFieldName]; - - if (result && filename) { - var newValue; - if (typeof this.settings.urlText === 'function') { - newValue = this.settings.urlText.call(this, filename, result); - } else { - newValue = this.settings.urlText.replace(this.filenameTag, filename); - } - var text = this.editor.getValue().replace(this.lastValue, newValue); - this.editor.setValue(text); - this.settings.onFileUploaded.call(this, filename); - } - } - }; - - - /** - * Called when a file has failed to upload - * - * @param {XMLHttpRequest} xhr - * @return {Void} - */ - inlineAttachment.prototype.onFileUploadError = function(xhr) { - if (this.settings.onFileUploadError.call(this, xhr) !== false) { - var text = this.editor.getValue().replace(this.lastValue, ""); - this.editor.setValue(text); - } - }; - - /** - * Called when a file has been inserted, either by drop or paste - * - * @param {File} file - * @return {Void} - */ - inlineAttachment.prototype.onFileInserted = function(file) { - if (this.settings.onFileReceived.call(this, file) !== false) { - this.lastValue = this.settings.progressText; - this.editor.insertValue(this.lastValue); - } - }; - - - /** - * Called when a paste event occured - * @param {Event} e - * @return {Boolean} if the event was handled - */ - inlineAttachment.prototype.onPaste = function(e) { - var result = false, - clipboardData = e.clipboardData, - items; - - if (typeof clipboardData === "object") { - items = clipboardData.items || clipboardData.files || []; - - for (var i = 0; i < items.length; i++) { - var item = items[i]; - if (this.isFileAllowed(item)) { - result = true; - this.onFileInserted(item.getAsFile()); - this.uploadFile(item.getAsFile()); - } - } - } - - if (result) { e.preventDefault(); } - - return result; - }; - - /** - * Called when a drop event occures - * @param {Event} e - * @return {Boolean} if the event was handled - */ - inlineAttachment.prototype.onDrop = function(e) { - var result = false; - for (var i = 0; i < e.dataTransfer.files.length; i++) { - var file = e.dataTransfer.files[i]; - if (this.isFileAllowed(file)) { - result = true; - this.onFileInserted(file); - this.uploadFile(file); - } - } - - return result; - }; - - window.inlineAttachment = inlineAttachment; - -})(document, window); - -/*jslint newcap: true */ -/*global inlineAttachment: false, jQuery: false */ -/** - * jQuery plugin for inline attach - * - * @param {document} document - * @param {window} window - * @param {jQuery} $ - */ -(function(document, window, $) { - 'use strict'; - - inlineAttachment.editors.jquery = {}; - - /** - * Creates a new editor using jQuery - */ - var editor = function(instance) { - - var $this = $(instance); - - return { - getValue: function() { - return $this.val(); - }, - insertValue: function(val) { - inlineAttachment.util.insertTextAtCursor($this[0], val); - }, - setValue: function(val) { - $this.val(val); - } - }; - }; - - $.fn.inlineattachment = function(options) { - - var set = $(this); - - set.each(function() { - - var $this = $(this), - ed = new editor($this), - inlineattach = new inlineAttachment(options, ed); - - $this.bind({ - 'paste': function(e) { - inlineattach.onPaste(e.originalEvent); - }, - 'drop': function(e) { - e.stopPropagation(); - e.preventDefault(); - inlineattach.onDrop(e.originalEvent); - }, - 'dragenter dragover': function(e) { - e.stopPropagation(); - e.preventDefault(); - } - }); - }); - - return this; - }; - - inlineAttachment.editors.jquery.Editor = editor; - -})(document, window, jQuery); \ No newline at end of file diff --git a/dist/jquery.inline-attachment.min.js b/dist/jquery.inline-attachment.min.js deleted file mode 100644 index 28e53c9..0000000 --- a/dist/jquery.inline-attachment.min.js +++ /dev/null @@ -1,2 +0,0 @@ -/*! inline-attachment - v2.0.3 - 2016-08-20 */ -!function(a,b){"use strict";var c=function(a,b){this.settings=c.util.merge(a,c.defaults),this.editor=b,this.filenameTag="{filename}",this.lastValue=null};c.editors={},c.util={merge:function(){for(var a={},b=arguments.length-1;b>=0;b--){var c=arguments[b];for(var d in c)c.hasOwnProperty(d)&&(a[d]=c[d])}return a},appendInItsOwnLine:function(a,b){return(a+"\n\n[[D]]"+b).replace(/(\n{2,})\[\[D\]\]/,"\n\n").replace(/^(\n*)/,"")},insertTextAtCursor:function(b,c){var d,e=b.scrollTop,f=0,g=!1;b.selectionStart||"0"===b.selectionStart?g="ff":a.selection&&(g="ie"),"ie"===g?(b.focus(),d=a.selection.createRange(),d.moveStart("character",-b.value.length),f=d.text.length):"ff"===g&&(f=b.selectionStart);var h=b.value.substring(0,f),i=b.value.substring(f,b.value.length);b.value=h+c+i,f+=c.length,"ie"===g?(b.focus(),d=a.selection.createRange(),d.moveStart("character",-b.value.length),d.moveStart("character",f),d.moveEnd("character",0),d.select()):"ff"===g&&(b.selectionStart=f,b.selectionEnd=f,b.focus()),b.scrollTop=e}},c.defaults={uploadUrl:"upload_attachment.php",uploadMethod:"POST",uploadFieldName:"file",defaultExtension:"png",jsonFieldName:"filename",allowedTypes:["image/jpeg","image/png","image/jpg","image/gif"],progressText:"![Uploading file...]()",urlText:"![file]({filename})",errorText:"Error uploading file",extraParams:{},extraHeaders:{},beforeFileUpload:function(){return!0},onFileReceived:function(){},onFileUploadResponse:function(){return!0},onFileUploadError:function(){return!0},onFileUploaded:function(){}},c.prototype.uploadFile=function(a){var b=this,c=new FormData,d=new XMLHttpRequest,e=this.settings,f=e.defaultExtension||e.defualtExtension;if("function"==typeof e.setupFormData&&e.setupFormData(c,a),a.name){var g=a.name.match(/\.(.+)$/);g&&(f=g[1])}var h="image-"+Date.now()+"."+f;if("function"==typeof e.remoteFilename&&(h=e.remoteFilename(a)),c.append(e.uploadFieldName,a,h),"object"==typeof e.extraParams)for(var i in e.extraParams)e.extraParams.hasOwnProperty(i)&&c.append(i,e.extraParams[i]);if(d.open("POST",e.uploadUrl),"object"==typeof e.extraHeaders)for(var j in e.extraHeaders)e.extraHeaders.hasOwnProperty(j)&&d.setRequestHeader(j,e.extraHeaders[j]);return d.onload=function(){200===d.status||201===d.status?b.onFileUploadResponse(d):b.onFileUploadError(d)},e.beforeFileUpload(d)!==!1&&d.send(c),d},c.prototype.isFileAllowed=function(a){return"string"===a.kind?!1:0===this.settings.allowedTypes.indexOf("*")?!0:this.settings.allowedTypes.indexOf(a.type)>=0},c.prototype.onFileUploadResponse=function(a){if(this.settings.onFileUploadResponse.call(this,a)!==!1){var b=JSON.parse(a.responseText),c=b[this.settings.jsonFieldName];if(b&&c){var d;d="function"==typeof this.settings.urlText?this.settings.urlText.call(this,c,b):this.settings.urlText.replace(this.filenameTag,c);var e=this.editor.getValue().replace(this.lastValue,d);this.editor.setValue(e),this.settings.onFileUploaded.call(this,c)}}},c.prototype.onFileUploadError=function(a){if(this.settings.onFileUploadError.call(this,a)!==!1){var b=this.editor.getValue().replace(this.lastValue,"");this.editor.setValue(b)}},c.prototype.onFileInserted=function(a){this.settings.onFileReceived.call(this,a)!==!1&&(this.lastValue=this.settings.progressText,this.editor.insertValue(this.lastValue))},c.prototype.onPaste=function(a){var b,c=!1,d=a.clipboardData;if("object"==typeof d){b=d.items||d.files||[];for(var e=0;e Date: Wed, 26 Oct 2016 20:33:54 +0200 Subject: [PATCH 14/32] updated demos --- demo/input.html | 5 ++--- demo/jquery.html | 7 +++---- demo/upload_attachment.php | 4 ++++ src/angular.js | 2 +- src/inline-attachment.js | 1 + src/input.js | 13 ++++++++----- src/jquery.js | 14 +++++++++++--- 7 files changed, 30 insertions(+), 16 deletions(-) diff --git a/demo/input.html b/demo/input.html index 1848c7e..2716e25 100644 --- a/demo/input.html +++ b/demo/input.html @@ -8,10 +8,9 @@ - - + \ No newline at end of file diff --git a/demo/jquery.html b/demo/jquery.html index dab4b14..9d3a528 100644 --- a/demo/jquery.html +++ b/demo/jquery.html @@ -9,12 +9,11 @@ - - - + + \ No newline at end of file diff --git a/src/angular.js b/src/angular/angular-1.js similarity index 91% rename from src/angular.js rename to src/angular/angular-1.js index 90125bb..3383059 100644 --- a/src/angular.js +++ b/src/angular/angular-1.js @@ -1,8 +1,8 @@ /*jslint newcap: true */ /*global inlineAttachment: false, angular: false */ -import Utils from "./utils"; -import InputInlineAttachment from "./input"; +import Utils from "../utils"; +import InputInlineAttachment from "../input/input"; let directiveName = 'inlineattachment'; let module = ng.module(directiveName, []); diff --git a/src/codemirror-3.js b/src/codemirror-3/codemirror-3.js similarity index 95% rename from src/codemirror-3.js rename to src/codemirror-3/codemirror-3.js index b626b66..9d86ae3 100644 --- a/src/codemirror-3.js +++ b/src/codemirror-3/codemirror-3.js @@ -1,7 +1,7 @@ /*jslint newcap: true */ /*global inlineAttachment: false */ -import InlineAttachment from "./inline-attachment"; +import InlineAttachment from "../inline-attachment"; export default class CodeMirror3InlineAttachment { diff --git a/src/codemirror-4.js b/src/codemirror-4/codemirror-4.js similarity index 95% rename from src/codemirror-4.js rename to src/codemirror-4/codemirror-4.js index b426b87..722d6d5 100644 --- a/src/codemirror-4.js +++ b/src/codemirror-4/codemirror-4.js @@ -1,7 +1,7 @@ /*jslint newcap: true */ /*global inlineAttachment: false */ -import InlineAttachment from "./inline-attachment"; +import InlineAttachment from "../inline-attachment"; export default class CodeMirror4InlineAttachment { diff --git a/src/inline-attachment.js b/src/inline-attachment.js index 353cd78..c8e98a4 100644 --- a/src/inline-attachment.js +++ b/src/inline-attachment.js @@ -98,9 +98,8 @@ export default class InlineAttachment { * Handles upload response * * @param {XMLHttpRequest} xhr - * @return {Void} + * @return {void} */ - onFileUploadResponse(xhr) { if (this.settings.onFileUploadResponse.call(this, xhr) !== false) { var result = JSON.parse(xhr.responseText), @@ -125,7 +124,7 @@ export default class InlineAttachment { * Called when a file has failed to upload * * @param {XMLHttpRequest} xhr - * @return {Void} + * @return {void} */ onFileUploadError(xhr) { if (this.settings.onFileUploadError.call(this, xhr) !== false) { @@ -138,7 +137,7 @@ export default class InlineAttachment { * Called when a file has been inserted, either by drop or paste * * @param {File} file - * @return {Void} + * @return {void} */ onFileInserted(file) { if (this.settings.onFileReceived.call(this, file) !== false) { diff --git a/src/input.js b/src/input/input.js similarity index 81% rename from src/input.js rename to src/input/input.js index 8a11f0a..3105d9c 100644 --- a/src/input.js +++ b/src/input/input.js @@ -1,7 +1,7 @@ "use strict"; -import Utils from "./utils"; -import InlineAttachment from "./inline-attachment"; +import Utils from "../utils"; +import InlineAttachment from "../inline-attachment"; class InputInlineAttachment { @@ -45,8 +45,4 @@ class InputInlineAttachment { } } -if (typeof window !== 'undefined') { - window.InputInlineAttachment = InputInlineAttachment; -} - export default InputInlineAttachment; \ No newline at end of file diff --git a/src/input/main.js b/src/input/main.js new file mode 100644 index 0000000..879fedf --- /dev/null +++ b/src/input/main.js @@ -0,0 +1,14 @@ +import InputInlineAttachment from './input'; + +(function() { + + let root = this; + + root.InputInlineAttachment = InputInlineAttachment; + + if (typeof exports !== "undefined") { + exports.InputInlineAttachment = root.InputInlineAttachment; + } + + +}).call(typeof window !== 'undefined' ? window : this); \ No newline at end of file diff --git a/src/jquery.js b/src/jquery/jquery.js similarity index 88% rename from src/jquery.js rename to src/jquery/jquery.js index 31b3150..ddfd179 100644 --- a/src/jquery.js +++ b/src/jquery/jquery.js @@ -1,8 +1,5 @@ -/*jslint newcap: true */ -/*global inlineAttachment: false, jQuery: false */ - -import InlineAttachment from "./inline-attachment"; -import Utils from "./utils"; +import InlineAttachment from "../inline-attachment"; +import Utils from "../utils"; export default class jQueryInlineAttachment { From 8463b0560ddfc9b57cd331b8782096b90c59b623 Mon Sep 17 00:00:00 2001 From: Roy van Kaathoven Date: Sat, 7 Jan 2017 14:28:56 +0100 Subject: [PATCH 21/32] add jquery dev-dependency --- package.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 755f1e4..e94a989 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,8 @@ "gulp-util": "^3.0.7", "webpack": "^1.13.2" }, - "devDependencies": {}, + "devDependencies": { + "jquery": "^3.1.1" + }, "scripts": {} } From a870de56a42a046d8400f103a7ea322448e19a1c Mon Sep 17 00:00:00 2001 From: Roy van Kaathoven Date: Sat, 7 Jan 2017 14:37:02 +0100 Subject: [PATCH 22/32] moved codemirror dependencies to bower --- .gitignore | 3 ++- Gulpfile.js | 4 ++-- bower.json | 6 +++++- demo/{codemirror.html => codemirror-3.html} | 7 +++---- demo/codemirror-4.html | 6 +++--- src/input/main.js | 1 - 6 files changed, 15 insertions(+), 12 deletions(-) rename demo/{codemirror.html => codemirror-3.html} (63%) diff --git a/.gitignore b/.gitignore index 74ba1cf..4b64901 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ dist nbproject data node_modules -_build \ No newline at end of file +_build +bower_components \ No newline at end of file diff --git a/Gulpfile.js b/Gulpfile.js index 0890e53..cbddb8b 100644 --- a/Gulpfile.js +++ b/Gulpfile.js @@ -10,8 +10,8 @@ function webpackOptions(options) { angular: './src/angular/angular-1.js', input: './src/input/main.js', jquery: './src/jquery/jquery.js', - codemirror3: './src/codemirror/codemirror-3.js', - codemirror4: './src/codemirror/codemirror-4.js', + "codemirror-3": './src/codemirror/codemirror-3.js', + "codemirror-3": './src/codemirror/codemirror-4.js', }, devtool: options.debug ? 'inline-source-map' : '', debug: options.debug, diff --git a/bower.json b/bower.json index 12b7108..79234db 100644 --- a/bower.json +++ b/bower.json @@ -17,5 +17,9 @@ "bower_components", "test", "tests" - ] + ], + "dependencies": { + "codemirror-3": "codemirror#3.23.0", + "codemirror-4": "codemirror#4.13.0" + } } diff --git a/demo/codemirror.html b/demo/codemirror-3.html similarity index 63% rename from demo/codemirror.html rename to demo/codemirror-3.html index 74c97e9..79794ad 100644 --- a/demo/codemirror.html +++ b/demo/codemirror-3.html @@ -5,13 +5,12 @@ CodeMirror 3 InlineAttachment Demo - - + + - - + + + - + \ No newline at end of file diff --git a/src/codemirror-3/codemirror-3.js b/src/codemirror-3/codemirror-3.js index 9d86ae3..9567baf 100644 --- a/src/codemirror-3/codemirror-3.js +++ b/src/codemirror-3/codemirror-3.js @@ -3,7 +3,7 @@ import InlineAttachment from "../inline-attachment"; -export default class CodeMirror3InlineAttachment { +export default class CodeMirror3 { constructor(instance, options) { if (!instance.getWrapperElement) { diff --git a/src/codemirror-3/main.js b/src/codemirror-3/main.js new file mode 100644 index 0000000..53a769d --- /dev/null +++ b/src/codemirror-3/main.js @@ -0,0 +1,15 @@ +import CodeMirror3 from './codemirror-3'; + +(function() { + + // Expose to Window + let root = this; + root.InlineAttachment = root.InlineAttachment || {}; + root.InlineAttachment.CodeMirror3 = CodeMirror3; + + // Expose to Node + if (typeof exports !== "undefined") { + exports.CodeMirror3 = CodeMirror3; + } + +}).call(typeof window !== 'undefined' ? window : this); \ No newline at end of file From accd14c0c5cfb53e61f787f378cc170b48b60fc7 Mon Sep 17 00:00:00 2001 From: Roy van Kaathoven Date: Sat, 7 Jan 2017 14:56:37 +0100 Subject: [PATCH 24/32] fix codemirror 4 example --- Gulpfile.js | 2 +- demo/codemirror-4.html | 3 +-- src/codemirror-4/codemirror-4.js | 5 ++--- src/codemirror-4/main.js | 15 +++++++++++++++ 4 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 src/codemirror-4/main.js diff --git a/Gulpfile.js b/Gulpfile.js index 7ca20b9..86d323c 100644 --- a/Gulpfile.js +++ b/Gulpfile.js @@ -11,7 +11,7 @@ function webpackOptions(options) { "input": './src/input/main.js', "jquery": './src/jquery/jquery.js', "codemirror-3": './src/codemirror-3/main.js', - "codemirror-4": './src/codemirror-4/codemirror-4.js', + "codemirror-4": './src/codemirror-4/main.js', }, devtool: options.debug ? 'inline-source-map' : '', debug: options.debug, diff --git a/demo/codemirror-4.html b/demo/codemirror-4.html index 66543ea..3f3a289 100644 --- a/demo/codemirror-4.html +++ b/demo/codemirror-4.html @@ -10,7 +10,6 @@ - \ No newline at end of file diff --git a/src/codemirror-4/codemirror-4.js b/src/codemirror-4/codemirror-4.js index 722d6d5..29563d8 100644 --- a/src/codemirror-4/codemirror-4.js +++ b/src/codemirror-4/codemirror-4.js @@ -3,7 +3,7 @@ import InlineAttachment from "../inline-attachment"; -export default class CodeMirror4InlineAttachment { +export default class CodeMirror4 { constructor(instance, options) { if (!instance.getWrapperElement) { @@ -31,7 +31,7 @@ export default class CodeMirror4InlineAttachment { bind() { - let inlineAttachment = new InlineAttachment(options, editor); + let inlineAttachment = new InlineAttachment(this, this.options); let el = this.instance.getWrapperElement(); el.addEventListener('paste', function (e) { @@ -48,5 +48,4 @@ export default class CodeMirror4InlineAttachment { } }); } - } \ No newline at end of file diff --git a/src/codemirror-4/main.js b/src/codemirror-4/main.js new file mode 100644 index 0000000..f7536f2 --- /dev/null +++ b/src/codemirror-4/main.js @@ -0,0 +1,15 @@ +import CodeMirror4 from './codemirror-4'; + +(function() { + + // Expose to Window + let root = this; + root.InlineAttachment = root.InlineAttachment || {}; + root.InlineAttachment.CodeMirror4 = CodeMirror4; + + // Expose to Node + if (typeof exports !== "undefined") { + exports.CodeMirror4 = CodeMirror4; + } + +}).call(typeof window !== 'undefined' ? window : this); \ No newline at end of file From 21f9c7093094b7b130bdd9c4e51cb81c4f10b731 Mon Sep 17 00:00:00 2001 From: Roy van Kaathoven Date: Sat, 7 Jan 2017 14:57:40 +0100 Subject: [PATCH 25/32] bower: dependencies -> devDependencies --- bower.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bower.json b/bower.json index 79234db..48901d7 100644 --- a/bower.json +++ b/bower.json @@ -18,7 +18,7 @@ "test", "tests" ], - "dependencies": { + "devDependencies": { "codemirror-3": "codemirror#3.23.0", "codemirror-4": "codemirror#4.13.0" } From b6900ca4636ed391611fb53eef8f2be8b7b06cc1 Mon Sep 17 00:00:00 2001 From: Roy van Kaathoven Date: Sat, 7 Jan 2017 15:01:30 +0100 Subject: [PATCH 26/32] moved angular 1 example dependencies to bower --- bower.json | 4 +++- demo/angularjs.html | 8 +++----- src/angular/angular-1.js | 2 +- src/angular/main.js | 13 +++++++++++++ 4 files changed, 20 insertions(+), 7 deletions(-) create mode 100644 src/angular/main.js diff --git a/bower.json b/bower.json index 48901d7..4269285 100644 --- a/bower.json +++ b/bower.json @@ -20,6 +20,8 @@ ], "devDependencies": { "codemirror-3": "codemirror#3.23.0", - "codemirror-4": "codemirror#4.13.0" + "codemirror-4": "codemirror#4.13.0", + "angular-1": "angular#1.6.1", + "jquery-1": "jquery#3.1.1" } } diff --git a/demo/angularjs.html b/demo/angularjs.html index 73655f0..80bd288 100644 --- a/demo/angularjs.html +++ b/demo/angularjs.html @@ -4,12 +4,10 @@ AngularJS InlineAttachment Demo - - + + - - - + - +
- +