Changeset 2015762
- Timestamp:
- 01/20/2019 01:02:21 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
aph-prism-highlighter/tags/1.3/js/aphph-admin-editor.js
r1473175 r2015762 1 1 (function($) { 2 $(document).ready(function(){ 2 $(document).ready(function() 3 { 3 4 var textarea = document.getElementById('aphph-editor-code'); 4 5 tabOverride.set(textarea); … … 24 25 } 25 26 }) 26 QTags.addButton( 'aphph_quicktag', 'APH Prism', function(btn, textarea, ed) 27 { 28 var $textarea = $(ed.canvas), 29 text = $textarea.val(), 30 selStart = ed.canvas.selectionStart, 31 selEnd = ed.canvas.selectionEnd, 32 selection = ''; 33 34 if (selEnd - selStart) 35 selection = text.substr(selStart, selEnd - selStart); 36 37 $('#aphph-editor-overlay').show(); 38 $('#aphph-editor-wrap').show(); 39 $('#aphph-editor-code').val(selection); 40 41 // Set defaut value 42 $('#aphsh-overr-showln').removeAttr('checked'); 43 $('#aphsh-opt-showln').val('false'); 44 $('#aphsh-start-number').val(''); 45 $('#aphph-highlight-lines').val(''); 46 $('#aphsh-input-class-name').val(''); 47 48 // Click submit button 49 $('#aphph-submit').click(function() 27 28 29 if (typeof QTags !== 'undefined') { 30 QTags.addButton( 'aphph_quicktag', 'APH Prism', function(btn, textarea, ed) 50 31 { 51 // Lang 52 var new_language = 'lang:' + $('#aphph-language').val(), 32 var $textarea = $(ed.canvas), 33 text = $textarea.val(), 34 selStart = ed.canvas.selectionStart, 35 selEnd = ed.canvas.selectionEnd, 36 selection = ''; 53 37 54 // gutter:true 55 override_line_number = $('#aphph-overr-showln').is(':checked'), 56 class_line_number = ''; 38 if (selEnd - selStart) 39 selection = text.substr(selStart, selEnd - selStart); 40 41 $('#aphph-editor-overlay').show(); 42 $('#aphph-editor-wrap').show(); 43 $('#aphph-editor-code').val(selection); 44 45 // Set defaut value 46 $('#aphsh-overr-showln').removeAttr('checked'); 47 $('#aphsh-opt-showln').val('false'); 48 $('#aphsh-start-number').val(''); 49 $('#aphph-highlight-lines').val(''); 50 $('#aphsh-input-class-name').val(''); 51 52 // Click submit button 53 $('#aphph-submit').click(function() 54 { 55 // Lang 56 var new_language = 'lang:' + $('#aphph-language').val(), 57 57 58 if (override_line_number) { 58 // gutter:true 59 override_line_number = $('#aphph-overr-showln').is(':checked'), 60 class_line_number = ''; 61 62 if (override_line_number) { 63 64 var start_number = $.trim($('#aphph-start-number').val()) || 1, 65 show_line_number = $.trim($('#aphph-opt-showln').val()), 66 data_start_number = show_line_number == 'true' ? ' start:' + start_number : '', 67 class_line_number = ' gutter:' + show_line_number + data_start_number; 68 } 59 69 60 var start_number = $.trim($('#aphph-start-number').val()) || 1, 61 show_line_number = $.trim($('#aphph-opt-showln').val()), 62 data_start_number = show_line_number == 'true' ? ' start:' + start_number : '', 63 class_line_number = ' gutter:' + show_line_number + data_start_number; 64 } 70 // class-name 71 var input_class_name = $.trim($('#aphph-input-class-name').val()), 72 add_class_name = input_class_name ? ' class:' + input_class_name : ''; 73 74 // html-script:true 75 html_script = $('#aphph-html-script').val() == 'true' ? ' html-script:true' : '', 76 77 // highlight:true 78 highlight_line = $.trim($('#aphph-highlight-lines').val()), 79 data_highlight_line = highlight_line ? ' mark:' + highlight_line : '', 80 81 // Encode TAG 82 $div = $('<div/>'), 83 clean_code = $.trim($('#aphph-editor-code').val()), 84 encoded_html = $div.text(clean_code).html(), 85 $div.remove(), 86 87 // Title 88 title = $('#aphph-title').val(), 89 90 attr_title = title ? ' title="' + title + '"' : ''; 91 92 // Class name 93 class_name = new_language + data_highlight_line + html_script + class_line_number + add_class_name; 94 95 var textBefore = text.substr(0, selStart), 96 textAfter = text.substr(selStart + selection.length, text.length - selStart), 97 content = '<pre class="' + class_name + '"' + attr_title + '>' + encoded_html + '</pre>'; 98 99 100 $textarea.val(textBefore + content + textAfter); 65 101 66 // class-name 67 var input_class_name = $.trim($('#aphph-input-class-name').val()), 68 add_class_name = input_class_name ? ' class:' + input_class_name : ''; 69 70 // html-script:true 71 html_script = $('#aphph-html-script').val() == 'true' ? ' html-script:true' : '', 102 // QTags.insertContent(); 103 $('#aphph-editor-overlay').hide(); 104 $('#aphph-editor-wrap').hide(); 105 if (!$('#aphph-other-options-container').is(':hidden')) 106 { 107 $('#aphph-other-options').trigger('click'); 108 } 72 109 73 // highlight:true 74 highlight_line = $.trim($('#aphph-highlight-lines').val()), 75 data_highlight_line = highlight_line ? ' mark:' + highlight_line : '', 76 77 // Encode TAG 78 $div = $('<div/>'), 79 clean_code = $.trim($('#aphph-editor-code').val()), 80 encoded_html = $div.text(clean_code).html(), 81 $div.remove(), 82 83 // Title 84 title = $('#aphph-title').val(), 85 86 attr_title = title ? ' title="' + title + '"' : ''; 87 88 // Class name 89 class_name = new_language + data_highlight_line + html_script + class_line_number + add_class_name; 90 91 var textBefore = text.substr(0, selStart), 92 textAfter = text.substr(selStart + selection.length, text.length - selStart), 93 content = '<pre class="' + class_name + '"' + attr_title + '>' + encoded_html + '</pre>'; 94 95 96 $textarea.val(textBefore + content + textAfter); 97 98 // QTags.insertContent(); 99 $('#aphph-editor-overlay').hide(); 100 $('#aphph-editor-wrap').hide(); 101 if (!$('#aphph-other-options-container').is(':hidden')) 102 { 103 $('#aphph-other-options').trigger('click'); 104 } 105 110 }); 106 111 }); 107 } );112 } 108 113 }); 109 114 })(jQuery);
Note: See TracChangeset
for help on using the changeset viewer.