diff --git a/README.md b/README.md index 94df716..8d88c3a 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,6 @@ Vue.use(VueHtml5Editor, { //config image module image: { //Url of the server-side,default null and convert image to base64 - //return json data like {ok:false,msg:"unexpected"} or {ok:true,data:"image url"} server: null, //the name for file field in multipart request fieldName: "image", @@ -80,7 +79,17 @@ Vue.use(VueHtml5Editor, { //follows are options of localResizeIMG width: 1600, height: 1600, - quality: 80 + quality: 80, + //handle response data,return image url + uploadHandler(responseText){ + //default accept json data like {ok:false,msg:"unexpected"} or {ok:true,data:"image url"} + var json = JSON.parse(responseText) + if (!json.ok) { + alert(json.msg) + } else { + return json.data + } + } }, //default en-us, en-us and zh-cn are built-in language: "zh-cn", @@ -129,11 +138,30 @@ Vue.use(VueHtml5Editor, { "reset": "重置" } }, + //the modules you don't want + hiddenModules: [], + //keep only the modules you want and customize the order. + //can be used with hiddenModules together + visibleModules: [ + "text", + "color", + "font", + "align", + "list", + "link", + "unlink", + "tabulation", + "image", + "hr", + "eraser", + "undo", + "full-screen", + "info", + ], //extended modules modules: { //omit,reference to source code of build-in modules } - }) ``` diff --git a/dist/vue-html5-editor.js b/dist/vue-html5-editor.js index 605dd91..8534171 100644 --- a/dist/vue-html5-editor.js +++ b/dist/vue-html5-editor.js @@ -1,5 +1,5 @@ /*! - * Vue-html5-editor 0.4.2 + * Vue-html5-editor 0.5.0 * https://github.com/PeakTai/vue-html5-editor */ (function webpackUniversalModuleDefinition(root, factory) { @@ -132,6 +132,10 @@ return /******/ (function(modules) { // webpackBootstrap var _enUs2 = _interopRequireDefault(_enUs); + var _arrayPolyfill = __webpack_require__(126); + + var _arrayPolyfill2 = _interopRequireDefault(_arrayPolyfill); + function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /** @@ -141,6 +145,8 @@ return /******/ (function(modules) { // webpackBootstrap */ exports.install = function (Vue, options) { + (0, _arrayPolyfill2.default)(); + options = options || {}; //modules @@ -157,6 +163,32 @@ return /******/ (function(modules) { // webpackBootstrap modules = modules.concat(arr); })(); } + //hidden modules + if (Array.isArray(options.hiddenModules)) { + modules = function () { + var arr = []; + modules.forEach(function (m) { + if (!options.hiddenModules.includes(m.name)) { + arr.push(m); + } + }); + return arr; + }(); + } + //visible modules + if (Array.isArray(options.visibleModules)) { + modules = function () { + var arr = []; + options.visibleModules.forEach(function (name) { + modules.forEach(function (module) { + if (module.name == name) { + arr.push(module); + } + }); + }); + return arr; + }(); + } var components = {}; modules.forEach(function (module) { @@ -1053,7 +1085,8 @@ return /******/ (function(modules) { // webpackBootstrap exports.default = { props: { content: { - twoWay: true, + //no longer be required + //twoWay: true, type: String, required: true, default: "" @@ -1133,6 +1166,9 @@ return /******/ (function(modules) { // webpackBootstrap computeDashboardStyle: function computeDashboardStyle() { this.dashboardStyle = { 'max-height': this.$els.content.clientHeight + 'px' }; }, + getContentElement: function getContentElement() { + return this.$els.content; + }, toggleFullScreen: function toggleFullScreen() { this.fullScreen = !this.fullScreen; }, @@ -1146,11 +1182,11 @@ return /******/ (function(modules) { // webpackBootstrap this.dashboard = null; }, getCurrentRange: function getCurrentRange() { - var selection = window.getSelection(); - return selection.rangeCount ? selection.getRangeAt(0) : null; + return this.range; }, saveCurrentRange: function saveCurrentRange() { - var range = this.getCurrentRange(); + var selection = window.getSelection ? window.getSelection() : document.getSelection(); + var range = selection.rangeCount ? selection.getRangeAt(0) : null; if (!range) { return; } @@ -1159,7 +1195,7 @@ return /******/ (function(modules) { // webpackBootstrap } }, restoreSelection: function restoreSelection() { - var selection = window.getSelection(); + var selection = window.getSelection ? window.getSelection() : document.getSelection(); selection.removeAllRanges(); if (this.range) { selection.addRange(this.range); @@ -1202,20 +1238,17 @@ return /******/ (function(modules) { // webpackBootstrap component.content = component.$els.content.innerHTML; }, false); - component.touchHander = function (e) { - var isInside = component.$els.content.contains(e.target); - var currentRange = component.getCurrentRange(); - var clear = currentRange && currentRange.startContainer === currentRange.endContainer && currentRange.startOffset === currentRange.endOffset; - if (!clear || isInside) { + component.touchHandler = function (e) { + if (component.$els.content.contains(e.target)) { component.saveCurrentRange(); } }; - window.addEventListener("touchend", component.touchHander, false); + window.addEventListener("touchend", component.touchHandler, false); }, beforeDestroy: function beforeDestroy() { var editor = this; - window.removeEventListener("touchend", editor.touchHander); + window.removeEventListener("touchend", editor.touchHandler); editor.modules.forEach(function (module) { if (typeof module.destroyed == "function") { module.destroyed(editor); @@ -1416,13 +1449,22 @@ return /******/ (function(modules) { // webpackBootstrap // // // + //