11/* DOKUWIKI:include jquery.paste_image_reader.js */
22
33jQuery ( function ( ) {
4- if ( ! jQuery ( '#wiki__text' ) . length ) return ;
5-
6- jQuery ( 'html' ) . pasteImageReader ( {
7- callback : function ( x ) {
8- console . log ( x ) ;
9-
10- // create dialog
11- var offset = jQuery ( '.plugin_imagepaste' ) . length * 20 ;
12- var $box = jQuery ( '<div><div class="content">' + LANG . plugins . imgpaste . inprogress + '</div></div>' ) ;
13- $box . dialog ( {
14- title : 'Upload' ,
15- dialogClass : 'plugin_imagepaste' ,
16- closeOnEscape : false ,
17- resizable : false ,
18- position : {
19- my : 'center+' + offset + ' center+' + offset
20- } ,
21- appendTo : '.dokuwiki'
22- } ) ;
23-
24- // upload via AJAX
25- jQuery . ajax ( {
26- url : DOKU_BASE + 'lib/exe/ajax.php' ,
27- type : 'POST' ,
28- data : {
29- call : 'plugin_imgpaste' ,
30- data : x . dataURL ,
31- id : JSINFO . id
32- } ,
33-
34- // insert syntax and close dialog
35- success : function ( data ) {
36- $box . find ( '.content' ) . addClass ( 'success' ) . text ( data . message ) ;
37- insertAtCarret ( 'wiki__text' , '{{:' + data . id + '}}' ) ;
38- $box . delay ( 500 ) . fadeOut ( 500 , function ( ) {
39- $box . dialog ( 'destroy' ) . remove ( )
40- } ) ;
41- } ,
42-
43- // display error and close dialog
44- error : function ( xhr , status , error ) {
45- $box . find ( '.content' ) . addClass ( 'error' ) . text ( error ) ;
46- $box . delay ( 1000 ) . fadeOut ( 500 , function ( ) {
47- $box . dialog ( 'destroy' ) . remove ( )
48- } ) ;
49- }
50- } ) ;
4+ var _didInit = false ;
5+ function init ( ) {
6+ if ( ! jQuery ( '#wiki__text' ) . length || _didInit ) return ;
7+ _didInit = true ;
8+ jQuery ( 'html' ) . pasteImageReader ( {
9+ callback : function ( x ) {
10+ if ( ! jQuery ( '#wiki__text' ) . length ) return ;
11+
12+ console . log ( x ) ;
13+
14+ // create dialog
15+ var offset = jQuery ( '.plugin_imagepaste' ) . length * 20 ;
16+ var $box = jQuery ( '<div><div class="content">' + LANG . plugins . imgpaste . inprogress + '</div></div>' ) ;
17+ $box . dialog ( {
18+ title : 'Upload' ,
19+ dialogClass : 'plugin_imagepaste' ,
20+ closeOnEscape : false ,
21+ resizable : false ,
22+ position : {
23+ my : 'center+' + offset + ' center+' + offset
24+ } ,
25+ appendTo : '.dokuwiki'
26+ } ) ;
27+
28+ // upload via AJAX
29+ jQuery . ajax ( {
30+ url : DOKU_BASE + 'lib/exe/ajax.php' ,
31+ type : 'POST' ,
32+ data : {
33+ call : 'plugin_imgpaste' ,
34+ data : x . dataURL ,
35+ id : JSINFO . id
36+ } ,
37+
38+ // insert syntax and close dialog
39+ success : function ( data ) {
40+ $box . find ( '.content' ) . addClass ( 'success' ) . text ( data . message ) ;
41+ insertAtCarret ( 'wiki__text' , '{{:' + data . id + '}}' ) ;
42+ $box . delay ( 500 ) . fadeOut ( 500 , function ( ) {
43+ $box . dialog ( 'destroy' ) . remove ( )
44+ } ) ;
45+ } ,
46+
47+ // display error and close dialog
48+ error : function ( xhr , status , error ) {
49+ $box . find ( '.content' ) . addClass ( 'error' ) . text ( error ) ;
50+ $box . delay ( 1000 ) . fadeOut ( 500 , function ( ) {
51+ $box . dialog ( 'destroy' ) . remove ( )
52+ } ) ;
53+ }
54+ } ) ;
55+ }
56+ } ) ;
57+ }
58+
59+ init ( ) ;
60+
61+ // fastwiki plugin support
62+ jQuery ( window ) . on ( 'fastwiki:afterSwitch' , function ( evt , viewMode , isSectionEdit , prevViewMode ) {
63+ if ( viewMode == 'edit' || isSectionEdit ) {
64+ init ( ) ;
5165 }
5266 } ) ;
53- } ) ;
67+ } ) ;
0 commit comments