/** * Copyright (c) 2014-2016, CKSource - Frederico Knabben. All rights reserved. * Licensed under the terms of the MIT License (see LICENSE.md). * * The abbr plugin dialog window definition. * * Created out of the CKEditor Plugin SDK: * http://docs.ckeditor.com/#!/guide/plugin_sdk_sample_1 */ // Our dialog definition. CKEDITOR.dialog.add( 'geshiDialog', function( editor ) { var radio, ckg_geshi_langopts = new Array(); var href, id,geshi_dialog, t_display,s_display; var getHref = function() { var data = window.location.pathname; var qs = window.location.search; var matches = data.match(/\/(.*?)\/(doku.php)?\/?(.*)/); if(qs_match = qs.match(/id=([\w:_\.]+)\b/)) { //none id = qs_match[1]; href = matches[0]; } else if(!matches[2]) { id = matches[3]; href = matches[1] + '/doku.php'; } else { id = matches[3]; href = matches[2] + '/doku.php'; } if(!href) href='doku.php'; if(!id) id = 'start'; return {'href':href, 'id':id}; }; var downloadable_header = function(type,fname) { var id = 'start'; var file = fname ? fname: 'temp.' + type; var href_vals = getHref(); return '
' +'
' +file +'
';
 };
 
    var downloadable_footer = function() {   
    return "
"; } ckg_geshi_langopts = editor.config.geshi_opts; if(!ckg_geshi_langopts.match(/ENotfound/)) { ckg_geshi_langopts = ckg_geshi_langopts.split(';;'); var tmp; for(var i=0; i" + editor.lang.geshi.quick_srch+"", //editor.lang.geshi.lang || 'Programming Language', width: '125px', onChange: function( api ) { var srch = this.getValue().toLowerCase(); srch = srch.escapeRegExpCkg(srch); var regex = new RegExp('^' +srch); for(var i = 1; i< ckg_geshi_langopts.length; i++) { if(regex.test(ckg_geshi_langopts[i])) { srch=ckg_geshi_langopts[i]; break; } } if(srch) geshi_dialog.getContentElement( 'tab-basic', 'ckg_geshi_lang' ).setValue(srch); } }, { type: 'text', id: 'file', label: editor.lang.geshi.file || 'File name', width: '175px', }, { type: 'radio', id: 'which', label: editor.lang.geshi.which, items: [ [ editor.lang.geshi.codeblock, 'block' ], [ editor.lang.geshi.snippet, 'snippet' ] ], 'default': 'block', style: 'color: green', onClick: function() { radio = this.getValue(); } }, ] //hbox children }, //hbox ] //elements }, //contents ], //contents onShow : function() { var dialog = this; geshi_dialog = dialog; selection = editor.getSelection(); var text = selection.getSelectedText(); dialog.getContentElement( 'tab-basic', 'geshi' ).setValue( text ); String.prototype.escapeRegExpCkg = function(str) { return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string }; // dialog.getContentElement( 'tab-basic', 'language' ).style='display:block'; // alert( 'Current value: ' + dialog.getValueOf( 'tab-basic', 'ckg_geshi_lang' ) ); }, onOk: function() { // The context of this function is the dialog object itself. // http://docs.ckeditor.com/#!/api/CKEDITOR.dialog var dialog = this, retval; var text = dialog.getValueOf( 'tab-basic', 'geshi' ); var which = dialog.getValueOf( 'tab-basic', 'which' ); var p_lang = dialog.getValueOf( 'tab-basic', 'ckg_geshi_lang' ); if(p_lang.match(/Not Set/i)) { p_lang = ""; } if(!p_lang) { if(confirm('Language not found. Try again?')) { return false; } } if(p_lang) { if(which == 'block') { retval = '
' + text + '
'; } else retval = downloadable_header(p_lang,dialog.getValueOf( 'tab-basic', 'file' ) ) + text + downloadable_footer(); editor.insertHtml(retval); } } }; });