1var ep = { }; 2 3ep.imgBase = null; 4ep.config = etherpad_lite_config; 5ep.aceWasEnabled = false; 6ep.cmWasEnabled = false; 7ep.isOwner = false; 8ep.readOnly = false; 9ep.isSaveable = false; 10ep.timer = null; 11ep.lang = null; 12ep.password = ""; 13ep.opened = false; 14ep.hasPadPlugin = false; 15 16ep.on_disable = function() { 17 if (ep.isOwner) { 18 jQuery.post( 19 DOKU_BASE + 'lib/exe/ajax.php', 20 { 'id' : ep.config["id"], "rev" : ep.config["rev"], "call" : "pad_getText", "isSaveable" : ep.isSaveable, "readOnly" : false }, 21 function(data) { 22 if (data.error) { 23 alert(data.error); 24 } else { 25 jQuery('#wiki__text').val(data.text); 26 self.textChanged = true; 27 jQuery('.pad-toggle').hide(); 28 jQuery('.pad-toggle-off').show(); 29 jQuery('.pad-iframecontainer').html(""); 30 jQuery('.pad-iframecontainer').hide(); 31 jQuery('#wiki__text').show(); 32 jQuery(".pad-action-buttons").hide(); 33 jQuery(".nopad-action-buttons").show(); 34 jQuery('.ace-toggle-hidden').removeClass('ace-toggle-hidden').show(); 35 if (!ep.isSaveable) { // fix toolbar 36 jQuery('#wiki__text').attr('readOnly','readOnly'); 37 jQery('tool__bar').empty(); 38 } 39 ep.opened = false; 40 ep.on_disable_close(); 41 } 42 } 43 ); 44 } else { 45 jQuery('.pad-toggle').hide(); 46 jQuery('.pad-toggle-off').show(); 47 jQuery('.pad-iframecontainer').html(""); 48 jQuery('.pad-iframecontainer').hide(); 49 jQuery('#wiki__text').show(); 50 jQuery(".pad-action-buttons").hide(); 51 jQuery(".nopad-action-buttons").show(); 52 jQuery('.ace-toggle-hidden').removeClass('ace-toggle-hidden').show(); 53 if (!ep.isSaveable) { // fix toolbar 54 jQuery('#wiki__text').attr('readOnly','readOnly'); 55 jQuery('#tool__bar').empty(); 56 } 57 ep.opened = false; 58 if (ep.aceWasEnabled) { 59 ep.aceShow(); 60 } 61 if (ep.cmWasEnabled) { 62 ep.cmShow(); 63 } 64 } 65}; 66 67ep.on_disable_close = function() { 68 window.clearInterval(ep.timer); ep.timer = null; 69 jQuery.post( 70 DOKU_BASE + 'lib/exe/ajax.php', 71 { "id" : ep.config["id"], "rev" : ep.config["rev"], "call" : "pad_close", 72 "sectok" : jQuery('input[name=sectok]').val(), 73 "prefix" : jQuery('#dw__editform').find('input[name=prefix]').val(), 74 "suffix" : jQuery('#dw__editform').find('input[name=suffix]').val(), 75 "date" : jQuery('#dw__editform').find('input[name=date]').val(), 76 "isSaveable" : ep.isSaveable, 77 "readOnly" : false 78 }, 79 function(data) { 80 if (data.error) { 81 alert(data.error); 82 } else { 83 jQuery('#wiki__text').val(data.text); 84 self.textChanged = true; 85 if (ep.aceWasEnabled) { 86 ep.aceShow(); 87 } 88 if (ep.cmWasEnabled) { 89 ep.cmShow(); 90 } 91 } 92 } 93 ); 94}; 95 96ep.on_password_cancel = function(event) { 97 ep.pwdlg.dlg.dialog('close'); 98 return false; 99} 100 101ep.on_password_submit = function() { 102 ep.password = ep.pwdlg.inp.val(); 103 ep.pwdlg.dlg.dialog('close'); 104 ep.on_re_enable(true); 105 return false; 106} 107ep.on_password_click = function() { 108 if (!ep.readOnly) { 109 alert(ep.lang.alreadywriteable); 110 } else { 111 ep.on_password(); 112 } 113 return false; 114} 115 116ep.on_password = function() { 117 ep.pwdlg.inp.val(ep.password); 118 ep.pwdlg.dlg.dialog('open'); 119} 120 121ep.init_password = function() { 122 ep.pwdlg = {}; 123 ep.pwdlg.dlg = jQuery('<div/>').attr('title',ep.lang.password); 124 ep.pwdlg.frm = jQuery('<form/>').addClass('pad-form').submit(ep.on_password_submit).appendTo(ep.pwdlg.dlg); 125 jQuery('<label/>').attr('for','password').text(ep.lang.passwordforpad).appendTo(ep.pwdlg.frm); 126 ep.pwdlg.inp = jQuery('<input/>').attr('name','password').attr('type','password').appendTo(ep.pwdlg.frm); 127 jQuery('<input/>').attr('type','submit').val(ep.lang.submit).click(ep.on_password_submit).appendTo(ep.pwdlg.frm); 128 jQuery('<input/>').attr('type','reset').val(ep.lang.reset).click(ep.on_password_cancel).appendTo(ep.pwdlg.frm); 129 ep.pwdlg.dlg.dialog({modal: true, width: 500,height:150, autoOpen: false}); 130} 131 132ep.init_security = function() { 133 ep.dlg = {}; 134 ep.dlg.dlg = jQuery('<div/>').attr('title',ep.lang.securitymanager); 135 ep.dlg.frm = jQuery('<form/>').addClass('pad-form').submit(ep.on_security_submit).appendTo(ep.dlg.dlg); 136 var encLabel = jQuery('<label/>').attr('for','encMode').text(ep.lang.encryption+':'); 137 ep.dlg.encMode = jQuery('<select/>').attr('name','encMode').attr('size',1).change(ep.on_security_encmode_changed); 138 ep.dlg.encMode.append(jQuery('<option/>').val('enc').text(ep.lang.padIsEncrypted)); 139 ep.dlg.encMode.append(jQuery('<option/>').val('noenc').text(ep.lang.padIsUnencrypted)); 140 ep.dlg.encPassword = jQuery('<span/>').show(); 141 var encALabel = jQuery('<label/>').attr('for','encAccessMode').text(ep.lang.accessRequires+':'); 142 ep.dlg.encAMode = jQuery('<select/>').attr('name','encAccessMode').attr('size',1); 143 ep.dlg.encAMode.append(jQuery('<option/>').val('wikiread').text(ep.lang.permToReadWiki)); 144 ep.dlg.encAMode.append(jQuery('<option/>').val('wikiwrite').text(ep.lang.permToWriteWiki)); 145 jQuery('<label/>').attr('for','encpw').text(ep.lang.password+':').appendTo(ep.dlg.encPassword); 146 ep.dlg.encPasswordFrm = jQuery('<input/>').attr('name','encpw').attr('type','password').appendTo(ep.dlg.encPassword); 147 148 var readLabel = jQuery('<label/>').attr('for','readMode').text(ep.lang.readAccessRequires+':'); 149 ep.dlg.readMode = jQuery('<select/>').attr('name','readMode').attr('size',1).change(ep.on_security_readmode_changed); 150 ep.dlg.readMode.append(jQuery('<option/>').val('wikiread').text(ep.lang.permToReadWiki)); 151 ep.dlg.readMode.append(jQuery('<option/>').val('wikiread+password').text(ep.lang.permToReadWikiPlusPassword)); 152 ep.dlg.readMode.append(jQuery('<option/>').val('wikiwrite').text(ep.lang.permToWriteWiki)); 153 ep.dlg.readMode.append(jQuery('<option/>').val('wikiwrite+password').text(ep.lang.permToWriteWikiPlusPassword)); 154 ep.dlg.readPassword = jQuery('<span/>').hide(); 155 jQuery('<label/>').attr('for','readpw').text(ep.lang.readPassword+':').appendTo(ep.dlg.readPassword); 156 ep.dlg.readPasswordFrm = jQuery('<input/>').attr('name','readpw').attr('type','password').appendTo(ep.dlg.readPassword); 157 158 var writeLabel = jQuery('<label/>').attr('for','writeMode').text(ep.lang.writeAccessRequires+':'); 159 ep.dlg.writeMode = jQuery('<select/>').attr('name','writeMode').attr('size',1).change(ep.on_security_writemode_changed); 160 ep.dlg.writeMode.append(jQuery('<option/>').val('wikiwrite').text(ep.lang.permToWriteWiki)); 161 ep.dlg.writeMode.append(jQuery('<option/>').val('wikiwrite+password').text(ep.lang.permToWriteWikiPlusPassword)); 162 ep.dlg.writePassword = jQuery('<span/>').hide(); 163 jQuery('<label/>').attr('for','writepw').text(ep.lang.writePassword+':').appendTo(ep.dlg.writePassword); 164 ep.dlg.writePasswordFrm = jQuery('<input/>').attr('name','writepw').attr('type','password').appendTo(ep.dlg.writePassword); 165 166 ep.dlg.frm.append(encLabel).append(ep.dlg.encMode); 167 ep.dlg.enc = jQuery('<span/>').show(); 168 ep.dlg.enc.append(encALabel).append(ep.dlg.encAMode).append(ep.dlg.encPassword); 169 ep.dlg.frm.append(ep.dlg.enc); 170 ep.dlg.noEnc = jQuery('<span/>').hide(); 171 ep.dlg.noEnc.append(readLabel).append(ep.dlg.readMode).append(ep.dlg.readPassword); 172 ep.dlg.noEnc.append(writeLabel).append(ep.dlg.writeMode).append(ep.dlg.writePassword); 173 ep.dlg.frm.append(ep.dlg.noEnc); 174 175 jQuery('<input/>').attr('type','submit').val(ep.lang.submit).click(ep.on_security_submit).appendTo(ep.dlg.frm); 176 jQuery('<input/>').attr('type','reset').val(ep.lang.reset).click(ep.on_security_cancel).appendTo(ep.dlg.frm); 177 178 ep.dlg.encMode.val('noenc'); 179 ep.dlg.encAMode.val('wikiwrite'); 180 ep.dlg.readMode.val('wikiwrite'); 181 ep.dlg.writeMode.val('wikiwrite'); 182 ep.dlg.encPasswordFrm.val(''); 183 ep.dlg.readPasswordFrm.val(''); 184 ep.dlg.writePasswordFrm.val(''); 185 186 ep.dlg.dlg.dialog({modal: true, width: 600,height:300, autoOpen: false}); 187} 188 189ep.on_security = function() { 190 ep.dlg.dlg.dialog('open'); 191 return false; 192} 193 194ep.on_security_submit = function() { 195 jQuery.post( 196 DOKU_BASE + 'lib/exe/ajax.php', 197 { 'id' : ep.config["id"], "rev" : ep.config["rev"], "call" : "pad_security", 198 "sectok" : jQuery('input[name=sectok]').val(), 199 "encMode" : ep.dlg.encMode.val(), 200 "encAMode" : ep.dlg.encAMode.val(), 201 "readMode" : ep.dlg.readMode.val(), 202 "writeMode" : ep.dlg.writeMode.val(), 203 "encpw" : ep.dlg.encPasswordFrm.val(), 204 "readpw" : ep.dlg.readPasswordFrm.val(), 205 "writepw" : ep.dlg.writePasswordFrm.val(), 206 "isSaveable" : ep.isSaveable, 207 "readOnly" : false 208 }, 209 function(data) { 210 if (data.error) { 211 alert(data.error); 212 } else { 213 ep.security_fill(data); 214 ep.dlg.dlg.dialog('close'); 215 jQuery('.pad-iframe').attr("src",data.url); 216 } 217 } 218 ); 219 return false; 220} 221 222ep.security_fill = function(data) { 223 if (!data.canPassword) { 224 jQuery('.pad-security').hide(); 225 } else { 226 jQuery('.pad-security').show(); 227 } 228 229 ep.dlg.encMode.val(data.encMode); 230 ep.dlg.encAMode.val(data.encAMode); 231 ep.dlg.readMode.val(data.readMode); 232 ep.dlg.writeMode.val(data.writeMode); 233 if (data.hasPassword) { 234 ep.dlg.encPasswordFrm.val(''); 235 } else { 236 ep.dlg.encPasswordFrm.val('***'); 237 } 238 ep.dlg.readPasswordFrm.val(data.readpw); 239 ep.dlg.writePasswordFrm.val(data.writepw); 240 ep.readOnly = data.isReadonly; 241 242 ep.on_security_encmode_changed(); 243 ep.on_security_readmode_changed(); 244 ep.on_security_writemode_changed(); 245 246 if (data.encMode == "enc") { 247 jQuery(".pad-security").attr("src",ep.imgBase+"lock.png"); 248 } else if (ep.dlg.writePasswordFrm.val() != "") { 249 jQuery(".pad-security").attr("src",ep.imgBase+"lock2.png"); 250 } else if (ep.dlg.readPasswordFrm.val() != "") { 251 jQuery(".pad-security").attr("src",ep.imgBase+"lock1.png"); 252 } else { 253 jQuery(".pad-security").attr("src",ep.imgBase+"nolock.png"); 254 } 255 if (ep.readOnly) { 256 jQuery(".pad-saveable").attr("src",ep.imgBase+"no-saveable.png"); 257 } else { 258 jQuery(".pad-saveable").attr("src",ep.imgBase+"saveable.png"); 259 } 260 261} 262 263ep.refresh = function() { 264 jQuery.post( 265 DOKU_BASE + 'lib/exe/ajax.php', 266 { 'id' : ep.config["id"], "rev" : ep.config["rev"], "call" : "pad_getText", "isSaveable" : ep.isSaveable, "readOnly" : false }, 267 function(data) { 268 if (data.error) { 269 alert(data.error); 270 } else { 271 jQuery('#wiki__text').val(data.text); 272 if (dw_locktimer) { 273 dw_locktimer.refresh(); 274 } 275 } 276 } 277 ); 278}; 279 280ep.on_security_encmode_changed = function() { 281 if (ep.dlg.encMode.val() == "enc") { 282 ep.dlg.enc.show(); 283 ep.dlg.noEnc.hide(); 284 } else { 285 ep.dlg.enc.hide(); 286 ep.dlg.noEnc.show(); 287 } 288} 289 290ep.on_security_writemode_changed = function() { 291 if(ep.dlg.writeMode.val().indexOf('password') == -1) { 292 ep.dlg.writePassword.hide(); 293 } else { 294 ep.dlg.writePassword.show(); 295 } 296} 297 298ep.on_security_readmode_changed = function() { 299 if(ep.dlg.readMode.val().indexOf('password') == -1) { 300 ep.dlg.readPassword.hide(); 301 } else { 302 ep.dlg.readPassword.show(); 303 } 304} 305 306ep.on_enable_password = function(txt) { 307 alert(txt); 308 ep.on_password(); 309} 310 311ep.on_enable = function() { 312 return ep.on_re_enable(false); 313} 314 315ep.aceShow = function() { 316 jQuery('img.ace-toggle[src*="off"]:visible').click(); 317} 318 319ep.aceHide = function() { 320 jQuery('img.ace-toggle[src*="on"]:visible').click(); 321} 322 323ep.aceIsEnabled = function() { 324 return (jQuery('img.ace-toggle[src*="on"]:visible').length > 0); 325} 326 327ep.cmShow = function() { 328 var $toggleLi = jQuery('.cm-settings-menu > li:last-child'); 329 if ($toggleLi.find('span.ui-icon-check').length == 0) {return;} 330 $toggleLi.find('a').click(); 331} 332 333ep.cmHide = function() { 334 var $toggleLi = jQuery('.cm-settings-menu > li:last-child'); 335 if ($toggleLi.find('span.ui-icon-check').length > 0) {return;} 336 $toggleLi.find('a').click(); 337} 338 339ep.cmIsEnabled = function() { 340 var $toggleLi = jQuery('.cm-settings-menu > li:last-child'); 341 return ($toggleLi.find('span.ui-icon-check').length == 0); 342} 343 344ep.on_re_enable = function(reopen) { 345 if (!reopen) { 346 /* disable ACE, cache it => text is in wiki__text, ace can be restored. */ 347 ep.aceWasEnabled = ep.aceIsEnabled(); 348 ep.cmWasEnabled = ep.cmIsEnabled(); 349 } 350 ep.aceHide(); 351 ep.cmHide(); 352 353 self.setTimeout(ep.on_re_enable_cont, 500); 354} 355 356ep.on_re_enable_cont = function() { 357 var text = ""; 358 if (ep.isSaveable) { 359 text = jQuery('#wiki__text').val(); 360 } 361 /* commit */ 362 jQuery.post( 363 DOKU_BASE + 'lib/exe/ajax.php', 364 { 'id' : ep.config["id"], "rev" : ep.config["rev"], "call" : "pad_open", "text" : text, 365 'sectok' : jQuery('input[name=sectok]').val(), 366 "isSaveable" : ep.isSaveable, "accessPassword" : ep.password }, 367 function(data) { 368 if (data.error) { 369 if (data.askPassword) { 370 ep.on_enable_password(data.error); 371 } else { 372 alert(data.error); 373 } 374 } else { 375 ep.isOwner = data.isOwner; 376 ep.opened = true; 377 document.cookie="sessionID="+data.sessionID+";domain="+data.domain+";path=/"; 378 jQuery('.pad-toggle').hide(); 379 jQuery('.pad-toggle-on').show(); 380 var htext = (ep.isOwner ? ep.lang.padowner : ep.lang.padnoowner); 381 htext = htext.replace(/%s/, ep.config["id"]); 382 htext = htext.replace(/%d/, ep.config["rev"]); 383 jQuery('.pad-toolbar span').html(htext); 384 385 h = screen.height - 500; 386 if (h < 300) { 387 h = 300; 388 } 389 if (jQuery('#wiki__text').length == 0) { 390 console.log("Missing Wiki Text Field"); 391 } 392 jQuery('#wiki__text').hide(); 393 jQuery(".pad-action-buttons").show(); 394 jQuery(".nopad-action-buttons").hide(); 395 jQuery('.ace-toggle:visible').addClass('ace-toggle-hidden').hide(); 396 jQuery('.pad-iframecontainer').empty(); 397 jQuery('<iframe/>').addClass("pad-iframe").attr("src",data.url).appendTo(jQuery('.pad-iframecontainer')); 398 jQuery('.pad-resizable').resizable(); 399 if (!ep.isSaveable) { // fix toolbar 400 jQuery('#wiki__text').removeAttr('readOnly'); 401 initToolbar('tool__bar','wiki__text',toolbar); 402 } 403 ep.security_fill(data); 404 if (ep.isOwner) { 405 ep.timer = window.setInterval(ep.refresh, 5 * 60 * 1000); 406 } 407 } 408 } 409 ); 410}; 411 412ep.sendMessage = function(func, data) { 413 if (ep.hasPadPlugin) { 414 var msg = new Object(); 415 msg.func = func; 416 msg.data = data; 417 jQuery('iframe.pad-iframe')[0].contentWindow.postMessage(msg, "*"); 418 } else { 419 alert(ep.lang.missingPlugin); 420 } 421} 422 423ep.proxyGetSelection = function(textArea) { 424 if (ep.opened) { 425 alert(ep.lang.noGetSelection); 426 } else { 427 return ep.getSelection.apply(self, [textArea]); 428 } 429}; 430 431ep.proxySetSelection = function(selection) { 432 if (ep.opened) { 433 alert(ep.lang.noSetSelection); 434 } else { 435 return ep.setSelection.apply(self, [selection]); 436 } 437} 438 439ep.proxyDWgetSelection = function(textArea) { 440 if (ep.opened) { 441 alert(ep.lang.noGetSelection); 442 } else { 443 return ep.DWgetSelection(textArea); 444 } 445}; 446 447ep.proxyDWsetSelection = function(selection) { 448 if (ep.opened) { 449 alert(ep.lang.noSetSelection); 450 } else { 451 return ep.DWsetSelection(selection); 452 } 453} 454 455ep.proxyPasteText = function (selection,text,opts) { 456 if (typeof(text) == 'undefined') return; 457 458 if (ep.opened) { 459 alert(ep.lang.noPasteText); 460 } else { 461 return ep.pasteText.apply(self,[selection,text,opts]); 462 } 463} 464 465ep.proxyInsertTags = function(textAreaID, tagOpen, tagClose, sampleText) { 466 if (ep.opened) { 467 ep.sendMessage('insertTags', {'tagOpen': tagOpen, 'tagClose' : tagClose, 'sampleText' : sampleText, 'trimSpaces' : false}); 468 } else { 469 return ep.insertTags.apply(this, [textAreaID, tagOpen, tagClose, sampleText]); 470 } 471} 472 473ep.proxyInsertAtCarret = function(textAreaID, text) { 474 if (ep.opened) { 475 ep.sendMessage('insert', {'text': text}); 476 } else { 477 return ep.insertAtCarret.apply(self, [textAreaID, text]); 478 } 479} 480 481// needed 482ep.proxyTbFormatLn = function(btn, props, edid) { 483 if (ep.opened) { 484 var sample = props.title || props.sample; 485 486 sample = fixtxt(sample); 487 props.open = fixtxt(props.open); 488 props.close = fixtxt(props.close); 489 490 ep.sendMessage('insertTagsLn', {'tagOpen': props.open, 'tagClose' : props.close, 'sampleText' : sample}); 491 492 pickerClose(); 493 return false; 494 } else { 495 return ep.tb_formatln.apply(self, [btn, props, edid]); 496 } 497} 498 499// needed 500ep.proxyInsertLink = function(title) { 501 if (ep.opened) { 502 var link = dw_linkwiz.$entry.val(); 503 if(!link) { 504 return; 505 } 506 if(dw_linkwiz.textArea.form.id.value.indexOf(':') != -1 && 507 link.indexOf(':') == -1){ 508 link = ':' + link; 509 } 510 ep.sendMessage('insertTags', {'tagOpen': '[['+link+'|', 'tagClose' : ']]', 'sampleText' : title, 'trimSpaces' : true}); 511 dw_linkwiz.hide(); 512 dw_linkwiz.$entry.val(dw_linkwiz.$entry.val().replace(/[^:]*$/, '')); 513 } else { 514 return ep.insertLink(title); 515 } 516} 517 518ep.onSave = function(event) { 519 event.preventDefault(); 520 event.stopPropagation(); 521 if (ep.opened) { 522 if (confirm("Das Pad muss zunächst geschlossen werden, bevor die Seite gespeichert werden kann.\nSoll das Pad geschlossen werden?")) { 523 ep.on_disable(event); 524 } 525 return false; 526 } else { 527 return jQuery('#edbtn__save').click(); 528 } 529} 530 531ep.onPreview = function(event) { 532 event.preventDefault(); 533 event.stopPropagation(); 534 if (ep.opened) { 535 alert(ep.lang.noPreview); 536 return false; 537 } else { 538 return jQuery('#edbtn__preview').click(); 539 } 540} 541 542ep.onCancel = function(event) { 543 event.preventDefault(); 544 event.stopPropagation(); 545 if (ep.opened) { 546 if (confirm("Das Pad muss zunächst geschlossen werden, bevor das Bearbeiten der Seite abgebrochen werden kann.\nSoll das Pad geschlossen werden?")) { 547 ep.on_disable(event); 548 } 549 return false; 550 } else { 551 return jQuery('#edbtn__cancel').click(); 552 } 553} 554 555/* init */ 556 557ep.initialize = function() { 558 ep.lang = LANG.plugins.etherpadlite; 559 ep.imgBase = ep.config["base"] + "/img/"; 560 ep.isSaveable = (ep.config["act"] != "locked"); 561 if (jQuery("#size__ctl").length == 0) { 562 console.log("Missing #size__ctl"); 563 } 564 jQuery("<img/>").addClass("pad-toggle pad-toggle-off").attr("src",ep.imgBase+"toggle_off.png").insertAfter(jQuery("#size__ctl")).click(ep.on_enable); 565 jQuery("<img/>").addClass("pad-toggle pad-toggle-on").attr("src",ep.imgBase+"toggle_on.png").insertAfter(jQuery("#size__ctl")).click(ep.on_disable); 566 jQuery("#edbtn__save").clone().attr('id','edbtn__save2').insertAfter('#edbtn__save').click(ep.onSave); 567 jQuery("#edbtn__save").addClass("nopad-action-buttons"); 568 jQuery("#edbtn__save2").addClass("pad-action-buttons"); 569 jQuery("#edbtn__save2").css("background-image", jQuery("#edbtn__save").css("background-image")); 570 jQuery("#edbtn__preview").clone().attr('id','edbtn__preview2').insertAfter('#edbtn__preview').click(ep.onPreview); 571 jQuery("#edbtn__preview").addClass("nopad-action-buttons"); 572 jQuery("#edbtn__preview2").addClass("pad-action-buttons"); 573 jQuery("#edbtn__preview2").css("background-image", jQuery("#edbtn__preview").css("background-image")); 574 jQuery('input.button[type="submit"][name="do[draftdel]"]').attr('id','edbtn__cancel'); 575 jQuery('#edbtn__cancel').clone().attr('id','edbtn__cancel2').insertAfter('#edbtn__cancel').click(ep.onCancel); 576 jQuery("#edbtn__cancel").addClass("nopad-action-buttons"); 577 jQuery("#edbtn__cancel2").addClass("pad-action-buttons"); 578 jQuery("#edbtn__cancel2").css("background-image", jQuery("#edbtn__cancel").css("background-image")); 579 jQuery('.pad-toggle').hide(); 580 jQuery('.pad-toggle-off').show(); 581 jQuery('<div/>').addClass("pad-iframecontainer pad-action-buttons pad-resizable").insertAfter(jQuery('#wiki__text')); 582 jQuery('<div/>').addClass("pad-toolbar pad-action-buttons").insertAfter(jQuery('.toolbar')); 583 jQuery("<span/>").appendTo(jQuery(".pad-toolbar")); 584 jQuery("<img/>").addClass("pad-close").attr("src",ep.imgBase+"close.png").appendTo(jQuery(".pad-toolbar")).click(ep.on_disable); 585 jQuery("<img/>").addClass("pad-security").attr("src",ep.imgBase+"nolock.png").appendTo(jQuery(".pad-toolbar")).click(ep.on_security); 586 jQuery("<img/>").addClass("pad-saveable").attr("src",ep.imgBase+"no-saveable.png").appendTo(jQuery(".pad-toolbar")).click(ep.on_password_click); 587 jQuery(".pad-action-buttons").hide(); 588 ep.init_security(); 589 ep.init_password(); 590 // check if pad exists -> open it 591 if (ep.config["rev"] !== false && ep.config["rev"] > 0) { 592 jQuery.post( 593 DOKU_BASE + 'lib/exe/ajax.php', 594 { 'id' : ep.config["id"], "rev" : ep.config["rev"], "call" : "has_pad", 595 "isSaveable" : ep.isSaveable, "accessPassword" : ep.password }, 596 function(data) { 597 if (data.error) { 598 alert(data.error); 599 } else if (data.exists) { 600 console.log("auto-start pad"); 601 ep.on_enable(); 602 } 603 } 604 ); 605 } 606}; 607 608ep.iframeinsertReceiveMessage = function(event) { 609 if (typeof(event.data) != 'object') { 610 return; 611 } 612 var data = event.data; 613 if (data.func == 'none' && data.context == 'ep_iframeinsert') { 614 ep.hasPadPlugin = true; 615 if (ep.opened) { 616 jQuery('#wiki__text').val(data.text); 617 self.textChanged = true; 618 } 619 event.preventDefault(); 620 event.stopPropagation(); 621 } 622} 623 624 625window.addEventListener('DOMContentLoaded', (event) => { 626 /* textselection / toolbar wrapper */ 627 ep.setSelection = self.setSelection; 628 ep.getSelection = self.getSelection; 629 ep.DWsetSelection = self.DWsetSelection; 630 ep.DWgetSelection = self.DWgetSelection; 631 ep.pasteText = self.pasteText; 632 ep.insertTags = self.insertTags; 633 ep.insertAtCarret = self.insertAtCarret; 634 ep.tb_formatln = self.tb_formatln; 635 ep.insertLink = dw_linkwiz.insertLink; 636 637 self.getSelection = ep.proxyGetSelection; 638 self.setSelection = ep.proxySetSelection; 639 self.DWgetSelection = ep.proxyDWgetSelection; 640 self.DWsetSelection = ep.proxyDWsetSelection; 641 self.pasteText = ep.proxyPasteText; 642 self.insertTags = ep.proxyInsertTags; 643 self.insertAtCarret = ep.proxyInsertAtCarret; 644 self.tb_formatln = ep.proxyTbFormatLn; 645 dw_linkwiz.insertLink = ep.proxyInsertLink; 646 647 self.setTimeout(ep.initialize, 500); 648 649 window.addEventListener("message", ep.iframeinsertReceiveMessage, false); 650}); 651 652