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 // // // + //
+ // + // + //
// // // + + + + + +
+ +
+ + + + \ No newline at end of file diff --git a/package.json b/package.json index c2c0962..9bfcd63 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vue-html5-editor", - "version": "0.4.2", + "version": "0.5.0", "description": "A WYSIWYG text editor base on html5 and vue", "repository": { "type": "git", diff --git a/src/array-polyfill.js b/src/array-polyfill.js new file mode 100644 index 0000000..0f45e97 --- /dev/null +++ b/src/array-polyfill.js @@ -0,0 +1,40 @@ +/** + * Created by peak on 16/9/12. + */ +export default function () { + if (!Array.prototype.includes) { + Array.prototype.includes = function (searchElement /*, fromIndex*/) { + 'use strict'; + if (this == null) { + throw new TypeError('Array.prototype.includes called on null or undefined'); + } + + var O = Object(this); + var len = parseInt(O.length, 10) || 0; + if (len === 0) { + return false; + } + var n = parseInt(arguments[1], 10) || 0; + var k; + if (n >= 0) { + k = n; + } else { + k = len + n; + if (k < 0) { + k = 0; + } + } + var currentElement; + while (k < len) { + currentElement = O[k]; + if (searchElement === currentElement || + (searchElement !== searchElement && currentElement !== currentElement)) { + return true; + } + k++; + } + return false; + }; + } +} + diff --git a/src/editor.vue b/src/editor.vue index 3c7351b..c5ba695 100644 --- a/src/editor.vue +++ b/src/editor.vue @@ -21,7 +21,8 @@ export default { props: { content: { - twoWay: true, + //no longer be required + //twoWay: true, type: String, required: true, default: "" @@ -100,6 +101,9 @@ computeDashboardStyle(){ this.dashboardStyle = {'max-height': this.$els.content.clientHeight + 'px'} }, + getContentElement(){ + return this.$els.content + }, toggleFullScreen(){ this.fullScreen = !this.fullScreen }, @@ -113,11 +117,11 @@ this.dashboard = null }, getCurrentRange(){ - let selection = window.getSelection() - return selection.rangeCount ? selection.getRangeAt(0) : null + return this.range }, saveCurrentRange(){ - let range = this.getCurrentRange() + let selection = window.getSelection ? window.getSelection() : document.getSelection() + let range = selection.rangeCount ? selection.getRangeAt(0) : null if (!range) { return } @@ -127,7 +131,7 @@ } }, restoreSelection(){ - let selection = window.getSelection() + let selection = window.getSelection ? window.getSelection() : document.getSelection() selection.removeAllRanges() if (this.range) { selection.addRange(this.range) @@ -170,21 +174,17 @@ component.content = component.$els.content.innerHTML }, false) - component.touchHander = function (e) { - let isInside = (component.$els.content.contains(e.target)) - let currentRange = component.getCurrentRange() - let 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(){ let 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) diff --git a/src/i18n/en-us.js b/src/i18n/en-us.js index d313180..d9a7ad3 100644 --- a/src/i18n/en-us.js +++ b/src/i18n/en-us.js @@ -40,5 +40,6 @@ export default { "abort": "abort", "reset": "reset", "hr": "horizontal rule", - "undo": "undo" + "undo": "undo", + "line height": "line height" } \ No newline at end of file diff --git a/src/i18n/zh-cn.js b/src/i18n/zh-cn.js index 8046062..0d18412 100644 --- a/src/i18n/zh-cn.js +++ b/src/i18n/zh-cn.js @@ -40,5 +40,6 @@ export default { "abort": "中断", "reset": "重置", "hr": "分隔线", - "undo": "撤消" + "undo": "撤消", + "line height": "行高" } \ No newline at end of file diff --git a/src/index.js b/src/index.js index 107432d..26e051d 100644 --- a/src/index.js +++ b/src/index.js @@ -15,6 +15,7 @@ import moduleFullScreen from "./modules/full-screen/index"; import moduleInfo from "./modules/info/index"; import i18nZhCn from "./i18n/zh-cn"; import i18nEnUs from "./i18n/en-us"; +import arrayFill from "./array-polyfill"; /** * install @@ -23,6 +24,8 @@ import i18nEnUs from "./i18n/en-us"; */ exports.install = (Vue, options) => { + arrayFill() + options = options || {} //modules @@ -52,6 +55,33 @@ exports.install = (Vue, options) => { }) modules = modules.concat(arr) } + //hidden modules + if (Array.isArray(options.hiddenModules)) { + modules = (()=> { + let arr = [] + modules.forEach(function (m) { + if (!options.hiddenModules.includes(m.name)) { + arr.push(m) + } + }) + return arr + })() + } + //visible modules + if (Array.isArray(options.visibleModules)) { + modules = (()=> { + let arr = [] + options.visibleModules.forEach(function (name) { + modules.forEach(function (module) { + if (module.name == name) { + arr.push(module) + } + }) + }) + return arr + })() + } + let components = {} modules.forEach((module)=> { diff --git a/src/modules/font/dashboard.vue b/src/modules/font/dashboard.vue index 0112dfd..c1ca146 100644 --- a/src/modules/font/dashboard.vue +++ b/src/modules/font/dashboard.vue @@ -21,6 +21,14 @@ +
+ + +