diff --git a/assets/editor.js b/assets/editor.js index af44d762..64b3d3ae 100644 --- a/assets/editor.js +++ b/assets/editor.js @@ -1,4 +1,36 @@ +/* eslint-disable linebreak-style */ +/* eslint-disable no-unused-vars */ /* eslint-disable no-undef */ + +function insertAtCursor(myField, myValue) { + var textTop = myField.scrollTop; + var documentTop = document.documentElement.scrollTop; + + //IE 浏览器 + if (document.selection) { + myField.focus(); + var sel = document.selection.createRange(); + sel.text = myValue; + sel.select(); + } + + //FireFox、Chrome等 + else if (myField.selectionStart || myField.selectionStart == '0') { + var startPos = myField.selectionStart; + var endPos = myField.selectionEnd; + myField.value = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos, myField.value.length); + myField.focus(); + myField.selectionStart = startPos + myValue.length; + myField.selectionEnd = startPos + myValue.length; + } else { + myField.value += myValue; + myField.focus(); + } + + myField.scrollTop = textTop; + document.documentElement.scrollTop=documentTop; +} + $(function() { if($('#wmd-button-row').length>0){ $('#wmd-button-row').append('
  • 图集
  • '); @@ -15,25 +47,6 @@ $(function() { } $(document).on('click','#wmd-photoset-button',function() { myField = document.getElementById('text'); - if (document.selection) { - myField.focus(); - sel = document.selection.createRange(); - sel.text = '\n\n[photos]\n\n'+sel.text+'[/photos]\n\n'; - myField.focus(); - } - else if (myField.selectionStart || myField.selectionStart == '0') { - var startPos = myField.selectionStart; - var endPos = myField.selectionEnd; - myField.value = myField.value.substring(0, startPos) - + '\n\n[photos]\n\n[/photos]\n\n' - + myField.value.substring(endPos, myField.value.length); - myField.focus(); - myField.selectionStart=startPos+'[photos]'.length+3; - myField.selectionEnd=startPos+'[photos]'.length+3; - } - else{ - myField.value +='\n\n[photos]\n\n[/photos]\n\n'; - myField.focus(); - } + insertAtCursor(myField, '\n\n[photos]\n\n[/photos]\n\n'); }); }); diff --git a/assets/libs/owo/owo_01.js b/assets/libs/owo/owo_02.js similarity index 83% rename from assets/libs/owo/owo_01.js rename to assets/libs/owo/owo_02.js index d4f0e815..36bc88a2 100644 --- a/assets/libs/owo/owo_01.js +++ b/assets/libs/owo/owo_02.js @@ -1,5 +1,42 @@ +/* eslint-disable linebreak-style */ +/* eslint-disable no-console */ +/* eslint-disable no-undef */ +/* eslint-disable quotes */ +/* eslint-disable no-unused-vars */ 'use strict'; +function insertAtCursor(myField, myValue) { + var textTop = myField.scrollTop; + var documentTop = document.documentElement.scrollTop; + + //IE 浏览器 + if (document.selection) { + myField.focus(); + var sel = document.selection.createRange(); + sel.text = myValue; + sel.select(); + } + + //FireFox、Chrome等 + else if (myField.selectionStart || myField.selectionStart == '0') { + var startPos = myField.selectionStart; + var endPos = myField.selectionEnd; + + myField.value = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos, myField.value.length); + + myField.focus(); + myField.selectionStart = startPos + myValue.length; + myField.selectionEnd = startPos + myValue.length; + } else { + + myField.value += myValue; + myField.focus(); + } + + myField.scrollTop = textTop; + document.documentElement.scrollTop=documentTop; +} + var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } @@ -100,9 +137,11 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons var cursorPos = _this2.area.selectionEnd; var areaValue = _this2.area.value; if (target.dataset.id == "not-given") { - _this2.area.value = areaValue.slice(0, cursorPos) + target.innerHTML + areaValue.slice(cursorPos) + ' '; + insertAtCursor(_this2.area, ' ' + target.innerHTML + ' '); + //_this2.area.value = areaValue.slice(0, cursorPos) + target.innerHTML + areaValue.slice(cursorPos) + ' '; } else { - _this2.area.value = areaValue.slice(0, cursorPos) + target.dataset.id + areaValue.slice(cursorPos) + ' '; + insertAtCursor(_this2.area, ' ' + target.dataset.id + ' '); + //_this2.area.value = areaValue.slice(0, cursorPos) + target.dataset.id + areaValue.slice(cursorPos) + ' '; } _this2.area.focus(); _this2.toggle(); diff --git a/gulpfile.js b/gulpfile.js index ec51ddcf..fd11c5d6 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,3 +1,4 @@ +/* eslint-disable linebreak-style */ /* eslint-disable no-undef */ var gulp = require('gulp'); var sass = require('gulp-sass'); diff --git a/libs/Utils.php b/libs/Utils.php index a22fd617..523f5b95 100644 --- a/libs/Utils.php +++ b/libs/Utils.php @@ -106,7 +106,7 @@ public static function isMobile() public static function addButton() { echo ''; echo '