/** * 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' ], [ editor.lang.geshi.plain_text, 'text' ]], 'default': 'block', style: 'color: green', onClick: function() { radio = this.getValue(); } }, ] //hbox children }, //hbox { type: 'hbox', widths: [ '60%','40%'], children: [ { type: 'radio', id: 'numbers', label: editor.lang.geshi.numbers_header||'For syntax numbering, select type', items: [ [ editor.lang.geshi.nonumbers, 'nonumbers' ], [ editor.lang.geshi.numonly, 'numonly' ], [ editor.lang.geshi.startat, 'startat' ], [ editor.lang.geshi.xtra, 'xtra' ]], 'default': 'nonumbers', style: 'color: green', onClick: function() { radio = this.getValue(); } }, { type: 'text', id: 'linenums', label: editor.lang.geshi.linenums ||'Line number or numbers: line n or n1,n2..', width: '175px', }, ] },//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' ); text = text.replace(//gm,'>'); var which = dialog.getValueOf( 'tab-basic', 'which' ); var highlight = dialog.getValueOf( 'tab-basic', 'numbers' ); var hiliting = '/*[enable_line_numbers="true"'; if(highlight != 'nonumbers') {//'numonly' if(highlight == 'numonly'){ text = "\n" + hiliting +']' +"*/\n" + text; } else if(highlight == 'startat'){ var num = dialog.getValueOf( 'tab-basic', 'linenums' ); text = "\n" + hiliting + ', start_line_numbers_at="'+num +'"]' +"*/\n" + text; } else { //hilite individual lines var num = dialog.getValueOf( 'tab-basic', 'linenums' ); text = "\n" + hiliting + ', highlight_lines_extra="'+num +'"]' +"*/\n" + text; } } var p_lang = dialog.getValueOf( 'tab-basic', 'ckg_geshi_lang' ); if(p_lang.match(/Not Set/i)) { if(which == 'text') { p_lang = 'text'; } else p_lang = ""; } if(!p_lang) { if(confirm('Language not found. Try again?')) { return false; } } if(p_lang) { if(p_lang == 'text') { text = text.replace(/^(.*?)\n$/gm,"

$1

"); retval = text; } else if(which == 'block') { retval = '
' + text + '
'; } else retval = downloadable_header(p_lang,dialog.getValueOf( 'tab-basic', 'file' ) ) + text + downloadable_footer(); editor.insertHtml(retval); } } }; });