This repository has been archived by the owner on Feb 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
364 additions
and
462 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,104 +1,101 @@ | ||
(function (window, $) { | ||
'use strict'; | ||
'use strict'; | ||
|
||
/** | ||
* Custom Trim function | ||
* @returns {string} | ||
*/ | ||
String.prototype.trim = function () { | ||
return this.replace(/^\s+|\s+$/g, ''); | ||
}; | ||
function trim(str) { | ||
return str.replace(/^\s+|\s+$/g, ''); | ||
} | ||
|
||
/** | ||
* Get language list from inline script | ||
*/ | ||
var langs = []; | ||
if (typeof window.prismLangs !== 'undefined') { | ||
langs = window.prismLangs; | ||
} | ||
tinymce.PluginManager.add('prism_assist_button', function (editor, url) { | ||
editor.addButton('prism_assist_button', { | ||
title: 'Prism Assistant', | ||
text: 'Prism', | ||
type: false, | ||
icon: 'apfw-icon', | ||
onclick: function () { | ||
editor.windowManager.open({ | ||
title: 'Prism Syntax Highlighter Assistant', | ||
width: 550, | ||
height: 450, | ||
body: [ | ||
{ | ||
type: 'listbox', | ||
name: 'language', | ||
label: 'Language* :', | ||
values: langs, | ||
value: langs[0].value | ||
}, | ||
{ | ||
type: 'checkbox', | ||
name: 'lineNumbers', | ||
label: 'Show line numbers:', | ||
checked: true | ||
}, | ||
{ | ||
type: 'textbox', | ||
name: 'lineNumStart', | ||
label: 'Start line number from:' | ||
}, | ||
{ | ||
type: 'textbox', | ||
name: 'highLight', | ||
label: 'Lines to highlight:' | ||
}, | ||
{ | ||
type: 'textbox', | ||
name: 'code', | ||
label: 'Paste code*:', | ||
multiline: true, | ||
minHeight: 250, | ||
value: '', | ||
onclick: function (e) { | ||
$(e.target).css('border-color', ''); | ||
} | ||
}, | ||
{ | ||
type: 'label', | ||
name: 'info', | ||
label: 'Note:', | ||
text: 'These options works only if enabled on Plugin Option Page.', | ||
style: 'font-size:smaller' | ||
} | ||
], | ||
onsubmit: function (e) { | ||
var lineNum = '', | ||
lineNumStart = '', | ||
highlight = '', | ||
code = e.data.code.trim(); | ||
/** | ||
* Get language list from inline script | ||
*/ | ||
var langs = []; | ||
if (typeof window.prismLangs !== 'undefined') { | ||
langs = window.prismLangs; | ||
} | ||
|
||
// Code is required | ||
if (code === '') { | ||
var windowId = this._id; | ||
var inputs = $('#' + windowId + '-body').find('.mce-formitem textarea'); | ||
$(inputs.get(0)).css('border-color', 'red').focus(); | ||
return false; | ||
} | ||
if (e.data.lineNumbers) { | ||
lineNum = ' class="line-numbers" '; | ||
} | ||
if (e.data.lineNumStart && e.data.lineNumbers) { | ||
lineNumStart = ' data-start="' + e.data.lineNumStart + '" '; | ||
} | ||
if (e.data.highLight) { | ||
highlight = ' data-line="' + e.data.highLight + '" '; | ||
tinymce.PluginManager.add('prism_assist_button', function (editor, url) { | ||
editor.addButton('prism_assist_button', { | ||
title: 'Prism Assistant', | ||
text: 'Prism', | ||
type: false, | ||
icon: 'apfw-icon', | ||
onclick: function () { | ||
editor.windowManager.open({ | ||
title: 'Prism Syntax Highlighter Assistant', | ||
width: 550, | ||
height: 450, | ||
body: [ | ||
{ | ||
type: 'listbox', | ||
name: 'language', | ||
label: 'Language* :', | ||
values: langs, | ||
value: langs[0].value | ||
}, | ||
{ | ||
type: 'checkbox', | ||
name: 'lineNumbers', | ||
label: 'Show line numbers:', | ||
checked: true | ||
}, | ||
{ | ||
type: 'textbox', | ||
name: 'lineNumStart', | ||
label: 'Start line number from:' | ||
}, | ||
{ | ||
type: 'textbox', | ||
name: 'highLight', | ||
label: 'Lines to highlight:' | ||
}, | ||
{ | ||
type: 'textbox', | ||
name: 'code', | ||
label: 'Paste code*:', | ||
multiline: true, | ||
minHeight: 250, | ||
value: '', | ||
onclick: function (e) { | ||
$(e.target).css('border-color', ''); | ||
} | ||
}, | ||
{ | ||
type: 'label', | ||
name: 'info', | ||
label: 'Note:', | ||
text: 'These options works only if enabled on Plugin Option Page.', | ||
style: 'font-size:smaller' | ||
} | ||
], | ||
onsubmit: function (e) { | ||
var lineNum = '', | ||
lineNumStart = '', | ||
highlight = '', | ||
code = trim(e.data.code); | ||
|
||
// Code is required | ||
if (code === '') { | ||
var windowId = this._id; | ||
var inputs = $('#' + windowId + '-body').find('.mce-formitem textarea'); | ||
$(inputs.get(0)).css('border-color', 'red').focus(); | ||
return false; | ||
} | ||
if (e.data.lineNumbers) { | ||
lineNum = ' class="line-numbers" '; | ||
} | ||
if (e.data.lineNumStart && e.data.lineNumbers) { | ||
lineNumStart = ' data-start="' + e.data.lineNumStart + '" '; | ||
} | ||
if (e.data.highLight) { | ||
highlight = ' data-line="' + e.data.highLight + '" '; | ||
} | ||
var language = e.data.language; | ||
// HTML entities encode | ||
code = code.replace(/</g, '<').replace(/>/g, '>'); | ||
editor.insertContent('<pre' + highlight + lineNum + lineNumStart + '><code class="language-' + language + '">' + code + '</code></pre>'); | ||
} | ||
}); | ||
} | ||
var language = e.data.language; | ||
// HTML entities encode | ||
code = code.replace(/</g, '<').replace(/>/g, '>'); | ||
editor.insertContent('<pre' + highlight + lineNum + lineNumStart + '><code class="language-' + language + '">' + code + '</code></pre>'); | ||
} | ||
}); | ||
} | ||
}); | ||
}); | ||
})(window, jQuery); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,26 @@ | ||
(function ($) { | ||
'use strict'; | ||
/** | ||
* Determines if element has given attribute | ||
* @param name | ||
* @returns {boolean} | ||
*/ | ||
$.fn.hasAttr = function (name) { | ||
return this.attr(name) !== undefined; | ||
}; | ||
'use strict'; | ||
|
||
var $checkboxContainer = $("#plang-list"); | ||
var $checkboxes = $checkboxContainer.find('input:checkbox'); | ||
$.fn.hasAttr = function (name) { | ||
return this.attr(name) !== undefined; | ||
}; | ||
|
||
$checkboxes.on('change', function (e) { | ||
if (!$(this).is(":checked")) { | ||
var thisId = $(this).attr('id'); | ||
$($checkboxes).each(function () { | ||
if ($(this).hasAttr('data-require')) { | ||
if ('plang-' + $(this).attr('data-require') === thisId) { | ||
$(this).prop('checked', false).trigger('change'); | ||
} | ||
var $checkboxContainer = $("#plang-list"); | ||
var $checkboxes = $checkboxContainer.find('input:checkbox'); | ||
|
||
$checkboxes.on('change', function (e) { | ||
if (!$(this).is(":checked")) { | ||
var thisId = $(this).attr('id'); | ||
$($checkboxes).each(function () { | ||
if ($(this).hasAttr('data-require')) { | ||
if ('plang-' + $(this).attr('data-require') === thisId) { | ||
$(this).prop('checked', false).trigger('change'); | ||
} | ||
} | ||
}); | ||
} | ||
if ($(this).hasAttr('data-require') && $(this).is(":checked")) { | ||
$checkboxContainer.find("#plang-" + $(this).attr('data-require')).prop('checked', true).trigger('change'); | ||
} | ||
}); | ||
} | ||
if ($(this).hasAttr('data-require') && $(this).is(":checked")) { | ||
$checkboxContainer.find("#plang-" + $(this).attr('data-require')).prop('checked', true).trigger('change'); | ||
} | ||
}); | ||
}); | ||
})(jQuery); |
Oops, something went wrong.