This commit is contained in:
root
2019-08-30 19:30:19 +02:00
commit 6f2b105ca0
595 changed files with 78405 additions and 0 deletions

1
js/jquery-colorpicker/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.svn

View File

@ -0,0 +1,231 @@
jQuery.colorpicker v0.9.3
Copyright (c) 2011-2012 Martijn W. van der Lee
Licensed under the MIT.
Full-featured colorpicker for jQueryUI with full theming support.
Most images from jPicker by Christopher T. Tillman.
Sourcecode created from scratch by Martijn W. van der Lee.
IE support; make sure you have a doctype defined, or the colorpicker will not
display correctly.
Options:
alpha: false
Whether or not to show the inputs for alpha.
altAlpha: true
Change the opacity of the altField element(s) according to the alpha
setting.
altField: ''
Change the background color of the elements specified in this element.
altOnChange: true
If true, the altField element(s) are updated on every change, otherwise
only upon closing.
altProperties: 'background-color'
Comma-separated list of CSS properties to set color of in the altField.
The following properties are allowed, all others are ignored.
background-color
color
border-color
outline-color
autoOpen: false
If true, the dialog opens automatically upon page load.
buttonColorize: false
If a buttonimage is specified, change the background color of the
image when the color is changed.
buttonImage: 'images/ui-colorpicker.png'
Same as jQueryUI DatePicker.
buttonImageOnly: false
Same as jQueryUI DatePicker.
buttonText: null
Same as jQueryUI DatePicker. If null, use language default.
closeOnEscape: true
Close the window when pressing the Escape key on the keyboard.
closeOnOutside: true
Close the window when clicking outside the colorpicker display.
color: '#00FF00'
Initial color. Formats recognized are:
#rrggbb
rrggbb (same as previous, but without the #)
rgb(rrr,ggg,bbb)
rgba(rrr,ggg,bbb,a.a)
rgb(rrr%,ggg%,bbb%)
rgba(rrr%,ggg%,bbb%,aaa%)
w3c-defined color name
colorFormat: 'HEX'
Specifies the format of the color string returned in callbacks.
You can either specify one of the predefined formats:
#HEX #112233
#HEX3 #123 if possible, otherwise false.
HEX 112233
HEX3 123 if possible, otherwise false.
RGB rgb(123,45,67) if opaque, otherwise false.
RGBA rgba(123,45,67,0.123%)
RGB% rgb(12%,34%,56%) if opaque, otherwise false.
RGBA% rgba(12%,34%,56%,0.123%)
HSL hsl(123,45,67) if opaque, otherwise false.
HSLA hsla(123,45,67,0.123%)
HSL% hsl(12%,34%,56%) if opaque, otherwise false.
HSLA% hsla(12%,34%,56%,0.123%)
NAME Closest color name
EXACT Exact name if possible, otherwise false.
or specify your own format...
Each color channel is specified as a pair of two characters.
The first character determines the color channel:
a Alpha
r, g, b RGB color space; red, green and blue
h, s, v HSV color space; hue, saturation and value
c, m, y, k CMYK color space; cyan, magenta, yellow and black
L, A, B LAB color space; Luminosity, *A and *B.
The second character specifies the data type:
x Two-digit hexadecimal notation.
d Decimal (0-255) notation.
f Floating point (0-1) notation, not rounded.
p Percentage (0-100) notation, not rounded.
If you prefix a valid pair with a backslash, it won't be replaced.
All patterns are case sensitive.
For example, to create the common hex color format, use "#rxgxbx".
For an rgba() format, use "rgba(rd,gd,bd,af)"
You can also specify an array of formats where the first non-FALSE one
is returned. Note that the only formats able to return FALSE are the
predefined formats HEX3 and EXACT. For example, this array will output
HEX3 format if possible or HEX format otherwise:
['HEX3', 'HEX']
dragggable: true
Make the dialog draggable if the header is visible and the dialog is
not inline.
duration: 'fast'
Same as jQueryUI DatePicker.
hsv: true
Whether or not to show the inputs for HSV.
layout: { ... }
Set the position of elements in a table layout.
You could create any layout possible with HTML tables by specifying
cell position and size of each part.
@todo document how this works.
limit: ''
Limit the selectable colors to any of the predefined limits:
'' No limitations, allow 8bpp color for a palette of
all 16 million colors.
'websafe' Set of 216 colors composed of 00, 33, 66, 99, cc
and ff color channel values in #rrggbb.
'nibble' 4 bits per color, can be easily converted to #rgb
format.
The palette is limited to 4096 colors.
'binary' Allow only #00 or #ff as color channel values for
primary colors only; only 8 colors are available
with this limit.
'name' Limit to closest color name.
modal:
Ensures no other controls on screen can be used while the dialog is
opened.
Also look at showCancelButton and closeOnEscape to use in combination
with the modal option. closeOnOutside is redundant when used with modal.
mode: 'h'
Determines the functionality of the map and bar components. Allowed
values are; 'h', 's', 'l', 'r', 'g', 'b' or 'a', for hue, saturation,
luminosity, red, green, blue and alpha respectively.
parts: ''
Determine which parts to display.
Use any of the preset names ('full', 'popup' or 'inline') or specify
an array of part names (i.e. ['header', 'map', 'bar', 'hex', 'hsv',
'rgb', 'alpha', 'lab', 'cmyk', 'preview', 'swatches', 'footer']).
If an empty string is given, the parts will be automatically chosen as
preset 'popup' or 'inline' depending on the context in which the
colorpicker is used.
rgb: true, // Show RGB controls and modes
Whether or not to show the inputs for RGB.
regional: '',
Sets the language to use. Note that you must load the appropriate
language file from the i18n directory. '' is included by default.
showAnim: 'fadeIn'
Same as jQueryUI DatePicker.
showCancelButton: true
Show the Cancel button if buttonpane is visible.
showCloseButton: true
Show the Close button if the header is visible.
If the dialog is inline, the close button is never shown.
showNoneButton: false
Show the None/Revert button if buttonpane is visible.
showOn: 'focus'
Same as jQueryUI DatePicker.
showOptions: {}
Same as jQueryUI DatePicker.
swatches: null
'null' to show swatches of HTML colors or provide your own object
with colornames and {r:1, g:1, b:1} array.
For example { 'red': {r:1, g:0, b:0}, 'blue': {r:0, g:0, b:1} }
title: null
Title to display in the header. If null, use language default.
Events:
init: null
Triggered on initially setting the color. Called only once.
Callbacks recieve same data as select event.
close: null
Triggered when the popup is closed.
Callbacks recieve same data as select event and an additional number
of fields containing the current color in all supported color spaces.
These are rgb{}, hsv{}, cmyk{}, lab{}, hsl{} and a.
Most values are floating point numbers in range [0,1] for accuracy.
The a and b values in the lab color space have range [-1,1].
select: null
Triggered on each change, confirmation (click on OK button) and
cancellation (click on Cancel, outside window or window close button)
respectively.
The event recieves a jQuery event object and a data object containing
the elements 'formatted' (with the color formatted according to
formatColor).
Note that select may be triggered in rapid succession when dragging
the mouse accross the map or bar and may be triggered without a change
in color upon specific user interactions.
Methods:
open
Open the dialog
close
Close the dialog
destroy
Destroy the widget
setColor
Set the current color to the specified color. Accepts any
CSS-confirmant color specification.

View File

@ -0,0 +1,20 @@
Fix the weird one-pixel vertical shift bug.
Caused by ui-widget class.
Only happens in Chrome and only on some, not all.
Disappears and re-appears at different zoom levels.
In hex input, accept (and strip) '#' symbol on copy/past.
Completely destroy object when closed.
Enabled/disabled
isRTL? What to RTL, besides button?
Disable selection in MSIE: this.dialog.on('selectstart', function(event) { return false; })
Special rendering mode for color_none? Use [X] images?
Fix parsing from input with websafe colors
Recognize "transparent" color name.
Limit number of events triggered.
Small size variant (128x128)
isRTL? What to RTL, besides button?
Undo/redo memory?
ARIA support.
Allow only set (dec/hex) characters in inputs
Most-recently-used swatches
HSL/HSV distance calculations should take into account cyclic hue.

View File

@ -0,0 +1,27 @@
jQuery(function($) {
$.colorpicker.regional['en'] = {
ok: 'OK',
cancel: 'Cancel',
none: 'None',
button: 'Color',
title: 'Pick a color',
transparent: 'Transparent',
hsvH: 'H',
hsvS: 'S',
hsvV: 'V',
rgbR: 'R',
rgbG: 'G',
rgbB: 'B',
labL: 'L',
labA: 'a',
labB: 'b',
hslH: 'H',
hslS: 'S',
hslL: 'L',
cmykC: 'C',
cmykM: 'M',
cmykY: 'Y',
cmykK: 'K',
alphaA: 'A'
};
});

View File

@ -0,0 +1,27 @@
jQuery(function($) {
$.colorpicker.regional['fr'] = {
ok: 'OK',
cancel: 'Annuler',
none: 'Aucune couleur',
button: 'Couleur',
title: 'Choisir une couleur',
transparent: 'Transparent',
hsvH: 'T',
hsvS: 'S',
hsvV: 'V',
rgbR: 'R',
rgbG: 'V',
rgbB: 'B',
labL: 'L',
labA: 'a',
labB: 'b',
hslH: 'T',
hslS: 'S',
hslL: 'L',
cmykC: 'C',
cmykM: 'M',
cmykY: 'J',
cmykK: 'N',
alphaA: 'A'
};
});

View File

@ -0,0 +1,27 @@
jQuery(function($) {
$.colorpicker.regional['nl'] = {
ok: 'OK',
cancel: 'Annuleren',
none: 'Geen',
button: 'Kleur',
title: 'Kies een kleur',
transparent: 'Transparant',
hsvH: 'H',
hsvS: 'S',
hsvV: 'V',
rgbR: 'R',
rgbG: 'G',
rgbB: 'B',
labL: 'L',
labA: 'a',
labB: 'b',
hslH: 'H',
hslS: 'S',
hslL: 'L',
cmykC: 'C',
cmykM: 'M',
cmykY: 'Y',
cmykK: 'K',
alphaA: 'A'
};
});

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 134 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 198 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 382 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 139 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 344 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 135 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 494 B

View File

@ -0,0 +1,210 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>jQuery Colorpicker</title>
<!-- jQuery/jQueryUI (hosted) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.js"></script>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/ui-lightness/jquery-ui.css" rel="stylesheet" type="text/css"/>
<style>
body {
font-family: 'Segoe UI', Verdana, Arial, Helvetica, sans-serif;
font-size: 62.5%;
}
</style>
<script src="jquery.colorpicker.js"></script>
<link href="jquery.colorpicker.css" rel="stylesheet" type="text/css"/>
<script src="i18n/jquery.ui.colorpicker-nl.js"></script>
</head>
<body>
<h1>jQuery ColorPicker</h1>
<hr/>
Basic &lt;input&gt; example, without any options: <input type="text" class="cp-basic" value="fe9810"/>
<hr/>
Basic &lt;div&gt; example, without any options: <span class="cp-basic" style="display: inline-block; vertical-align: top;"></span>
<script>
$( function() {
$('.cp-basic').colorpicker();
});
</script>
<hr/>
Fully-featured example: <input type="text" class="cp-full" value="186aa7"/>
<script>
$( function() {
$('.cp-full').colorpicker({
parts: 'full',
showOn: 'both',
buttonColorize: true,
showNoneButton: true,
alpha: true
});
});
</script>
<hr/>
Localized to Dutch (nl): <input type="text" class="cp-nl" value="ccea73"/>
<script>
$( function() {
$('.cp-nl').colorpicker({
regional: 'nl',
showNoneButton: true,
alpha: true
});
});
</script>
<hr/>
Limit to websafe colors: <input type="text" class="cp-websafe" value="0fa7c2"/>
<script>
$( function() {
$('.cp-websafe').colorpicker({
limit: 'websafe'
});
});
</script>
<hr/>
Alternative field class: <input type="text" class="cp-alt" value="b762ae"/>
<span class="cp-alt-target" style="display: inline-block; border: thin solid black; padding: .5em 4em;">
<div style=" background-color: white; border: thin solid black; padding: .25em 2em; font-size: 1.25em; font-weight: bold;">Background-color on outside, text color here</div>
</span>
<script>
$( function() {
$('.cp-alt').colorpicker({
altField: '.cp-alt-target',
altProperties: 'background-color,color',
altAlpha: true,
alpha: true
});
});
</script>
<hr/>
Events: <input type="text" class="cp-events" value="92b64a"/>
<div class="cp-events-log" style="vertical-align: top; display: inline-block; border: thin solid black; height: 10em; overflow-y: scroll; width: 50em;"></div>
<script>
$( function() {
var count = 0;
function addToEventLog(label, message) {
var line = '<div>#'+(++count)+' '+label+': '+message+'</div>';
var log = $('.cp-events-log');
log.append(line).scrollTop(log[0].scrollHeight);
}
$('.cp-events').colorpicker({
init: function(event, color) {
addToEventLog('Init', color.formatted);
},
select: function(event, color) {
addToEventLog('Select', color.formatted);
},
close: function(event, color) {
addToEventLog('Close', color.formatted + ' r:' + color.rgb.r + ' g:' + color.rgb.g + ' b:' + color.rgb.b + ' a:' + color.a);
}
});
});
</script>
<hr/>
Output formatting HSLA: <input type="text" class="cp-format" value="918237"/>
<span class="cp-format-output"></span>
<script>
$( function() {
$('.cp-format').colorpicker({
colorFormat: 'HSLA',
alpha: true,
init: function(event, color) {
$('.cp-format-output').text(color.formatted);
},
select: function(event, color) {
$('.cp-format-output').text(color.formatted);
}
});
});
</script>
<hr/>
Output format list: <input type="text" class="cp-name" value="a92fb4"/>
<span class="cp-name-output"></span>
<script>
$( function() {
$('.cp-name').colorpicker({
parts: 'full',
colorFormat: ['NAME', 'EXACT', '#HEX3', 'RGB', 'RGBA'],
init: function(event, color) {
$('.cp-name-output').text(color.formatted);
},
select: function(event, color) {
$('.cp-name-output').text(color.formatted);
}
});
});
</script>
<hr/>
Dialog with Colorpicker popup (demonstrates z-index):
<button id="cp-dialog-open">Open dialog</button>
<div id="cp-dialog-modal" title="Basic modal dialog">
Basic &lt;input&gt; example, without any options: <input type="text" class="cp-basic" value="fe9810"/>
<br/>
Basic &lt;div&gt; example, without any options: <span class="cp-basic" style="display: inline-block; vertical-align: top;"></span>
</div>
<script>
$(function() {
var dialog = $('#cp-dialog-modal').dialog({
autoOpen: false,
minWidth: 500,
modal: true,
buttons: { 'Close': function() {
$(this).dialog('close');
}
}
});
$('#cp-dialog-open').click(function() {
dialog.dialog('open');
});
});
</script>
<hr/>
Modal (and showCancelButton, closeOnEscape, showCloseButton): <input type="text" class="cp-modal" value="9ba73f"/>
<script>
$( function() {
$('.cp-modal').colorpicker({
parts: 'draggable',
showCloseButton: false,
modal: true,
showCancelButton: false,
closeOnEscape: false
});
});
</script>
<hr/>
Input formatting: <input type="text" class="cp-input" value="rgb(123,42,87)"/>
<script>
$( function() {
$('.cp-input').colorpicker({
colorFormat: ['RGBA']
});
});
</script>
</body>
</html>

View File

@ -0,0 +1,199 @@
.ui-colorpicker,
.ui-dialog.ui-colorpicker {
width: auto;
white-space: nowrap;
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.ui-colorpicker-inline {
position: static;
}
.ui-colorpicker-buttonset {
float: left;
margin-left: .4em;
}
.ui-colorpicker-buttonset .ui-button {
margin: .5em 0 .5em 0;
cursor: pointer;
}
.ui-colorpicker-buttonpane {
background-image: none;
margin: .7em 0 0 0;
padding: 0 .2em;
border-left: 0;
border-right: 0;
border-bottom: 0;
}
.ui-colorpicker-buttonpane button {
float: right;
margin: .5em .2em .4em;
cursor: pointer;
padding: .2em .6em .3em .6em;
width: auto;
overflow: visible;
}
.ui-colorpicker-buttonpane button.ui-colorpicker-current {
float: left;
}
.ui-colorpicker table {
font-size: 100%; /* Reset browser table font-size */
margin: 0;
}
.ui-colorpicker table td {
vertical-align: top;
}
.ui-colorpicker-padding-left {
padding-left: 10px;
}
.ui-colorpicker-padding-top {
padding-top: 10px;
}
.ui-colorpicker-border {
border: 1px inset;
display: inline-block;
}
/* Bar & map */
.ui-colorpicker-map > *,
.ui-colorpicker-bar > * {
position: absolute;
cursor: crosshair;
}
.ui-colorpicker-map-pointer,
.ui-colorpicker-bar-pointer {
position: absolute;
}
/* Map */
.ui-colorpicker-map,
.ui-colorpicker-map > * {
display: block;
width: 256px;
height: 256px;
overflow: hidden;
}
.ui-colorpicker-map-layer-1,
.ui-colorpicker-map-layer-2 {
background: url(images/map.png) no-repeat;
}
.ui-colorpicker-map-layer-alpha {
background: url(images/map-opacity.png);
}
.ui-colorpicker-map-pointer {
display: inline-block;
width: 15px;
height: 15px;
background: url(images/map-pointer.png) no-repeat;
}
/* Bar */
.ui-colorpicker-bar,
.ui-colorpicker-bar > * {
display: block;
width: 20px;
height: 256px;
overflow: hidden;
background-repeat: repeat-x;
}
.ui-colorpicker-bar-layer-1,
.ui-colorpicker-bar-layer-2,
.ui-colorpicker-bar-layer-3,
.ui-colorpicker-bar-layer-4 {
background: url(images/bar.png) repeat-x;
}
.ui-colorpicker-bar-layer-alpha {
background: url(images/bar-opacity.png);
}
.ui-colorpicker-bar-layer-alphabar {
background: url(images/bar-alpha.png);
}
.ui-colorpicker-bar-pointer {
display: inline-block;
width: 20px;
height: 7px;
background: url(images/bar-pointer.png) no-repeat;
}
/* Preview */
.ui-colorpicker-preview {
text-align: center;
}
.ui-colorpicker-preview-initial {
cursor: pointer;
}
.ui-colorpicker-preview-initial,
.ui-colorpicker-preview-current {
width: 50px;
height: 20px;
display: inline-block;
}
.ui-colorpicker-preview-initial-alpha,
.ui-colorpicker-preview-current-alpha {
width: 50px;
height: 20px;
display: inline-block;
background: url(images/preview-opacity.png) repeat;
}
/* Inputs */
.ui-colorpicker-rgb label,
.ui-colorpicker-hsv label,
.ui-colorpicker-hsl label,
.ui-colorpicker-lab label,
.ui-colorpicker-cmyk label,
.ui-colorpicker-alpha label {
width: 1.5em;
display: inline-block;
}
.ui-colorpicker-number {
margin: .1em;
width: 4em;
}
/* Hex */
.ui-colorpicker-hex {
text-align: center;
}
/* Swatches */
.ui-colorpicker-swatches {
width: 84px;
height: 256px;
overflow: auto;
background-color: #f8f8f8;
}
.ui-colorpicker-swatch {
cursor: pointer;
float: left;
width: 11px;
height: 11px;
border-right: 1px solid black;
border-bottom: 1px solid black;
}

File diff suppressed because it is too large Load Diff

1
js/min/crayon.min.js vendored Normal file

File diff suppressed because one or more lines are too long

8
js/min/crayon.te.min.js vendored Normal file

File diff suppressed because one or more lines are too long

9
js/minify.sh Normal file
View File

@ -0,0 +1,9 @@
#!/bin/bash
BASEDIR=$(dirname $0)
cd $BASEDIR
source ../util/minify.sh
common=$"$INPUT_PATH/util.js $INPUT_PATH/jquery.popup.js $INPUT_PATH/crayon.js"
minify $common $OUTPUT_PATH/crayon.min.js
minify $common $TE_PATH/crayon_qt.js $COLORBOX_PATH/jquery.colorbox-min.js $TE_PATH/crayon_tag_editor.js $OUTPUT_PATH/crayon.te.min.js

1152
js/src/crayon.js Normal file

File diff suppressed because it is too large Load Diff

579
js/src/crayon_admin.js Normal file
View File

@ -0,0 +1,579 @@
// Crayon Syntax Highlighter Admin JavaScript
(function ($) {
window.CrayonSyntaxAdmin = new function () {
var base = this;
// Preview
var preview, previewWrapper, previewInner, preview_info, preview_cbox, preview_delay_timer, preview_get, preview_loaded;
// The DOM object ids that trigger a preview update
var preview_obj_names = [];
// The jQuery objects for these objects
var preview_objs = [];
var preview_last_values = [];
// Alignment
var align_drop, float;
// Toolbar
var overlay, toolbar;
// Error
var msg_cbox, msg;
// Log
var log_button, log_text, log_wrapper, change_button, change_code, plain, copy, clog, help;
var main_wrap, theme_editor_wrap, theme_editor_loading, theme_editor_edit_button, theme_editor_create_button, theme_editor_duplicate_button, theme_editor_delete_button, theme_editor_submit_button;
var theme_select, theme_info, theme_ver, theme_author, theme_desc;
var settings = null;
var strings = null;
var adminSettings = null;
var util = null;
base.init = function () {
CrayonUtil.log('admin init');
settings = CrayonSyntaxSettings;
adminSettings = CrayonAdminSettings;
strings = CrayonAdminStrings;
util = CrayonUtil;
// Dialogs
var dialogFunction = adminSettings.dialogFunction;
dialogFunction = $.fn[dialogFunction] ? dialogFunction : 'dialog';
$.fn.crayonDialog = $.fn[dialogFunction];
// Wraps
main_wrap = $('#crayon-main-wrap');
theme_editor_wrap = $('#crayon-theme-editor-wrap');
// Themes
theme_select = $('#crayon-theme');
theme_info = $('#crayon-theme-info');
theme_ver = theme_info.find('.version').next('div');
theme_author = theme_info.find('.author').next('div');
theme_desc = theme_info.find('.desc');
base.show_theme_info();
theme_select.change(function () {
base.show_theme_info();
base.preview_update();
});
theme_editor_edit_button = $('#crayon-theme-editor-edit-button');
theme_editor_create_button = $('#crayon-theme-editor-create-button');
theme_editor_duplicate_button = $('#crayon-theme-editor-duplicate-button');
theme_editor_delete_button = $('#crayon-theme-editor-delete-button');
theme_editor_submit_button = $('#crayon-theme-editor-submit-button');
theme_editor_edit_button.click(function () {
base.show_theme_editor(theme_editor_edit_button,
true);
});
theme_editor_create_button.click(function () {
base.show_theme_editor(theme_editor_create_button,
false);
});
theme_editor_duplicate_button.click(function () {
CrayonSyntaxThemeEditor.duplicate(adminSettings.currTheme, adminSettings.currThemeName);
});
theme_editor_delete_button.click(function () {
if (!theme_editor_edit_button.attr('disabled')) {
CrayonSyntaxThemeEditor.del(adminSettings.currTheme, adminSettings.currThemeName);
}
return false;
});
theme_editor_submit_button.click(function () {
CrayonSyntaxThemeEditor.submit(adminSettings.currTheme, adminSettings.currThemeName);
});
// Help
help = $('.crayon-help-close');
help.click(function () {
$('.crayon-help').hide();
CrayonUtil.getAJAX({
action: 'crayon-ajax',
'hide-help': 1
});
});
// Preview
preview = $('#crayon-live-preview');
previewWrapper = $('#crayon-live-preview-wrapper');
previewInner = $('#crayon-live-preview-inner');
preview_info = $('#crayon-preview-info');
preview_cbox = util.cssElem('#preview');
if (preview.length != 0) {
// Preview not needed in Tag Editor
preview_register();
preview.ready(function () {
preview_toggle();
});
preview_cbox.change(function () {
preview_toggle();
});
}
$('#show-posts').click(function () {
CrayonUtil.getAJAX({
action: 'crayon-show-posts'
}, function (data) {
$('#crayon-subsection-posts-info').html(data);
});
});
$('#show-langs').click(function () {
CrayonUtil.getAJAX({
action: 'crayon-show-langs'
}, function (data) {
$('#lang-info').hide();
$('#crayon-subsection-langs-info').html(data);
});
});
// Convert
$('#crayon-settings-form input').live(
'focusin focusout mouseup',
function () {
$('#crayon-settings-form').data('lastSelected', $(this));
});
$('#crayon-settings-form')
.submit(
function () {
var last = $(this).data('lastSelected').get(0);
var target = $('#convert').get(0);
if (last == target) {
var r = confirm("Please BACKUP your database first! Converting will update your post content. Do you wish to continue?");
return r;
}
});
// Alignment
align_drop = util.cssElem('#h-align');
float = $('#crayon-subsection-float');
align_drop.change(function () {
float_toggle();
});
align_drop.ready(function () {
float_toggle();
});
// Custom Error
msg_cbox = util.cssElem('#error-msg-show');
msg = util.cssElem('#error-msg');
toggle_error();
msg_cbox.change(function () {
toggle_error();
});
// Toolbar
overlay = $('#crayon-subsection-toolbar');
toolbar = util.cssElem('#toolbar');
toggle_toolbar();
toolbar.change(function () {
toggle_toolbar();
});
// Copy
plain = util.cssElem('#plain');
copy = $('#crayon-subsection-copy-check');
plain.change(function () {
if (plain.is(':checked')) {
copy.show();
} else {
copy.hide();
}
});
// Log
log_wrapper = $('#crayon-log-wrapper');
log_button = $('#crayon-log-toggle');
log_text = $('#crayon-log-text');
var show_log = log_button.attr('show_txt');
var hide_log = log_button.attr('hide_txt');
clog = $('#crayon-log');
log_button.val(show_log);
log_button.click(function () {
clog.width(log_wrapper.width());
clog.toggle();
// Scrolls content
clog.scrollTop(log_text.height());
var text = (log_button.val() == show_log ? hide_log
: show_log);
log_button.val(text);
});
change_button = $('#crayon-change-code');
change_button.click(function () {
base.createDialog({
title: strings.changeCode,
html: '<textarea id="crayon-change-code-text"></textarea>',
desc: null,
value: '',
options: {
buttons: {
"OK": function () {
change_code = $('#crayon-change-code-text').val();
base.preview_update();
$(this).crayonDialog('close');
},
"Cancel": function () {
$(this).crayonDialog('close');
}
},
open: function () {
if (change_code) {
$('#crayon-change-code-text').val(change_code);
}
}
}
});
return false;
});
$('#crayon-fallback-lang').change(function () {
change_code = null;
base.preview_update();
});
};
/* Whenever a control changes preview */
base.preview_update = function (vars) {
var val = 0;
var obj;
var getVars = $.extend({
action: 'crayon-show-preview',
theme: adminSettings.currTheme
}, vars);
if (change_code) {
getVars[adminSettings.sampleCode] = change_code;
}
for (var i = 0; i < preview_obj_names.length; i++) {
obj = preview_objs[i];
if (obj.attr('type') == 'checkbox') {
val = obj.is(':checked');
} else {
val = obj.val();
}
getVars[preview_obj_names[i]] = val;//CrayonUtil.escape(val);
}
// Load Preview
CrayonUtil.postAJAX(getVars, function (data) {
preview.html(data);
// Important! Calls the crayon.js init
CrayonSyntax.init();
base.preview_ready();
});
};
base.preview_ready = function () {
if (!preview_loaded) {
preview_loaded = true;
if (window.GET['theme-editor']) {
CrayonSyntaxAdmin.show_theme_editor(
theme_editor_edit_button, true);
}
}
};
var preview_toggle = function () {
// CrayonUtil.log('preview_toggle');
if (preview_cbox.is(':checked')) {
preview.show();
preview_info.show();
base.preview_update();
} else {
preview.hide();
preview_info.hide();
}
};
var float_toggle = function () {
if (align_drop.val() != 0) {
float.show();
} else {
float.hide();
}
};
// List of callbacks
var preview_callback;
var preview_txt_change;
var preview_txt_callback; // Only updates if text value changed
var preview_txt_callback_delayed;
// var height_set;
// Register all event handlers for preview objects
var preview_register = function () {
// Instant callback
preview_callback = function () {
base.preview_update();
};
// Checks if the text input is changed, if so, runs the callback
// with given event
preview_txt_change = function (callback, event) {
// CrayonUtil.log('checking if changed');
var obj = event.target;
var last = preview_last_values[obj.id];
// CrayonUtil.log('last' + preview_last_values[obj.id]);
if (obj.value != last) {
// CrayonUtil.log('changed');
// Update last value to current
preview_last_values[obj.id] = obj.value;
// Run callback with event
callback(event);
}
};
// Only updates when text is changed
preview_txt_callback = function (event) {
// CrayonUtil.log('txt callback');
preview_txt_change(base.preview_update, event);
};
// Only updates when text is changed, but callback
preview_txt_callback_delayed = function (event) {
preview_txt_change(function () {
clearInterval(preview_delay_timer);
preview_delay_timer = setInterval(function () {
// CrayonUtil.log('delayed update');
base.preview_update();
clearInterval(preview_delay_timer);
}, 500);
}, event);
};
// Retreive preview objects
$('[crayon-preview="1"]').each(function (i) {
var obj = $(this);
var id = obj.attr('id');
// XXX Remove prefix
id = util.removePrefixFromID(id);
preview_obj_names[i] = id;
preview_objs[i] = obj;
// To capture key up events when typing
if (obj.attr('type') == 'text') {
preview_last_values[obj.attr('id')] = obj.val();
obj.bind('keyup', preview_txt_callback_delayed);
obj.change(preview_txt_callback);
} else {
// For all other objects
obj.change(preview_callback);
}
});
};
var toggle_error = function () {
if (msg_cbox.is(':checked')) {
msg.show();
} else {
msg.hide();
}
};
var toggle_toolbar = function () {
if (toolbar.val() == 0) {
overlay.show();
} else {
overlay.hide();
}
};
base.get_vars = function () {
var vars = {};
window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function (m, key, value) {
vars[key] = value;
});
return vars;
};
// Changing wrap views
base.show_main = function () {
theme_editor_wrap.hide();
main_wrap.show();
return false;
};
base.refresh_theme_info = function (callback) {
adminSettings.currTheme = theme_select.val();
adminSettings.currThemeName = theme_select.find('option:selected').attr('data-value');
adminSettings.currThemeIsUser = adminSettings.currTheme in adminSettings.userThemes;
var url = adminSettings.currThemeIsUser ? adminSettings.userThemesURL : adminSettings.themesURL;
adminSettings.currThemeURL = base.get_theme_url(adminSettings.currTheme);
// Load the theme file
$.ajax({
url: adminSettings.currThemeURL,
success: function (data) {
adminSettings.currThemeCSS = data;
// var fields = {
// 'Version': theme_ver,
// 'Author': theme_author,
// 'URL': null,
// 'Description': theme_desc
// };
// for (field in fields) {
// var re = new RegExp('(?:^|[\\r\\n]\\s*)\\b' + field
// + '\\s*:\\s*([^\\r\\n]+)', 'gmi');
// var match = re.exec(data);
// var val = fields[field];
// if (match) {
// if (val != null) {
// val.html(match[1].escape().linkify('_blank'));
// } else if (field == 'Author URI') {
// theme_author.html('<a href="' + match[1]
// + '" target="_blank">'
// + theme_author.text() + '</a>');
// }
// } else if (val != null) {
// val.text('N/A');
// }
// }
if (callback) {
callback();
}
},
cache: false
});
adminSettings.currThemeCSS = '';
};
base.get_theme_url = function ($id) {
var url = $id in adminSettings.userThemes ? adminSettings.userThemesURL : adminSettings.themesURL;
return url + $id + '/' + $id + '.css';
};
base.show_theme_info = function (callback) {
base.refresh_theme_info(function () {
var info = CrayonSyntaxThemeEditor.readCSSInfo(adminSettings.currThemeCSS);
var infoHTML = '';
for (id in info) {
if (id != 'name') {
infoHTML += '<div class="fieldset">';
if (id != 'description') {
infoHTML += '<div class="' + id + ' field">' + CrayonSyntaxThemeEditor.getFieldName(id) + ':</div>';
}
infoHTML += '<div class="' + id + ' value">' + info[id].linkify('_blank') + '</div></div>';
}
}
var type, typeName;
if (adminSettings.currThemeIsUser) {
type = 'user';
typeName = CrayonThemeEditorStrings.userTheme;
} else {
type = 'stock';
typeName = CrayonThemeEditorStrings.stockTheme;
}
infoHTML = '<div class="type ' + type + '">' + typeName + '</div><div class="content">' + infoHTML + '</div>';
theme_info.html(infoHTML);
// Disable for stock themes
var disabled = !adminSettings.currThemeIsUser && !settings.debug;
theme_editor_edit_button.attr('disabled', disabled);
theme_editor_delete_button.attr('disabled', disabled);
theme_editor_submit_button.attr('disabled', disabled);
if (callback) {
callback();
}
});
};
base.show_theme_editor = function (button, editing) {
if (theme_editor_edit_button.attr('disabled')) {
return false;
}
base.refresh_theme_info();
button.html(button.attr('loading'));
adminSettings.editing_theme = editing;
theme_editor_loading = true;
// Load theme editor
CrayonUtil.getAJAX({
action: 'crayon-theme-editor',
currTheme: adminSettings.currTheme,
editing: editing
}, function (data) {
theme_editor_wrap.html(data);
// Load preview into editor
if (theme_editor_loading) {
CrayonSyntaxThemeEditor.init();
}
CrayonSyntaxThemeEditor.show(function () {
base.show_theme_editor_now(button);
}, previewInner);
});
return false;
};
base.resetPreview = function () {
previewWrapper.append(previewInner);
CrayonSyntaxThemeEditor.removeStyle();
};
base.show_theme_editor_now = function (button) {
main_wrap.hide();
theme_editor_wrap.show();
theme_editor_loading = false;
button.html(button.attr('loaded'));
};
// JQUERY UI DIALOGS
base.createAlert = function (args) {
args = $.extend({
title: strings.alert,
options: {
buttons: {
"OK": function () {
$(this).crayonDialog('close');
}
}
}
}, args);
base.createDialog(args);
};
base.createDialog = function (args, options) {
var defaultArgs = {
yesLabel: strings.yes,
noLabel: strings.no,
title: strings.confirm
};
args = $.extend(defaultArgs, args);
var options = $.extend({
modal: true, title: args.title, zIndex: 10000, autoOpen: true,
width: 'auto', resizable: false,
buttons: {
},
dialogClass: 'wp-dialog',
selectedButtonIndex: 1, // starts from 1
close: function (event, ui) {
$(this).remove();
}
}, options);
options.buttons[args.yesLabel] = function () {
if (args.yes) {
args.yes();
}
$(this).crayonDialog('close');
};
options.buttons[args.noLabel] = function () {
if (args.no) {
args.no();
}
$(this).crayonDialog('close');
};
options = $.extend(options, args.options);
options.open = function () {
$('.ui-button').addClass('button-primary');
$(this).parent().find('button:nth-child(' + options.selectedButtonIndex + ')').focus();
if (args.options.open) {
args.options.open();
}
};
$('<div></div>').appendTo('body').html(args.html).crayonDialog(options);
// Can be modified afterwards
return args;
};
};
})(jQueryCrayon);

190
js/src/cssjson.js Normal file
View File

@ -0,0 +1,190 @@
/**
* CSS-JSON Converter for JavaScript, v.2.0 By Aram Kocharyan, http://aramk.com/
* Converts CSS to JSON and back.
*/
var CSSJSON = new function() {
var base = this;
base.init = function() {
// String functions
String.prototype.trim = function() {
return this.replace(/^\s+|\s+$/g, '');
};
String.prototype.repeat = function(n) {
return new Array(1 + n).join(this);
};
};
base.init();
var selX = /([^\s\;\{\}][^\;\{\}]*)\{/g;
var endX = /\}/g;
var lineX = /([^\;\{\}]*)\;/g;
var commentX = /\/\*[\s\S]*?\*\//g;
var lineAttrX = /([^\:]+):([^\;]*);/;
// This is used, a concatenation of all above. We use alternation to
// capture.
var altX = /(\/\*[\s\S]*?\*\/)|([^\s\;\{\}][^\;\{\}]*(?=\{))|(\})|([^\;\{\}]+\;(?!\s*\*\/))/gmi;
// Capture groups
var capComment = 1;
var capSelector = 2;
var capEnd = 3;
var capAttr = 4;
var isEmpty = function(x) {
return typeof x == 'undefined' || x.length == 0 || x == null;
};
/**
* Input is css string and current pos, returns JSON object
*
* @param cssString
* The CSS string.
* @param args
* An optional argument object. ordered: Whether order of
* comments and other nodes should be kept in the output. This
* will return an object where all the keys are numbers and the
* values are objects containing "name" and "value" keys for each
* node. comments: Whether to capture comments. split: Whether to
* split each comma separated list of selectors.
*/
base.toJSON = function(cssString, args) {
var node = {
children: {},
attributes: {}
};
var match = null;
var count = 0;
if (typeof args == 'undefined') {
var args = {
ordered : false,
comments : false,
stripComments : false,
split : false
};
}
if (args.stripComments) {
args.comments = false;
cssString = cssString.replace(commentX, '');
}
while ((match = altX.exec(cssString)) != null) {
if (!isEmpty(match[capComment]) && args.comments) {
// Comment
var add = match[capComment].trim();
node[count++] = add;
} else if (!isEmpty(match[capSelector])) {
// New node, we recurse
var name = match[capSelector].trim();
// This will return when we encounter a closing brace
var newNode = base.toJSON(cssString, args);
if (args.ordered) {
var obj = {};
obj['name'] = name;
obj['value'] = newNode;
// Since we must use key as index to keep order and not
// name, this will differentiate between a Rule Node and an
// Attribute, since both contain a name and value pair.
obj['type'] = 'rule';
node[count++] = obj;
} else {
if (args.split) {
var bits = name.split(',');
} else {
var bits = [name];
}
for (i in bits) {
var sel = bits[i].trim();
if (sel in node.children) {
for (var att in newNode.attributes) {
node.children[sel].attributes[att] = newNode.attributes[att];
}
} else {
node.children[sel] = newNode;
}
}
}
} else if (!isEmpty(match[capEnd])) {
// Node has finished
return node;
} else if (!isEmpty(match[capAttr])) {
var line = match[capAttr].trim();
var attr = lineAttrX.exec(line);
if (attr) {
// Attribute
var name = attr[1].trim();
var value = attr[2].trim();
if (args.ordered) {
var obj = {};
obj['name'] = name;
obj['value'] = value;
obj['type'] = 'attr';
node[count++] = obj;
} else {
node.attributes[name] = value;
}
} else {
// Semicolon terminated line
node[count++] = line;
}
}
}
return node;
};
/**
* @param node
* A JSON node.
* @param depth
* The depth of the current node; used for indentation and
* optional.
* @param breaks
* Whether to add line breaks in the output.
*/
base.toCSS = function(node, depth, breaks) {
var cssString = '';
if (typeof depth == 'undefined') {
depth = 0;
}
if (typeof breaks == 'undefined') {
breaks = false;
}
if (node.attributes) {
for (i in node.attributes) {
cssString += strAttr(i, node.attributes[i], depth);
}
}
if (node.children) {
var first = true;
for (i in node.children) {
if (breaks && !first) {
cssString += '\n';
} else {
first = false;
}
cssString += strNode(i, node.children[i], depth);
}
}
return cssString;
};
// Helpers
var strAttr = function(name, value, depth) {
return '\t'.repeat(depth) + name + ': ' + value + ';\n';
};
var strNode = function(name, value, depth) {
var cssString = '\t'.repeat(depth) + name + ' {\n';
cssString += base.toCSS(value, depth + 1);
cssString += '\t'.repeat(depth) + '}\n';
return cssString;
};
};

101
js/src/jquery.popup.js Normal file
View File

@ -0,0 +1,101 @@
// Default Settings
jqueryPopup = Object();
jqueryPopup.defaultSettings = {
centerBrowser:0, // center window over browser window? {1 (YES) or 0 (NO)}. overrides top and left
centerScreen:0, // center window over entire screen? {1 (YES) or 0 (NO)}. overrides top and left
height:500, // sets the height in pixels of the window.
left:0, // left position when the window appears.
location:0, // determines whether the address bar is displayed {1 (YES) or 0 (NO)}.
menubar:0, // determines whether the menu bar is displayed {1 (YES) or 0 (NO)}.
resizable:0, // whether the window can be resized {1 (YES) or 0 (NO)}. Can also be overloaded using resizable.
scrollbars:0, // determines whether scrollbars appear on the window {1 (YES) or 0 (NO)}.
status:0, // whether a status line appears at the bottom of the window {1 (YES) or 0 (NO)}.
width:500, // sets the width in pixels of the window.
windowName:null, // name of window set from the name attribute of the element that invokes the click
windowURL:null, // url used for the popup
top:0, // top position when the window appears.
toolbar:0, // determines whether a toolbar (includes the forward and back buttons) is displayed {1 (YES) or 0 (NO)}.
data:null,
event:'click'
};
(function ($) {
popupWindow = function (object, instanceSettings, beforeCallback, afterCallback) {
beforeCallback = typeof beforeCallback !== 'undefined' ? beforeCallback : null;
afterCallback = typeof afterCallback !== 'undefined' ? afterCallback : null;
if (typeof object == 'string') {
object = jQuery(object);
}
if (!(object instanceof jQuery)) {
return false;
}
var settings = jQuery.extend({}, jqueryPopup.defaultSettings, instanceSettings || {});
object.handler = jQuery(object).bind(settings.event, function() {
if (beforeCallback) {
beforeCallback();
}
var windowFeatures = 'height=' + settings.height +
',width=' + settings.width +
',toolbar=' + settings.toolbar +
',scrollbars=' + settings.scrollbars +
',status=' + settings.status +
',resizable=' + settings.resizable +
',location=' + settings.location +
',menuBar=' + settings.menubar;
settings.windowName = settings.windowName || jQuery(this).attr('name');
var href = jQuery(this).attr('href');
if (!settings.windowURL && !(href == '#') && !(href == '')) {
settings.windowURL = jQuery(this).attr('href');
}
var centeredY,centeredX;
var win = null;
if (settings.centerBrowser) {
if (typeof window.screenY == 'undefined') {// not defined for old IE versions
centeredY = (window.screenTop - 120) + ((((document.documentElement.clientHeight + 120)/2) - (settings.height/2)));
centeredX = window.screenLeft + ((((document.body.offsetWidth + 20)/2) - (settings.width/2)));
} else {
centeredY = window.screenY + (((window.outerHeight/2) - (settings.height/2)));
centeredX = window.screenX + (((window.outerWidth/2) - (settings.width/2)));
}
win = window.open(settings.windowURL, settings.windowName, windowFeatures+',left=' + centeredX +',top=' + centeredY);
} else if (settings.centerScreen) {
centeredY = (screen.height - settings.height)/2;
centeredX = (screen.width - settings.width)/2;
win = window.open(settings.windowURL, settings.windowName, windowFeatures+',left=' + centeredX +',top=' + centeredY);
} else {
win = window.open(settings.windowURL, settings.windowName, windowFeatures+',left=' + settings.left +',top=' + settings.top);
}
if (win != null) {
win.focus();
if (settings.data) {
win.document.write(settings.data);
}
}
if (afterCallback) {
afterCallback();
}
});
return settings;
};
popdownWindow = function(object, event) {
if (typeof event == 'undefined') {
event = 'click';
}
object = jQuery(object);
if (!(object instanceof jQuery)) {
return false;
}
object.unbind(event, object.handler);
};
})(jQueryCrayon);

265
js/src/util.js Normal file
View File

@ -0,0 +1,265 @@
// To avoid duplicates conflicting
var jQueryCrayon = jQuery;
(function ($) {
CrayonUtil = new function () {
var base = this;
var settings = null;
base.init = function () {
settings = CrayonSyntaxSettings;
base.initGET();
};
base.addPrefixToID = function (id) {
return id.replace(/^([#.])?(.*)$/, '$1' + settings.prefix + '$2');
};
base.removePrefixFromID = function (id) {
var re = new RegExp('^[#.]?' + settings.prefix, 'i');
return id.replace(re, '');
};
base.cssElem = function (id) {
return $(base.addPrefixToID(id));
};
base.setDefault = function (v, d) {
return (typeof v == 'undefined') ? d : v;
};
base.setMax = function (v, max) {
return v <= max ? v : max;
};
base.setMin = function (v, min) {
return v >= min ? v : min;
};
base.setRange = function (v, min, max) {
return base.setMax(base.setMin(v, min), max);
};
base.getExt = function (str) {
if (str.indexOf('.') == -1) {
return undefined;
}
var ext = str.split('.');
if (ext.length) {
ext = ext[ext.length - 1];
} else {
ext = '';
}
return ext;
};
base.initGET = function () {
// URLs
window.currentURL = window.location.protocol + '//' + window.location.host + window.location.pathname;
window.currentDir = window.currentURL.substring(0, window.currentURL.lastIndexOf('/'));
// http://stackoverflow.com/questions/439463
function getQueryParams(qs) {
qs = qs.split("+").join(" ");
var params = {}, tokens, re = /[?&]?([^=]+)=([^&]*)/g;
while (tokens = re.exec(qs)) {
params[decodeURIComponent(tokens[1])] = decodeURIComponent(tokens[2]);
}
return params;
}
window.GET = getQueryParams(document.location.search);
};
base.getAJAX = function (args, callback) {
args.version = settings.version;
$.get(settings.ajaxurl, args, callback);
};
base.postAJAX = function (args, callback) {
args.version = settings.version;
$.post(settings.ajaxurl, args, callback);
};
base.reload = function () {
var get = '?';
for (var i in window.GET) {
get += i + '=' + window.GET[i] + '&';
}
window.location = window.currentURL + get;
};
base.escape = function (string) {
if (typeof encodeURIComponent == 'function') {
return encodeURIComponent(string);
} else if (typeof escape != 'function') {
return escape(string);
} else {
return string;
}
};
base.log = function (string) {
if (typeof console != 'undefined' && settings.debug) {
console.log(string);
}
};
base.decode_html = function (str) {
return String(str).replace(/&amp;/g, '&').replace(/&lt;/g, '<').replace(
/&gt;/g, '>');
};
base.encode_html = function (str) {
return String(str).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(
/>/g, '&gt;');
};
/**
* Returns either black or white to ensure this color is distinguishable with the given RGB hex.
* This function can be used to create a readable foreground color given a background color, or vice versa.
* It forms a radius around white where black is returned. Outside this radius, white is returned.
*
* @param hex An RGB hex (e.g. "#FFFFFF")
* @requires jQuery and TinyColor
* @param args The argument object. Properties:
* amount: a value in the range [0,1]. If the distance of the given hex from white exceeds this value,
* white is returned. Otherwise, black is returned.
* xMulti: a multiplier to the distance in the x-axis.
* yMulti: a multiplier to the distance in the y-axis.
* normalizeHue: either falsey or an [x,y] array range. If hex is a colour with hue in this range,
* then normalizeHueXMulti and normalizeHueYMulti are applied.
* normalizeHueXMulti: a multiplier to the distance in the x-axis if hue is normalized.
* normalizeHueYMulti: a multiplier to the distance in the y-axis if hue is normalized.
* @return the RGB hex string of black or white.
*/
base.getReadableColor = function (hex, args) {
args = $.extend({
amount: 0.5,
xMulti: 1,
// We want to achieve white a bit sooner in the y axis
yMulti: 1.5,
normalizeHue: [20, 180],
// For colors that appear lighter (yellow, green, light blue) we reduce the distance in the x direction,
// stretching the radius in the x axis allowing more black than before.
normalizeHueXMulti: 1 / 2.5,
normalizeHueYMulti: 1
}, args);
var color = tinycolor(hex);
var hsv = color.toHsv();
// Origin is white
var coord = {x: hsv.s, y: 1 - hsv.v};
// Multipliers
coord.x *= args.xMulti;
coord.y *= args.yMulti;
if (args.normalizeHue && hsv.h > args.normalizeHue[0] && hsv.h < args.normalizeHue[1]) {
coord.x *= args.normalizeHueXMulti;
coord.y *= args.normalizeHueYMulti;
}
var dist = Math.sqrt(Math.pow(coord.x, 2) + Math.pow(coord.y, 2));
if (dist < args.amount) {
hsv.v = 0; // black
} else {
hsv.v = 1; // white
}
hsv.s = 0;
return tinycolor(hsv).toHexString();
};
base.removeChars = function (chars, str) {
var re = new RegExp('[' + chars + ']', 'gmi');
return str.replace(re, '');
}
};
$(document).ready(function () {
CrayonUtil.init();
});
// http://stackoverflow.com/questions/2360655/jquery-event-handlers-always-execute-in-order-they-were-bound-any-way-around-t
// [name] is the name of the event "click", "mouseover", ..
// same as you'd pass it to bind()
// [fn] is the handler function
$.fn.bindFirst = function (name, fn) {
// bind as you normally would
// don't want to miss out on any jQuery magic
this.bind(name, fn);
// Thanks to a comment by @Martin, adding support for
// namespaced events too.
var handlers = this.data('events')[name.split('.')[0]];
// take out the handler we just inserted from the end
var handler = handlers.pop();
// move it at the beginning
handlers.splice(0, 0, handler);
};
// http://stackoverflow.com/questions/4079274/how-to-get-an-objects-properties-in-javascript-jquery
$.keys = function (obj) {
var keys = [];
for (var key in obj) {
keys.push(key);
}
return keys;
}
// Prototype modifications
RegExp.prototype.execAll = function (string) {
var matches = [];
var match = null;
while ((match = this.exec(string)) != null) {
var matchArray = [];
for (var i in match) {
if (parseInt(i) == i) {
matchArray.push(match[i]);
}
}
matches.push(matchArray);
}
return matches;
};
// Escape regex chars with \
RegExp.prototype.escape = function (text) {
return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
};
String.prototype.sliceReplace = function (start, end, repl) {
return this.substring(0, start) + repl + this.substring(end);
};
String.prototype.escape = function () {
var tagsToReplace = {
'&': '&amp;',
'<': '&lt;',
'>': '&gt;'
};
return this.replace(/[&<>]/g, function (tag) {
return tagsToReplace[tag] || tag;
});
};
String.prototype.linkify = function (target) {
target = typeof target != 'undefined' ? target : '';
return this.replace(/(http(s)?:\/\/(\S)+)/gmi, '<a href="$1" target="' + target + '">$1</a>');
};
String.prototype.toTitleCase = function () {
var parts = this.split(/\s+/);
var title = '';
$.each(parts, function (i, part) {
if (part != '') {
title += part.slice(0, 1).toUpperCase() + part.slice(1, part.length);
if (i != parts.length - 1 && parts[i + 1] != '') {
title += ' ';
}
}
});
return title;
};
})(jQueryCrayon);

21
js/tinycolor-min.js vendored Normal file
View File

@ -0,0 +1,21 @@
// TinyColor.js - <https://github.com/bgrins/TinyColor> - 2012 Brian Grinstead - v0.9.12
(function(C){var t,u,v,w,x,y,z;function d(a,c){a=a?a:"";if("object"==typeof a&&a.hasOwnProperty("_tc_id"))return a;var b=D(a),i=b.r,j=b.g,g=b.b,f=b.a,k=e(100*f)/100,E=b.format;1>i&&(i=e(i));1>j&&(j=e(j));1>g&&(g=e(g));return{ok:b.ok,format:E,_tc_id:F++,alpha:f,toHsv:function(){var a=A(i,j,g);return{h:360*a.h,s:a.s,v:a.v,a:f}},toHsvString:function(){var a=A(i,j,g),b=e(360*a.h),c=e(100*a.s),a=e(100*a.v);return 1==f?"hsv("+b+", "+c+"%, "+a+"%)":"hsva("+b+", "+c+"%, "+a+"%, "+k+")"},toHsl:function(){var a=
B(i,j,g);return{h:360*a.h,s:a.s,l:a.l,a:f}},toHslString:function(){var a=B(i,j,g),b=e(360*a.h),c=e(100*a.s),a=e(100*a.l);return 1==f?"hsl("+b+", "+c+"%, "+a+"%)":"hsla("+b+", "+c+"%, "+a+"%, "+k+")"},toHex:function(){return q(i,j,g)},toHexString:function(){return"#"+q(i,j,g)},toRgb:function(){return{r:e(i),g:e(j),b:e(g),a:f}},toRgbString:function(){return 1==f?"rgb("+e(i)+", "+e(j)+", "+e(g)+")":"rgba("+e(i)+", "+e(j)+", "+e(g)+", "+k+")"},toPercentageRgb:function(){return{r:e(100*h(i,255))+"%",g:e(100*
h(j,255))+"%",b:e(100*h(g,255))+"%",a:f}},toPercentageRgbString:function(){return 1==f?"rgb("+e(100*h(i,255))+"%, "+e(100*h(j,255))+"%, "+e(100*h(g,255))+"%)":"rgba("+e(100*h(i,255))+"%, "+e(100*h(j,255))+"%, "+e(100*h(g,255))+"%, "+k+")"},toName:function(){return G[q(i,j,g)]||!1},toFilter:function(){var a=q(i,j,g),b=a,e=Math.round(255*parseFloat(f)).toString(16),h=e,k=c&&c.gradientType?"GradientType = 1, ":"";secondColor&&(h=d(secondColor),b=h.toHex(),h=Math.round(255*parseFloat(h.alpha)).toString(16));
return"progid:DXImageTransform.Microsoft.gradient("+k+"startColorstr=#"+o(e)+a+",endColorstr=#"+o(h)+b+")"},toString:function(a){var a=a||this.format,b=!1;"rgb"===a&&(b=this.toRgbString());"prgb"===a&&(b=this.toPercentageRgbString());"hex"===a&&(b=this.toHexString());"name"===a&&(b=this.toName());"hsl"===a&&(b=this.toHslString());"hsv"===a&&(b=this.toHsvString());return b||this.toHexString()}}}function D(a){var c={r:255,g:255,b:255},b=1,i=!1,d=!1;if("string"==typeof a)a:{var a=a.replace(H,"").replace(I,
"").toLowerCase(),g=!1;if(r[a])a=r[a],g=!0;else if("transparent"==a){a={r:0,g:0,b:0,a:0};break a}var f,a=(f=t.exec(a))?{r:f[1],g:f[2],b:f[3]}:(f=u.exec(a))?{r:f[1],g:f[2],b:f[3],a:f[4]}:(f=v.exec(a))?{h:f[1],s:f[2],l:f[3]}:(f=w.exec(a))?{h:f[1],s:f[2],l:f[3],a:f[4]}:(f=x.exec(a))?{h:f[1],s:f[2],v:f[3]}:(f=y.exec(a))?{r:parseInt(f[1],16),g:parseInt(f[2],16),b:parseInt(f[3],16),format:g?"name":"hex"}:(f=z.exec(a))?{r:parseInt(f[1]+""+f[1],16),g:parseInt(f[2]+""+f[2],16),b:parseInt(f[3]+""+f[3],16),
format:g?"name":"hex"}:!1}if("object"==typeof a){if(a.hasOwnProperty("r")&&a.hasOwnProperty("g")&&a.hasOwnProperty("b"))c={r:255*h(a.r,255),g:255*h(a.g,255),b:255*h(a.b,255)},i=!0,d="%"===(""+a.r).substr(-1)?"prgb":"rgb";else if(a.hasOwnProperty("h")&&a.hasOwnProperty("s")&&a.hasOwnProperty("v")){a.s=p(a.s);a.v=p(a.v);var d=a.h,g=a.s,c=a.v,d=6*h(d,360),g=h(g,100),c=h(c,100),i=n.floor(d),e=d-i,d=c*(1-g);f=c*(1-e*g);g=c*(1-(1-e)*g);i%=6;c={r:255*[c,f,d,d,g,c][i],g:255*[g,c,c,f,d,d][i],b:255*[d,d,g,
c,c,f][i]};i=!0;d="hsv"}else a.hasOwnProperty("h")&&a.hasOwnProperty("s")&&a.hasOwnProperty("l")&&(a.s=p(a.s),a.l=p(a.l),c=J(a.h,a.s,a.l),i=!0,d="hsl");a.hasOwnProperty("a")&&(b=a.a)}b=parseFloat(b);if(isNaN(b)||0>b||1<b)b=1;return{ok:i,format:a.format||d,r:l(255,m(c.r,0)),g:l(255,m(c.g,0)),b:l(255,m(c.b,0)),a:b}}function B(a,c,b){var a=h(a,255),c=h(c,255),b=h(b,255),d=m(a,c,b),e=l(a,c,b),g,f=(d+e)/2;if(d==e)g=e=0;else{var k=d-e,e=0.5<f?k/(2-d-e):k/(d+e);switch(d){case a:g=(c-b)/k+(c<b?6:0);break;
case c:g=(b-a)/k+2;break;case b:g=(a-c)/k+4}g/=6}return{h:g,s:e,l:f}}function J(a,c,b){function d(a,b,c){0>c&&(c+=1);1<c&&(c-=1);return c<1/6?a+6*(b-a)*c:0.5>c?b:c<2/3?a+6*(b-a)*(2/3-c):a}a=h(a,360);c=h(c,100);b=h(b,100);if(0===c)b=c=a=b;else var e=0.5>b?b*(1+c):b+c-b*c,g=2*b-e,b=d(g,e,a+1/3),c=d(g,e,a),a=d(g,e,a-1/3);return{r:255*b,g:255*c,b:255*a}}function A(a,c,b){var a=h(a,255),c=h(c,255),b=h(b,255),d=m(a,c,b),e=l(a,c,b),g,f=d-e;if(d==e)g=0;else{switch(d){case a:g=(c-b)/f+(c<b?6:0);break;case c:g=
(b-a)/f+2;break;case b:g=(a-c)/f+4}g/=6}return{h:g,s:0===d?0:f/d,v:d}}function q(a,c,b){a=[o(e(a).toString(16)),o(e(c).toString(16)),o(e(b).toString(16))];return a[0][0]==a[0][1]&&a[1][0]==a[1][1]&&a[2][0]==a[2][1]?a[0][0]+a[1][0]+a[2][0]:a.join("")}function h(a,c){"string"==typeof a&&-1!=a.indexOf(".")&&1===parseFloat(a)&&(a="100%");var b="string"===typeof a&&-1!=a.indexOf("%"),a=l(c,m(0,parseFloat(a)));b&&(a=parseInt(a*c,10)/100);return 1.0E-6>n.abs(a-c)?1:a%c/parseFloat(c)}function o(a){return 1==
a.length?"0"+a:""+a}function p(a){1>=a&&(a=100*a+"%");return a}var H=/^[\s,#]+/,I=/\s+$/,F=0,n=Math,e=n.round,l=n.min,m=n.max,s=n.random;d.fromRatio=function(a){if("object"==typeof a){var c={},b;for(b in a)c[b]=p(a[b]);a=c}return d(a)};d.equals=function(a,c){return!a||!c?!1:d(a).toRgbString()==d(c).toRgbString()};d.random=function(){return d.fromRatio({r:s(),g:s(),b:s()})};d.desaturate=function(a,c){var b=d(a).toHsl();b.s-=(c||10)/100;b.s=l(1,m(0,b.s));return d(b)};d.saturate=function(a,c){var b=
d(a).toHsl();b.s+=(c||10)/100;b.s=l(1,m(0,b.s));return d(b)};d.greyscale=function(a){return d.desaturate(a,100)};d.lighten=function(a,c){var b=d(a).toHsl();b.l+=(c||10)/100;b.l=l(1,m(0,b.l));return d(b)};d.darken=function(a,c){var b=d(a).toHsl();b.l-=(c||10)/100;b.l=l(1,m(0,b.l));return d(b)};d.complement=function(a){a=d(a).toHsl();a.h=(a.h+180)%360;return d(a)};d.triad=function(a){var c=d(a).toHsl(),b=c.h;return[d(a),d({h:(b+120)%360,s:c.s,l:c.l}),d({h:(b+240)%360,s:c.s,l:c.l})]};d.tetrad=function(a){var c=
d(a).toHsl(),b=c.h;return[d(a),d({h:(b+90)%360,s:c.s,l:c.l}),d({h:(b+180)%360,s:c.s,l:c.l}),d({h:(b+270)%360,s:c.s,l:c.l})]};d.splitcomplement=function(a){var c=d(a).toHsl(),b=c.h;return[d(a),d({h:(b+72)%360,s:c.s,l:c.l}),d({h:(b+216)%360,s:c.s,l:c.l})]};d.analogous=function(a,c,b){var c=c||6,b=b||30,e=d(a).toHsl(),b=360/b,a=[d(a)];for(e.h=(e.h-(b*c>>1)+720)%360;--c;)e.h=(e.h+b)%360,a.push(d(e));return a};d.monochromatic=function(a,c){for(var c=c||6,b=d(a).toHsv(),e=b.h,h=b.s,b=b.v,g=[],f=1/c;c--;)g.push(d({h:e,
s:h,v:b})),b=(b+f)%1;return g};d.readable=function(a,c){var b=d(a).toRgb(),e=d(c).toRgb();return 10404<(e.r-b.r)*(e.r-b.r)+(e.g-b.g)*(e.g-b.g)+(e.b-b.b)*(e.b-b.b)};var r=d.names={aliceblue:"f0f8ff",antiquewhite:"faebd7",aqua:"0ff",aquamarine:"7fffd4",azure:"f0ffff",beige:"f5f5dc",bisque:"ffe4c4",black:"000",blanchedalmond:"ffebcd",blue:"00f",blueviolet:"8a2be2",brown:"a52a2a",burlywood:"deb887",burntsienna:"ea7e5d",cadetblue:"5f9ea0",chartreuse:"7fff00",chocolate:"d2691e",coral:"ff7f50",cornflowerblue:"6495ed",
cornsilk:"fff8dc",crimson:"dc143c",cyan:"0ff",darkblue:"00008b",darkcyan:"008b8b",darkgoldenrod:"b8860b",darkgray:"a9a9a9",darkgreen:"006400",darkgrey:"a9a9a9",darkkhaki:"bdb76b",darkmagenta:"8b008b",darkolivegreen:"556b2f",darkorange:"ff8c00",darkorchid:"9932cc",darkred:"8b0000",darksalmon:"e9967a",darkseagreen:"8fbc8f",darkslateblue:"483d8b",darkslategray:"2f4f4f",darkslategrey:"2f4f4f",darkturquoise:"00ced1",darkviolet:"9400d3",deeppink:"ff1493",deepskyblue:"00bfff",dimgray:"696969",dimgrey:"696969",
dodgerblue:"1e90ff",firebrick:"b22222",floralwhite:"fffaf0",forestgreen:"228b22",fuchsia:"f0f",gainsboro:"dcdcdc",ghostwhite:"f8f8ff",gold:"ffd700",goldenrod:"daa520",gray:"808080",green:"008000",greenyellow:"adff2f",grey:"808080",honeydew:"f0fff0",hotpink:"ff69b4",indianred:"cd5c5c",indigo:"4b0082",ivory:"fffff0",khaki:"f0e68c",lavender:"e6e6fa",lavenderblush:"fff0f5",lawngreen:"7cfc00",lemonchiffon:"fffacd",lightblue:"add8e6",lightcoral:"f08080",lightcyan:"e0ffff",lightgoldenrodyellow:"fafad2",
lightgray:"d3d3d3",lightgreen:"90ee90",lightgrey:"d3d3d3",lightpink:"ffb6c1",lightsalmon:"ffa07a",lightseagreen:"20b2aa",lightskyblue:"87cefa",lightslategray:"789",lightslategrey:"789",lightsteelblue:"b0c4de",lightyellow:"ffffe0",lime:"0f0",limegreen:"32cd32",linen:"faf0e6",magenta:"f0f",maroon:"800000",mediumaquamarine:"66cdaa",mediumblue:"0000cd",mediumorchid:"ba55d3",mediumpurple:"9370db",mediumseagreen:"3cb371",mediumslateblue:"7b68ee",mediumspringgreen:"00fa9a",mediumturquoise:"48d1cc",mediumvioletred:"c71585",
midnightblue:"191970",mintcream:"f5fffa",mistyrose:"ffe4e1",moccasin:"ffe4b5",navajowhite:"ffdead",navy:"000080",oldlace:"fdf5e6",olive:"808000",olivedrab:"6b8e23",orange:"ffa500",orangered:"ff4500",orchid:"da70d6",palegoldenrod:"eee8aa",palegreen:"98fb98",paleturquoise:"afeeee",palevioletred:"db7093",papayawhip:"ffefd5",peachpuff:"ffdab9",peru:"cd853f",pink:"ffc0cb",plum:"dda0dd",powderblue:"b0e0e6",purple:"800080",red:"f00",rosybrown:"bc8f8f",royalblue:"4169e1",saddlebrown:"8b4513",salmon:"fa8072",
sandybrown:"f4a460",seagreen:"2e8b57",seashell:"fff5ee",sienna:"a0522d",silver:"c0c0c0",skyblue:"87ceeb",slateblue:"6a5acd",slategray:"708090",slategrey:"708090",snow:"fffafa",springgreen:"00ff7f",steelblue:"4682b4",tan:"d2b48c",teal:"008080",thistle:"d8bfd8",tomato:"ff6347",turquoise:"40e0d0",violet:"ee82ee",wheat:"f5deb3",white:"fff",whitesmoke:"f5f5f5",yellow:"ff0",yellowgreen:"9acd32"},G=d.hexNames=function(a){var c={},b;for(b in a)a.hasOwnProperty(b)&&(c[a[b]]=b);return c}(r);t=RegExp("rgb[\\s|\\(]+((?:[-\\+]?\\d*\\.\\d+%?)|(?:[-\\+]?\\d+%?))[,|\\s]+((?:[-\\+]?\\d*\\.\\d+%?)|(?:[-\\+]?\\d+%?))[,|\\s]+((?:[-\\+]?\\d*\\.\\d+%?)|(?:[-\\+]?\\d+%?))\\s*\\)?");
u=RegExp("rgba[\\s|\\(]+((?:[-\\+]?\\d*\\.\\d+%?)|(?:[-\\+]?\\d+%?))[,|\\s]+((?:[-\\+]?\\d*\\.\\d+%?)|(?:[-\\+]?\\d+%?))[,|\\s]+((?:[-\\+]?\\d*\\.\\d+%?)|(?:[-\\+]?\\d+%?))[,|\\s]+((?:[-\\+]?\\d*\\.\\d+%?)|(?:[-\\+]?\\d+%?))\\s*\\)?");v=RegExp("hsl[\\s|\\(]+((?:[-\\+]?\\d*\\.\\d+%?)|(?:[-\\+]?\\d+%?))[,|\\s]+((?:[-\\+]?\\d*\\.\\d+%?)|(?:[-\\+]?\\d+%?))[,|\\s]+((?:[-\\+]?\\d*\\.\\d+%?)|(?:[-\\+]?\\d+%?))\\s*\\)?");w=RegExp("hsla[\\s|\\(]+((?:[-\\+]?\\d*\\.\\d+%?)|(?:[-\\+]?\\d+%?))[,|\\s]+((?:[-\\+]?\\d*\\.\\d+%?)|(?:[-\\+]?\\d+%?))[,|\\s]+((?:[-\\+]?\\d*\\.\\d+%?)|(?:[-\\+]?\\d+%?))[,|\\s]+((?:[-\\+]?\\d*\\.\\d+%?)|(?:[-\\+]?\\d+%?))\\s*\\)?");
x=RegExp("hsv[\\s|\\(]+((?:[-\\+]?\\d*\\.\\d+%?)|(?:[-\\+]?\\d+%?))[,|\\s]+((?:[-\\+]?\\d*\\.\\d+%?)|(?:[-\\+]?\\d+%?))[,|\\s]+((?:[-\\+]?\\d*\\.\\d+%?)|(?:[-\\+]?\\d+%?))\\s*\\)?");z=/^([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/;y=/^([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/;"undefined"!==typeof module&&module.exports?module.exports=d:C.tinycolor=d})(this);