Skip to content
This repository has been archived by the owner on Feb 20, 2021. It is now read-only.

Commit

Permalink
A few last cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
ankurk91 committed Feb 20, 2021
1 parent f1967ab commit 94cb35a
Show file tree
Hide file tree
Showing 11 changed files with 364 additions and 462 deletions.
20 changes: 2 additions & 18 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
# https://github.com/github/gitignore
# http://git-scm.com/docs/gitignore

# phpstorm, webstorm
# IDEs
.idea/


# sublime and other ide
.project
*.sublime-project
*.sublime-workspace
.brackets.json
.tmproj
.vscode.

# logs and cache
/logs/
Expand Down Expand Up @@ -40,15 +30,9 @@ $RECYCLE.BIN/
*.DS_Store
.DS_Store?


# node packages
# https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git
node_modules/


# bower packages
bower_components/

# svn folders
.svn/

Expand Down
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT LICENSE

Copyright (c) 2017 Ankur
Copyright (c) Ankur

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
189 changes: 93 additions & 96 deletions assets/editor-plugin.js
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, '&lt;').replace(/>/g, '&gt;');
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, '&lt;').replace(/>/g, '&gt;');
editor.insertContent('<pre' + highlight + lineNum + lineNumStart + '><code class="language-' + language + '">' + code + '</code></pre>');
}
});
}
});
});
})(window, jQuery);
46 changes: 21 additions & 25 deletions assets/options-page.js
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);
Loading

0 comments on commit 94cb35a

Please sign in to comment.