11/**
22 * Vue-html5-editor 1.0.0
33 * https://github.com/PeakTai/vue-html5-editor
4- * build at Mon Mar 06 2017 17:49:58 GMT+0800 (CST)
4+ * build at Thu Mar 09 2017 16:42:28 GMT+0800 (CST)
55 */
66
77( function ( global , factory ) {
@@ -27,6 +27,62 @@ function __$styleInject(css, returnValue) {
2727 return returnValue ;
2828}
2929
30+ var polyfill = function ( ) {
31+ // https://tc39.github.io/ecma262/#sec-array.prototype.includes
32+ if ( ! Array . prototype . includes ) {
33+ Object . defineProperty ( Array . prototype , 'includes' , {
34+ value : function value ( searchElement , fromIndex ) {
35+ // 1. Let O be ? ToObject(this value).
36+ if ( this == null ) {
37+ throw new TypeError ( '"this" is null or not defined' )
38+ }
39+
40+ var o = Object ( this ) ;
41+
42+ // 2. Let len be ? ToLength(? Get(O, "length")).
43+ var len = o . length >>> 0 ;
44+
45+ // 3. If len is 0, return false.
46+ if ( len === 0 ) {
47+ return false
48+ }
49+
50+ // 4. Let n be ? ToInteger(fromIndex).
51+ // (If fromIndex is undefined, this step produces the value 0.)
52+ var n = fromIndex | 0 ;
53+
54+ // 5. If n ≥ 0, then
55+ // a. Let k be n.
56+ // 6. Else n < 0,
57+ // a. Let k be len + n.
58+ // b. If k < 0, let k be 0.
59+ var k = Math . max ( n >= 0 ? n : len - Math . abs ( n ) , 0 ) ;
60+
61+ // 7. Repeat, while k < len
62+ while ( k < len ) {
63+ // a. Let elementK be the result of ? Get(O, ! ToString(k)).
64+ // b. If SameValueZero(searchElement, elementK) is true, return true.
65+ // c. Increase k by 1.
66+ // NOTE: === provides the correct "SameValueZero" comparison needed here.
67+ if ( o [ k ] === searchElement ) {
68+ return true
69+ }
70+ k ++ ;
71+ }
72+
73+ // 8. Return false
74+ return false
75+ }
76+ } ) ;
77+ }
78+ // text.contains()
79+ if ( ! Text . prototype . contains ) {
80+ Text . prototype . contains = function contains ( node ) {
81+ return this === node
82+ } ;
83+ }
84+ } ;
85+
3086var template = "<div> <button type=\"button\" @click=\"$parent.execCommand('justifyLeft')\"> {{$parent.locale[\"left justify\"]}} </button> <button type=\"button\" @click=\"$parent.execCommand('justifyCenter')\"> {{$parent.locale[\"center justify\"]}} </button> <button type=\"button\" @click=\"$parent.execCommand('justifyRight')\"> {{$parent.locale[\"right justify\"]}} </button> </div>" ;
3187
3288/**
@@ -743,6 +799,14 @@ var isInlineElement = function (node) {
743799 return inlineNodeNames . includes ( node . nodeName )
744800} ;
745801
802+ // for IE 11
803+ if ( ! Text . prototype . contains ) {
804+ Text . prototype . contains = function contains ( otherNode ) {
805+ return this === otherNode
806+ } ;
807+ }
808+
809+
746810/**
747811 * Created by peak on 2017/2/14.
748812 */
@@ -1143,14 +1207,24 @@ var editor = {
11431207 return this . range
11441208 } ,
11451209 saveCurrentRange : function saveCurrentRange ( ) {
1210+ var this$1 = this ;
1211+
11461212 var selection = window . getSelection ? window . getSelection ( ) : document . getSelection ( ) ;
1147- var range = selection . rangeCount ? selection . getRangeAt ( 0 ) : null ;
1148- if ( ! range ) {
1213+ if ( ! selection . rangeCount ) {
11491214 return
11501215 }
1151- if ( this . $refs . content . contains ( range . startContainer ) &&
1152- this . $refs . content . contains ( range . endContainer ) ) {
1153- this . range = range ;
1216+ var content = this . $refs . content ;
1217+ for ( var i = 0 ; i < selection . rangeCount ; i ++ ) {
1218+ var range = selection . getRangeAt ( 0 ) ;
1219+ var start = range . startContainer ;
1220+ var end = range . endContainer ;
1221+ // for IE11 : node.contains(textNode) always return false
1222+ start = start . nodeType === Node . TEXT_NODE ? start . parentNode : start ;
1223+ end = end . nodeType === Node . TEXT_NODE ? end . parentNode : end ;
1224+ if ( content . contains ( start ) && content . contains ( end ) ) {
1225+ this$1 . range = range ;
1226+ break
1227+ }
11541228 }
11551229 } ,
11561230 restoreSelection : function restoreSelection ( ) {
@@ -1194,12 +1268,15 @@ var editor = {
11941268 var content = this . $refs . content ;
11951269 content . innerHTML = this . content ;
11961270 content . addEventListener ( 'mouseup' , this . saveCurrentRange , false ) ;
1197- content . addEventListener ( 'keyup' , this . saveCurrentRange , false ) ;
1198- content . addEventListener ( 'mouseout' , this . saveCurrentRange , false ) ;
11991271 content . addEventListener ( 'keyup' , function ( ) {
12001272 this$1 . $emit ( 'change' , content . innerHTML ) ;
1273+ this$1 . saveCurrentRange ( ) ;
1274+ } , false ) ;
1275+ content . addEventListener ( 'mouseout' , function ( e ) {
1276+ if ( e . target === content ) {
1277+ this$1 . saveCurrentRange ( ) ;
1278+ }
12011279 } , false ) ;
1202-
12031280 this . touchHandler = function ( e ) {
12041281 if ( content . contains ( e . target ) ) {
12051282 this$1 . saveCurrentRange ( ) ;
@@ -1349,6 +1426,7 @@ function mixin(source, ext) {
13491426 return source
13501427}
13511428
1429+ polyfill ( ) ;
13521430/**
13531431 * Vue html5 Editor
13541432 * @param Vue {Vue}
0 commit comments