1+ /*!
2+ * Simditor v2.3.25
3+ * http://simditor.tower.im/
4+ * 2019-05-01
5+ */
16( function ( root , factory ) {
27 if ( typeof define === 'function' && define . amd ) {
38 // AMD. Register as an anonymous module unless amdModuleId is set
4- define ( 'simditor' , [ "jquery" , "simple-module" , "simple-hotkeys" , "simple-uploader" ] , function ( $ , SimpleModule , simpleHotkeys , simpleUploader ) {
5- return ( root [ 'Simditor' ] = factory ( $ , SimpleModule , simpleHotkeys , simpleUploader ) ) ;
9+ define ( 'simditor' , [ "jquery" , "simple-module" , "simple-hotkeys" , "simple-uploader" , "dompurify" ] , function ( $ , SimpleModule , simpleHotkeys , simpleUploader , DOMPurify ) {
10+ return ( root [ 'Simditor' ] = factory ( $ , SimpleModule , simpleHotkeys , simpleUploader , DOMPurify ) ) ;
611 } ) ;
712 } else if ( typeof exports === 'object' ) {
813 // Node. Does not work with strict CommonJS, but
914 // only CommonJS-like environments that support module.exports,
1015 // like Node.
11- module . exports = factory ( require ( "jquery" ) , require ( "simple-module" ) , require ( "simple-hotkeys" ) , require ( "simple-uploader" ) ) ;
16+ module . exports = factory ( require ( "jquery" ) , require ( "simple-module" ) , require ( "simple-hotkeys" ) , require ( "simple-uploader" ) , require ( "dompurify" ) ) ;
1217 } else {
13- root [ 'Simditor' ] = factory ( jQuery , SimpleModule , simple . hotkeys , simple . uploader ) ;
18+ root [ 'Simditor' ] = factory ( jQuery , SimpleModule , simple . hotkeys , simple . uploader , window . DOMPurify ) ;
1419 }
15- } ( this , function ( $ , SimpleModule , simpleHotkeys , simpleUploader ) {
20+ } ( this , function ( $ , SimpleModule , simpleHotkeys , simpleUploader , DOMPurify ) {
1621
1722var AlignmentButton , BlockquoteButton , BoldButton , Button , Clipboard , CodeButton , CodePopover , ColorButton , FontScaleButton , Formatter , HrButton , ImageButton , ImagePopover , IndentButton , Indentation , InputManager , ItalicButton , Keystroke , LinkButton , LinkPopover , ListButton , OrderListButton , OutdentButton , Popover , Selection , Simditor , StrikethroughButton , TableButton , TitleButton , Toolbar , UnderlineButton , UndoManager , UnorderListButton , Util ,
1823 extend = function ( child , parent ) { for ( var key in parent ) { if ( hasProp . call ( parent , key ) ) child [ key ] = parent [ key ] ; } function ctor ( ) { this . constructor = child ; } ctor . prototype = parent . prototype ; child . prototype = new ctor ( ) ; child . __super__ = parent . prototype ; return child ; } ,
@@ -1611,8 +1616,8 @@ UndoManager = (function(superClass) {
16111616 }
16121617 if ( ! startContainer || ! endContainer ) {
16131618 if ( typeof console !== "undefined" && console !== null ) {
1614- if ( typeof console . warn === "function" ) {
1615- console . warn ( 'simditor: invalid caret state' ) ;
1619+ if ( typeof console . info === "function" ) {
1620+ console . info ( 'simditor: invalid caret state' ) ;
16161621 }
16171622 }
16181623 return ;
@@ -2262,7 +2267,7 @@ Clipboard = (function(superClass) {
22622267 }
22632268 return this . editor . body . on ( 'paste' , ( function ( _this ) {
22642269 return function ( e ) {
2265- var range ;
2270+ var pasteBinAnchor , range ;
22662271 if ( _this . pasting || _this . _pasteBin ) {
22672272 return ;
22682273 }
@@ -2277,10 +2282,17 @@ Clipboard = (function(superClass) {
22772282 } else {
22782283 _this . editor . formatter . format ( ) ;
22792284 _this . editor . selection . setRangeAtStartOf ( _this . editor . body . find ( 'p:first' ) ) ;
2285+ range = _this . editor . selection . _range ;
22802286 }
22812287 if ( _this . _processPasteByClipboardApi ( e ) ) {
22822288 return false ;
22832289 }
2290+ pasteBinAnchor = $ ( '<span>' ) ;
2291+ range . insertNode ( pasteBinAnchor [ 0 ] ) ;
2292+ _this . _createPasteBin ( pasteBinAnchor ) ;
2293+ pasteBinAnchor . remove ( ) ;
2294+ range . collapse ( true ) ;
2295+ _this . editor . selection . range ( range ) ;
22842296 _this . editor . inputManager . throttledValueChanged . clear ( ) ;
22852297 _this . editor . inputManager . throttledSelectionChanged . clear ( ) ;
22862298 _this . editor . undoManager . throttledPushState . clear ( ) ;
@@ -2325,9 +2337,18 @@ Clipboard = (function(superClass) {
23252337 }
23262338 } ;
23272339
2340+ Clipboard . prototype . _createPasteBin = function ( anchorNode ) {
2341+ var anchorOffset , editorOffset ;
2342+ anchorOffset = anchorNode . offset ( ) ;
2343+ editorOffset = this . editor . el . offset ( ) ;
2344+ return this . _pasteBin = $ ( '<div contenteditable="true" />' ) . addClass ( 'simditor-paste-bin' ) . attr ( 'tabIndex' , '-1' ) . css ( {
2345+ top : anchorOffset . top - editorOffset . top ,
2346+ left : anchorOffset . left - editorOffset . left
2347+ } ) . appendTo ( this . editor . el ) ;
2348+ } ;
2349+
23282350 Clipboard . prototype . _getPasteContent = function ( callback ) {
23292351 var state ;
2330- this . _pasteBin = $ ( '<div contenteditable="true" />' ) . addClass ( 'simditor-paste-bin' ) . attr ( 'tabIndex' , '-1' ) . appendTo ( this . editor . el ) ;
23312352 state = {
23322353 html : this . editor . body . html ( ) ,
23332354 caret : this . editor . undoManager . caretPosition ( )
@@ -2337,7 +2358,7 @@ Clipboard = (function(superClass) {
23372358 return function ( ) {
23382359 var pasteContent ;
23392360 _this . editor . hidePopover ( ) ;
2340- _this . editor . body . get ( 0 ) . innerHTML = state . html ;
2361+ _this . editor . body . get ( 0 ) . innerHTML = DOMPurify ? DOMPurify . sanitize ( state . html ) : state . html ;
23412362 _this . editor . undoManager . caretPosition ( state . caret ) ;
23422363 _this . editor . body . focus ( ) ;
23432364 _this . editor . selection . reset ( ) ;
@@ -2644,7 +2665,7 @@ Simditor = (function(superClass) {
26442665 Simditor . prototype . setValue = function ( val ) {
26452666 this . hidePopover ( ) ;
26462667 this . textarea . val ( val ) ;
2647- this . body . get ( 0 ) . innerHTML = val ;
2668+ this . body . get ( 0 ) . innerHTML = DOMPurify ? DOMPurify . sanitize ( val ) : val ;
26482669 this . formatter . format ( ) ;
26492670 this . formatter . decorate ( ) ;
26502671 this . util . reflow ( this . body ) ;
@@ -3152,7 +3173,7 @@ Popover = (function(superClass) {
31523173 }
31533174 this . el . siblings ( '.simditor-popover' ) . each ( function ( i , popover ) {
31543175 popover = $ ( popover ) . data ( 'popover' ) ;
3155- if ( popover . active ) {
3176+ if ( popover && popover . active ) {
31563177 return popover . hide ( ) ;
31573178 }
31583179 } ) ;
@@ -4484,7 +4505,7 @@ ImageButton = (function(superClass) {
44844505 return ;
44854506 }
44864507 $img = $mask . data ( 'img' ) ;
4487- if ( ! ( $img . hasClass ( 'uploading' ) && $img . parent ( ) . length > 0 ) ) {
4508+ if ( ! ( $img && $img . hasClass ( 'uploading' ) && $img . parent ( ) . length > 0 ) ) {
44884509 $mask . remove ( ) ;
44894510 return ;
44904511 }
@@ -4648,7 +4669,7 @@ ImageButton = (function(superClass) {
46484669 $mask . remove ( ) ;
46494670 return $img . removeData ( 'mask' ) . removeClass ( 'loading' ) ;
46504671 } ;
4651- return img . src = src ;
4672+ return img . setAttribute ( ' src' , src ) ;
46524673 } ;
46534674
46544675 ImageButton . prototype . createImage = function ( name ) {
0 commit comments