Version Description
- Removed jQuery.noConflict() from crayon.js. This must have been causing some trouble if anything used $.
Download this release
Release Info
Developer | akarmenia |
Plugin | Crayon Syntax Highlighter |
Version | 1.7.5 |
Comparing to | |
See all releases |
Code changes from version 1.7.3 to 1.7.5
- crayon_formatter.class.php +3 -3
- crayon_wp.class.php +1 -1
- js/crayon.js +581 -576
- readme.txt +6 -0
crayon_formatter.class.php
CHANGED
@@ -191,9 +191,9 @@ class CrayonFormatter {
|
|
191 |
$plain_style = "-moz-tab-size:$tab; -o-tab-size:$tab; -webkit-tab-size:$tab; tab-size:$tab;";
|
192 |
$readonly = $touch ? '' : 'readonly';
|
193 |
$print_plain = '<textarea class="crayon-plain" settings="' . $plain_settings . '" '. $readonly .' wrap="off" style="' . $plain_style .'">' . self::clean_code($hl->code()) . '</textarea>';
|
194 |
-
$print_plain_button = '<a href="#" class="crayon-plain-button crayon-button" title="Toggle Plain Code" onclick="toggle_plain(\'' . $uid . '\'); return false;"></a>';
|
195 |
$print_copy_button = !$touch && $hl->setting_val(CrayonSettings::PLAIN) && $hl->setting_val(CrayonSettings::COPY) ?
|
196 |
-
'<a href="#" class="crayon-copy-button crayon-button" title="Copy Plain Code" onclick="copy_plain(\'' . $uid . '\'); return false;"></a>' : '';
|
197 |
$print_popup_button = $hl->setting_val(CrayonSettings::POPUP) ?
|
198 |
'<a href="#" class="crayon-popup-button crayon-button" title="Open Code in Window" onclick="return false;"></a>' : '';
|
199 |
} else {
|
@@ -201,7 +201,7 @@ class CrayonFormatter {
|
|
201 |
}
|
202 |
|
203 |
if ($hl->setting_val(CrayonSettings::NUMS_TOGGLE)) {
|
204 |
-
$print_nums_button = '<a href="#" class="crayon-nums-button crayon-button" title="Toggle Line Numbers" onclick="toggle_nums(\'' . $uid . '\'); return false;"></a>';
|
205 |
} else {
|
206 |
$print_nums_button = '';
|
207 |
}
|
191 |
$plain_style = "-moz-tab-size:$tab; -o-tab-size:$tab; -webkit-tab-size:$tab; tab-size:$tab;";
|
192 |
$readonly = $touch ? '' : 'readonly';
|
193 |
$print_plain = '<textarea class="crayon-plain" settings="' . $plain_settings . '" '. $readonly .' wrap="off" style="' . $plain_style .'">' . self::clean_code($hl->code()) . '</textarea>';
|
194 |
+
$print_plain_button = '<a href="#" class="crayon-plain-button crayon-button" title="Toggle Plain Code" onclick="CrayonSyntax.toggle_plain(\'' . $uid . '\'); return false;"></a>';
|
195 |
$print_copy_button = !$touch && $hl->setting_val(CrayonSettings::PLAIN) && $hl->setting_val(CrayonSettings::COPY) ?
|
196 |
+
'<a href="#" class="crayon-copy-button crayon-button" title="Copy Plain Code" onclick="CrayonSyntax.copy_plain(\'' . $uid . '\'); return false;"></a>' : '';
|
197 |
$print_popup_button = $hl->setting_val(CrayonSettings::POPUP) ?
|
198 |
'<a href="#" class="crayon-popup-button crayon-button" title="Open Code in Window" onclick="return false;"></a>' : '';
|
199 |
} else {
|
201 |
}
|
202 |
|
203 |
if ($hl->setting_val(CrayonSettings::NUMS_TOGGLE)) {
|
204 |
+
$print_nums_button = '<a href="#" class="crayon-nums-button crayon-button" title="Toggle Line Numbers" onclick="CrayonSyntax.toggle_nums(\'' . $uid . '\'); return false;"></a>';
|
205 |
} else {
|
206 |
$print_nums_button = '';
|
207 |
}
|
crayon_wp.class.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
Plugin Name: Crayon Syntax Highlighter
|
4 |
Plugin URI: http://ak.net84.net/
|
5 |
Description: Supports multiple languages, themes, highlighting from a URL, local file or post text. <a href="options-general.php?page=crayon_settings">View Settings</a>
|
6 |
-
Version: 1.7.
|
7 |
Author: Aram Kocharyan
|
8 |
Author URI: http://ak.net84.net/
|
9 |
Text Domain: crayon-syntax-highlighter
|
3 |
Plugin Name: Crayon Syntax Highlighter
|
4 |
Plugin URI: http://ak.net84.net/
|
5 |
Description: Supports multiple languages, themes, highlighting from a URL, local file or post text. <a href="options-general.php?page=crayon_settings">View Settings</a>
|
6 |
+
Version: 1.7.5
|
7 |
Author: Aram Kocharyan
|
8 |
Author URI: http://ak.net84.net/
|
9 |
Text Domain: crayon-syntax-highlighter
|
js/crayon.js
CHANGED
@@ -8,7 +8,7 @@ var DEBUG = true;
|
|
8 |
|
9 |
// jQuery
|
10 |
|
11 |
-
jQuery.noConflict();
|
12 |
|
13 |
var PRESSED = 'crayon-pressed';
|
14 |
var UNPRESSED = '';
|
@@ -27,617 +27,622 @@ var CRAYON_NUMS_BUTTON = '.crayon-nums-button';
|
|
27 |
var CRAYON_POPUP_BUTTON = '.crayon-popup-button';
|
28 |
|
29 |
jQuery(document).ready(function() {
|
30 |
-
init();
|
31 |
});
|
32 |
|
33 |
-
var
|
34 |
-
function init() {
|
35 |
-
if (typeof crayon == 'undefined') {
|
36 |
-
crayon = new Object();
|
37 |
-
}
|
38 |
-
|
39 |
-
jQuery(CRAYON_SYNTAX).each(function() {
|
40 |
-
var uid = jQuery(this).attr('id');
|
41 |
-
var toolbar = jQuery(this).find(CRAYON_TOOLBAR);
|
42 |
-
var info = jQuery(this).find(CRAYON_INFO);
|
43 |
-
var plain = jQuery(this).find(CRAYON_PLAIN);
|
44 |
-
var plain_button = jQuery(this).find(CRAYON_PLAIN_BUTTON);
|
45 |
-
var main = jQuery(this).find(CRAYON_MAIN);
|
46 |
-
var table = jQuery(this).find(CRAYON_TABLE);
|
47 |
-
var code = jQuery(this).find(CRAYON_CODE);
|
48 |
-
var nums = jQuery(this).find(CRAYON_NUMS);
|
49 |
-
var nums_content = jQuery(this).find(CRAYON_NUMS_CONTENT);
|
50 |
-
var nums_button = jQuery(this).find(CRAYON_NUMS_BUTTON);
|
51 |
-
var popup_button = jQuery(this).find(CRAYON_POPUP_BUTTON);
|
52 |
-
// Register the objects
|
53 |
-
make_uid(uid);
|
54 |
-
crayon[uid] = jQuery(this);
|
55 |
-
crayon[uid].toolbar = toolbar;
|
56 |
-
crayon[uid].plain = plain;
|
57 |
-
crayon[uid].plain_button = plain_button;
|
58 |
-
crayon[uid].info = info;
|
59 |
-
crayon[uid].main = main;
|
60 |
-
crayon[uid].table = table;
|
61 |
-
crayon[uid].code = code;
|
62 |
-
crayon[uid].nums = nums;
|
63 |
-
crayon[uid].nums_content = nums_content;
|
64 |
-
crayon[uid].nums_button = nums_button;
|
65 |
-
crayon[uid].popup_button = popup_button;
|
66 |
-
crayon[uid].nums_visible = true;
|
67 |
-
crayon[uid].plain_visible = false;
|
68 |
-
|
69 |
-
crayon[uid].toolbar_delay = 0;
|
70 |
-
crayon[uid].time = 1;
|
71 |
-
|
72 |
-
// Set plain
|
73 |
-
jQuery(CRAYON_PLAIN).css('position', 'absolute');
|
74 |
-
jQuery(CRAYON_PLAIN).css('z-index', 0);
|
75 |
-
|
76 |
-
// Remember CSS dimensions
|
77 |
-
var main_style = crayon[uid].main.get(0).style;
|
78 |
-
crayon[uid].main_height = main_style.height;
|
79 |
-
crayon[uid].main_max_height = main_style.maxHeight;
|
80 |
-
crayon[uid].main_min_height = main_style.minHeight;
|
81 |
-
crayon[uid].main_width = main_style.width;
|
82 |
-
crayon[uid].main_max_width = main_style.maxWidth;
|
83 |
-
crayon[uid].main_min_width = main_style.minWidth;
|
84 |
-
|
85 |
-
var load_timer;
|
86 |
-
var last_num_width = nums.width();
|
87 |
-
var i = 0;
|
88 |
-
crayon[uid].loading = true;
|
89 |
-
crayon[uid].scroll_block_fix = false;
|
90 |
-
|
91 |
-
var load_func = function() {
|
92 |
-
if (main.height() < 30) {
|
93 |
-
crayon[uid].scroll_block_fix = true;
|
94 |
-
}
|
95 |
-
|
96 |
-
// If nums hidden by default
|
97 |
-
if (nums.filter('[settings~="hide"]').length != 0) {
|
98 |
-
nums_content.ready(function() {
|
99 |
-
toggle_nums(uid, true, true);
|
100 |
-
});
|
101 |
-
} else {
|
102 |
-
update_nums_button(uid);
|
103 |
-
}
|
104 |
-
|
105 |
-
// TODO If width has changed or timeout, stop timer
|
106 |
-
if (/*last_num_width != nums.width() ||*/ i == 5) {
|
107 |
-
clearInterval(load_timer);
|
108 |
-
crayon[uid].loading = false;
|
109 |
-
}
|
110 |
-
i++;
|
111 |
-
};
|
112 |
-
main.ready(function() {
|
113 |
-
load_timer = setInterval(load_func, 300);
|
114 |
-
});
|
115 |
-
|
116 |
-
// Used for toggling
|
117 |
-
main.css('position', 'relative');
|
118 |
-
main.css('z-index', 1);
|
119 |
-
|
120 |
-
// Disable certain features for touchscreen devices
|
121 |
-
touchscreen = (jQuery(this).filter('[settings~="touchscreen"]').length != 0);
|
122 |
-
|
123 |
-
// Used to hide info
|
124 |
-
if (!touchscreen) {
|
125 |
-
main.click(function() { crayon_info(uid, '', false); });
|
126 |
-
plain.click(function() { crayon_info(uid, '', false); });
|
127 |
-
info.click(function() { crayon_info(uid, '', false); });
|
128 |
-
}
|
129 |
-
|
130 |
-
// Used for code popup
|
131 |
-
crayon[uid].popup_settings = popupWindow(popup_button, {
|
132 |
-
height:screen.height - 200,
|
133 |
-
width:screen.width - 100,
|
134 |
-
top:75,
|
135 |
-
left:50,
|
136 |
-
scrollbars:1,
|
137 |
-
windowURL:'',
|
138 |
-
data:'', // Data overrides URL
|
139 |
-
}, function() {
|
140 |
-
code_popup(uid);
|
141 |
-
}, function() {
|
142 |
-
//alert('after');
|
143 |
-
});
|
144 |
-
|
145 |
-
plain.css('opacity', 0);
|
146 |
-
crayon.toolbar_neg_height = '-' + toolbar.height() + 'px';
|
147 |
-
// If a toolbar with mouseover was found
|
148 |
-
if (toolbar.filter('[settings~="mouseover"]').length != 0 && !touchscreen) {
|
149 |
-
crayon[uid].toolbar_mouseover = true;
|
150 |
-
|
151 |
-
toolbar.css('margin-top', crayon.toolbar_neg_height);
|
152 |
-
toolbar.hide();
|
153 |
-
// Overlay the toolbar if needed, only if doing so will not hide the
|
154 |
-
// whole code!
|
155 |
-
if (toolbar.filter('[settings~="overlay"]').length != 0
|
156 |
-
&& main.height() > toolbar.height() * 2) {
|
157 |
-
toolbar.css('position', 'absolute');
|
158 |
-
toolbar.css('z-index', 2);
|
159 |
-
// Hide on single click when overlayed
|
160 |
-
if (toolbar.filter('[settings~="hide"]').length != 0) {
|
161 |
-
main.click(function() { toolbar_toggle(uid, undefined, undefined, 0); });
|
162 |
-
plain.click(function() { toolbar_toggle(uid, false, undefined, 0); });
|
163 |
-
}
|
164 |
-
} else {
|
165 |
-
toolbar.css('z-index', 4);
|
166 |
-
}
|
167 |
-
// Enable delay on mouseout
|
168 |
-
if (toolbar.filter('[settings~="delay"]').length != 0) {
|
169 |
-
crayon[uid].toolbar_delay = 500;
|
170 |
-
}
|
171 |
-
// Use .hover() for chrome, but in firefox mouseover/mouseout worked best
|
172 |
-
jQuery(this).mouseenter(function() { toolbar_toggle(uid, true); })
|
173 |
-
.mouseleave(function() { toolbar_toggle(uid, false); });
|
174 |
-
|
175 |
-
} else if (touchscreen) {
|
176 |
-
toolbar.show();
|
177 |
-
}
|
178 |
-
// Plain show events
|
179 |
-
if (plain.length != 0 && !touchscreen) {
|
180 |
-
if (plain.filter('[settings~="dblclick"]').length != 0) {
|
181 |
-
main.dblclick(function() { toggle_plain(uid); });
|
182 |
-
} else if (plain.filter('[settings~="click"]').length != 0) {
|
183 |
-
main.click(function() { toggle_plain(uid); });
|
184 |
-
} else if (plain.filter('[settings~="mouseover"]').length != 0) {
|
185 |
-
jQuery(this).mouseenter(function() { toggle_plain(uid, true); })
|
186 |
-
.mouseleave(function() { toggle_plain(uid, false); });
|
187 |
-
nums_button.hide();
|
188 |
-
}
|
189 |
-
}
|
190 |
-
// Scrollbar show events
|
191 |
-
if (!touchscreen && jQuery(this).filter('[settings~="scroll-mouseover"]').length != 0) {
|
192 |
-
// Disable on touchscreen devices and when set to mouseover
|
193 |
-
main.css('overflow', 'hidden');
|
194 |
-
plain.css('overflow', 'hidden');
|
195 |
-
jQuery(this).mouseenter(function() { toggle_scroll(uid, true); })
|
196 |
-
.mouseleave(function() { toggle_scroll(uid, false); });
|
197 |
-
}
|
198 |
-
// Disable animations
|
199 |
-
if ( jQuery(this).filter('[settings~="disable-anim"]').length != 0 ) {
|
200 |
-
crayon[uid].time = 0;
|
201 |
-
}
|
202 |
-
|
203 |
-
// Determine if Mac
|
204 |
-
crayon[uid].mac = (jQuery(this).filter('[crayon-os~="mac"]').length != 0);
|
205 |
-
});
|
206 |
-
}
|
207 |
-
|
208 |
-
function make_uid(uid) {
|
209 |
-
if (typeof crayon[uid] == 'undefined') {
|
210 |
-
crayon[uid] = jQuery('#'+uid);
|
211 |
-
return true;
|
212 |
-
}
|
213 |
-
return false;
|
214 |
-
}
|
215 |
-
|
216 |
-
function code_popup(uid) {
|
217 |
-
if (typeof crayon[uid] == 'undefined') {
|
218 |
-
return make_uid(uid);
|
219 |
-
}
|
220 |
-
var code = crayon[uid].plain_visible ? crayon[uid].plain : crayon[uid].main;
|
221 |
-
var settings = crayon[uid].popup_settings;
|
222 |
-
settings.data = get_all_css() + '<body style="padding:0; margin:0;"><div class="' + crayon[uid].attr('class') +
|
223 |
-
' crayon-popup">' + remove_css_inline(get_jquery_str(code)) + '</div></body>';
|
224 |
-
if (typeof settings == 'undefined') {
|
225 |
-
return;
|
226 |
-
}
|
227 |
-
}
|
228 |
-
|
229 |
-
function get_jquery_str(object) {
|
230 |
-
return jQuery('<div>').append(object.clone()).remove().html();
|
231 |
-
}
|
232 |
-
|
233 |
-
function remove_css_inline(string) {
|
234 |
-
return string.replace(/style\s*=\s*"[^"]+"/mi, '');
|
235 |
-
}
|
236 |
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
246 |
|
247 |
-
|
248 |
-
|
249 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
250 |
}
|
251 |
|
252 |
-
var
|
|
|
|
|
|
|
|
|
|
|
|
|
253 |
|
254 |
-
|
255 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
256 |
|
257 |
-
|
258 |
-
|
259 |
-
crayon_info(uid, text);
|
260 |
-
}
|
261 |
-
|
262 |
-
function crayon_info(uid, text, show) {
|
263 |
-
if (typeof crayon[uid] == 'undefined') {
|
264 |
-
return make_uid(uid);
|
265 |
}
|
266 |
|
267 |
-
var
|
|
|
|
|
268 |
|
269 |
-
|
270 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
271 |
}
|
272 |
-
|
273 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
274 |
}
|
275 |
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
282 |
crayon_slide(uid, info, false);
|
283 |
-
}
|
284 |
-
}
|
285 |
|
286 |
-
if (!show) {
|
287 |
-
crayon_slide(uid, info, false);
|
288 |
}
|
289 |
-
|
290 |
-
}
|
291 |
-
|
292 |
-
function crayon_is_slide_hidden(object) {
|
293 |
-
var object_neg_height = '-' + object.height() + 'px';
|
294 |
-
if (object.css('margin-top') == object_neg_height || object.css('display') == 'none') {
|
295 |
-
return true;
|
296 |
-
} else {
|
297 |
-
return false;
|
298 |
-
}
|
299 |
-
}
|
300 |
-
|
301 |
-
function crayon_slide(uid, object, show, anim_time, hide_delay) {
|
302 |
-
var object_neg_height = '-' + object.height() + 'px';
|
303 |
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
// Instant means no time delay for showing/hiding
|
312 |
-
if (typeof anim_time == 'undefined') {
|
313 |
-
anim_time = 100;
|
314 |
-
}
|
315 |
-
if (anim_time == false) {
|
316 |
-
anim_time = false;
|
317 |
-
}
|
318 |
-
if (typeof hide_delay== 'undefined') {
|
319 |
-
hide_delay = 0;
|
320 |
-
}
|
321 |
-
object.stop(true);
|
322 |
-
if (show == true) {
|
323 |
-
object.show();
|
324 |
-
object.animate({
|
325 |
-
marginTop: 0
|
326 |
-
}, animt(anim_time, uid));
|
327 |
-
} else if (show == false) {
|
328 |
-
// Delay if fully visible
|
329 |
-
if (/*instant == false && */object.css('margin-top') == '0px' && hide_delay) {
|
330 |
-
object.delay(hide_delay);
|
331 |
-
}
|
332 |
-
object.animate({
|
333 |
-
marginTop: object_neg_height
|
334 |
-
}, animt(anim_time, uid), function() {
|
335 |
-
object.hide();
|
336 |
-
});
|
337 |
-
}
|
338 |
-
}
|
339 |
-
|
340 |
-
function toggle_plain(uid, hover, select) {
|
341 |
-
if (typeof crayon[uid] == 'undefined') {
|
342 |
-
return make_uid(uid);
|
343 |
}
|
344 |
-
|
345 |
-
var main = crayon[uid].main;
|
346 |
-
var plain = crayon[uid].plain;
|
347 |
-
var plain_button = crayon[uid].plain_button;
|
348 |
-
|
349 |
-
// Reconsile height
|
350 |
-
plain.height(main.height());
|
351 |
-
plain.width(main.width());
|
352 |
-
|
353 |
-
if ( (main.is(':animated') || plain.is(':animated')) && typeof hover == 'undefined' ) {
|
354 |
-
return;
|
355 |
-
}
|
356 |
-
|
357 |
-
var visible, hidden;
|
358 |
-
if (typeof hover != 'undefined') {
|
359 |
-
if (hover) {
|
360 |
-
visible = main;
|
361 |
-
hidden = plain;
|
362 |
-
//crayon[uid].plain_visible = true;
|
363 |
-
} else {
|
364 |
-
visible = plain;
|
365 |
-
hidden = main;
|
366 |
-
}
|
367 |
-
} else {
|
368 |
-
if (main.css('z-index') == 1) {
|
369 |
-
visible = main;
|
370 |
-
hidden = plain;
|
371 |
-
//crayon[uid].plain_visible = true;
|
372 |
-
} else {
|
373 |
-
visible = plain;
|
374 |
-
hidden = main;
|
375 |
-
//crayon[uid].plain_visible = false;
|
376 |
-
}
|
377 |
-
}
|
378 |
-
|
379 |
-
crayon[uid].plain_visible = (hidden == plain);
|
380 |
-
|
381 |
-
// Remember scroll positions of visible
|
382 |
-
crayon[uid].top = visible.scrollTop();
|
383 |
-
crayon[uid].left = visible.scrollLeft();
|
384 |
-
|
385 |
-
/* Used to detect a change in overflow when the mouse moves out
|
386 |
-
* of the Crayon. If it does, then overflow has already been changed,
|
387 |
-
* no need to revert it after toggling plain. */
|
388 |
-
crayon[uid].scroll_changed = false;
|
389 |
|
390 |
-
var
|
391 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
392 |
|
393 |
-
|
394 |
-
|
395 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
396 |
|
397 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
398 |
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
hidden.scrollTop(crayon[uid].top);
|
419 |
-
hidden.scrollLeft(crayon[uid].left + 1);
|
420 |
-
hidden.scrollLeft(crayon[uid].left);
|
421 |
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
445 |
}
|
446 |
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
452 |
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
|
|
|
|
|
|
|
|
|
|
460 |
}
|
|
|
|
|
|
|
|
|
|
|
461 |
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
crayon[uid].table.css('margin-left', '0px');
|
471 |
-
crayon[uid].nums_visible = false;
|
472 |
-
num_margin = neg_width;
|
473 |
-
table_width += nums_width;
|
474 |
-
}
|
475 |
-
|
476 |
-
if (typeof instant != 'undefined') {
|
477 |
-
crayon[uid].table.css('margin-left', num_margin);
|
478 |
-
crayon[uid].table.width(table_width);
|
479 |
-
update_nums_button(uid);
|
480 |
-
return;
|
481 |
-
}
|
482 |
-
|
483 |
-
// Stop jerking animation from scrollbar appearing for a split second due to
|
484 |
-
// change in width. Prevents scrollbar disappearing if already visible.
|
485 |
-
h_scroll_visible = (crayon[uid].table.width() + px_to_int(crayon[uid].table.css('margin-left')) > crayon[uid].main.width());
|
486 |
-
v_scroll_visible = (crayon[uid].table.height() > crayon[uid].main.height());
|
487 |
-
if (!h_scroll_visible && !v_scroll_visible) {
|
488 |
-
crayon[uid].main.css('overflow', 'hidden');
|
489 |
-
}
|
490 |
-
crayon[uid].table.animate({
|
491 |
-
marginLeft: num_margin,
|
492 |
-
width: table_width
|
493 |
-
}, animt(200, uid), function() {
|
494 |
-
if (typeof crayon[uid] != 'undefined') {
|
495 |
-
update_nums_button(uid);
|
496 |
-
if (!h_scroll_visible && !v_scroll_visible) {
|
497 |
-
crayon[uid].main.css('overflow', 'auto');
|
498 |
-
}
|
499 |
-
}
|
500 |
-
});
|
501 |
-
}
|
502 |
-
|
503 |
-
// Convert '-10px' to -10
|
504 |
-
function px_to_int(pixels) {
|
505 |
-
if (typeof pixels != 'string') {
|
506 |
-
return 0;
|
507 |
}
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
}
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
} else {
|
524 |
-
// TODO doesn't work on iPhone
|
525 |
-
crayon[uid].nums_button.removeClass(PRESSED);
|
526 |
-
crayon[uid].nums_button.addClass(UNPRESSED);
|
527 |
}
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
533 |
}
|
534 |
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
crayon[uid].
|
|
|
|
|
|
|
542 |
}
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
}
|
557 |
-
|
558 |
-
crayon_slide(uid, toolbar, show, anim_time, hide_delay);
|
559 |
-
}
|
560 |
-
|
561 |
-
function toggle_scroll(uid, show) {
|
562 |
-
if (typeof crayon[uid] == 'undefined') {
|
563 |
-
return make_uid(uid);
|
564 |
}
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
var main = crayon[uid].main;
|
570 |
-
var plain = crayon[uid].plain;
|
571 |
-
|
572 |
-
if (show) {
|
573 |
-
main.css('overflow', 'auto');
|
574 |
-
plain.css('overflow', 'auto');
|
575 |
-
if (typeof crayon[uid].top != 'undefined') {
|
576 |
-
visible = (main.css('z-index') == 1 ? main : plain);
|
577 |
-
// Browser will not render until scrollbar moves, move it manually
|
578 |
-
visible.scrollTop(crayon[uid].top-1);
|
579 |
-
visible.scrollTop(crayon[uid].top);
|
580 |
-
visible.scrollLeft(crayon[uid].left-1);
|
581 |
-
visible.scrollLeft(crayon[uid].left);
|
582 |
-
}
|
583 |
-
if (!crayon[uid].scroll_block_fix) {
|
584 |
-
// Fix dimensions so scrollbars stay inside
|
585 |
-
main.css('height', main.height());
|
586 |
-
main.css('width', main.width());
|
587 |
-
} else {
|
588 |
-
// Relax dimensions so scrollbars are visible
|
589 |
-
main.css('height', '');
|
590 |
-
main.css('max-height', '');
|
591 |
-
main.css('min-height', '');
|
592 |
-
main.css('width', '');
|
593 |
-
}
|
594 |
-
} else {
|
595 |
-
visible = (main.css('z-index') == 1 ? main : plain);
|
596 |
-
crayon[uid].top = visible.scrollTop();
|
597 |
-
crayon[uid].left = visible.scrollLeft();
|
598 |
-
main.css('overflow', 'hidden');
|
599 |
-
plain.css('overflow', 'hidden');
|
600 |
-
if (!crayon[uid].scroll_block_fix) {
|
601 |
-
// Restore dimensions
|
602 |
-
main.css('height', crayon[uid].main_height);
|
603 |
-
main.css('max-height', crayon[uid].main_max_height);
|
604 |
-
main.css('min-height', crayon[uid].main_min_height);
|
605 |
-
main.css('width', crayon[uid].main_width);
|
606 |
-
}
|
607 |
-
}
|
608 |
-
// Register that overflow has changed
|
609 |
-
crayon[uid].scroll_changed = true;
|
610 |
-
fix_scroll_blank(uid);
|
611 |
-
}
|
612 |
-
|
613 |
-
/* Fix weird draw error, causes blank area to appear where scrollbar once was. */
|
614 |
-
function fix_scroll_blank(uid) {
|
615 |
-
if (typeof crayon[uid] == 'undefined') {
|
616 |
-
return make_uid(uid);
|
617 |
}
|
618 |
-
|
619 |
-
crayon[uid].main.width(width);
|
620 |
-
crayon[uid].main.width(width - 1);
|
621 |
-
crayon[uid].main.width(width + 1);
|
622 |
-
crayon[uid].main.width(width);
|
623 |
-
}
|
624 |
-
|
625 |
-
function animt(x, uid) {
|
626 |
-
if (x == 'fast') {
|
627 |
-
x = 200;
|
628 |
-
} else if (x == 'slow') {
|
629 |
-
x = 600;
|
630 |
-
} else if (!isNumber(x)) {
|
631 |
-
x = parseInt(x);
|
632 |
-
if (isNaN(x)) {
|
633 |
-
return 0;
|
634 |
-
}
|
635 |
-
}
|
636 |
-
return x * crayon[uid].time;
|
637 |
-
}
|
638 |
-
|
639 |
-
function isNumber(x) {
|
640 |
-
return typeof x == 'number';
|
641 |
}
|
642 |
|
643 |
// -->
|
8 |
|
9 |
// jQuery
|
10 |
|
11 |
+
// jQuery.noConflict();
|
12 |
|
13 |
var PRESSED = 'crayon-pressed';
|
14 |
var UNPRESSED = '';
|
27 |
var CRAYON_POPUP_BUTTON = '.crayon-popup-button';
|
28 |
|
29 |
jQuery(document).ready(function() {
|
30 |
+
CrayonSyntax.init();
|
31 |
});
|
32 |
|
33 |
+
var CrayonSyntax = new function() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
|
35 |
+
var crayon = new Object();
|
36 |
+
|
37 |
+
this.init = function() {
|
38 |
+
if (typeof crayon == 'undefined') {
|
39 |
+
crayon = new Object();
|
40 |
+
}
|
41 |
+
|
42 |
+
jQuery(CRAYON_SYNTAX).each(function() {
|
43 |
+
var uid = jQuery(this).attr('id');
|
44 |
+
var toolbar = jQuery(this).find(CRAYON_TOOLBAR);
|
45 |
+
var info = jQuery(this).find(CRAYON_INFO);
|
46 |
+
var plain = jQuery(this).find(CRAYON_PLAIN);
|
47 |
+
var plain_button = jQuery(this).find(CRAYON_PLAIN_BUTTON);
|
48 |
+
var main = jQuery(this).find(CRAYON_MAIN);
|
49 |
+
var table = jQuery(this).find(CRAYON_TABLE);
|
50 |
+
var code = jQuery(this).find(CRAYON_CODE);
|
51 |
+
var nums = jQuery(this).find(CRAYON_NUMS);
|
52 |
+
var nums_content = jQuery(this).find(CRAYON_NUMS_CONTENT);
|
53 |
+
var nums_button = jQuery(this).find(CRAYON_NUMS_BUTTON);
|
54 |
+
var popup_button = jQuery(this).find(CRAYON_POPUP_BUTTON);
|
55 |
+
// Register the objects
|
56 |
+
make_uid(uid);
|
57 |
+
crayon[uid] = jQuery(this);
|
58 |
+
crayon[uid].toolbar = toolbar;
|
59 |
+
crayon[uid].plain = plain;
|
60 |
+
crayon[uid].plain_button = plain_button;
|
61 |
+
crayon[uid].info = info;
|
62 |
+
crayon[uid].main = main;
|
63 |
+
crayon[uid].table = table;
|
64 |
+
crayon[uid].code = code;
|
65 |
+
crayon[uid].nums = nums;
|
66 |
+
crayon[uid].nums_content = nums_content;
|
67 |
+
crayon[uid].nums_button = nums_button;
|
68 |
+
crayon[uid].popup_button = popup_button;
|
69 |
+
crayon[uid].nums_visible = true;
|
70 |
+
crayon[uid].plain_visible = false;
|
71 |
+
|
72 |
+
crayon[uid].toolbar_delay = 0;
|
73 |
+
crayon[uid].time = 1;
|
74 |
+
|
75 |
+
// Set plain
|
76 |
+
jQuery(CRAYON_PLAIN).css('position', 'absolute');
|
77 |
+
jQuery(CRAYON_PLAIN).css('z-index', 0);
|
78 |
+
|
79 |
+
// Remember CSS dimensions
|
80 |
+
var main_style = crayon[uid].main.get(0).style;
|
81 |
+
crayon[uid].main_height = main_style.height;
|
82 |
+
crayon[uid].main_max_height = main_style.maxHeight;
|
83 |
+
crayon[uid].main_min_height = main_style.minHeight;
|
84 |
+
crayon[uid].main_width = main_style.width;
|
85 |
+
crayon[uid].main_max_width = main_style.maxWidth;
|
86 |
+
crayon[uid].main_min_width = main_style.minWidth;
|
87 |
+
|
88 |
+
var load_timer;
|
89 |
+
var last_num_width = nums.width();
|
90 |
+
var i = 0;
|
91 |
+
crayon[uid].loading = true;
|
92 |
+
crayon[uid].scroll_block_fix = false;
|
93 |
+
|
94 |
+
var load_func = function() {
|
95 |
+
if (main.height() < 30) {
|
96 |
+
crayon[uid].scroll_block_fix = true;
|
97 |
+
}
|
98 |
+
|
99 |
+
// If nums hidden by default
|
100 |
+
if (nums.filter('[settings~="hide"]').length != 0) {
|
101 |
+
nums_content.ready(function() {
|
102 |
+
CrayonSyntax.toggle_nums(uid, true, true);
|
103 |
+
});
|
104 |
+
} else {
|
105 |
+
update_nums_button(uid);
|
106 |
+
}
|
107 |
+
|
108 |
+
// TODO If width has changed or timeout, stop timer
|
109 |
+
if (/*last_num_width != nums.width() ||*/ i == 5) {
|
110 |
+
clearInterval(load_timer);
|
111 |
+
crayon[uid].loading = false;
|
112 |
+
}
|
113 |
+
i++;
|
114 |
+
};
|
115 |
+
main.ready(function() {
|
116 |
+
load_timer = setInterval(load_func, 300);
|
117 |
+
});
|
118 |
+
|
119 |
+
// Used for toggling
|
120 |
+
main.css('position', 'relative');
|
121 |
+
main.css('z-index', 1);
|
122 |
+
|
123 |
+
// Disable certain features for touchscreen devices
|
124 |
+
touchscreen = (jQuery(this).filter('[settings~="touchscreen"]').length != 0);
|
125 |
+
|
126 |
+
// Used to hide info
|
127 |
+
if (!touchscreen) {
|
128 |
+
main.click(function() { crayon_info(uid, '', false); });
|
129 |
+
plain.click(function() { crayon_info(uid, '', false); });
|
130 |
+
info.click(function() { crayon_info(uid, '', false); });
|
131 |
+
}
|
132 |
+
|
133 |
+
// Used for code popup
|
134 |
+
crayon[uid].popup_settings = popupWindow(popup_button, {
|
135 |
+
height:screen.height - 200,
|
136 |
+
width:screen.width - 100,
|
137 |
+
top:75,
|
138 |
+
left:50,
|
139 |
+
scrollbars:1,
|
140 |
+
windowURL:'',
|
141 |
+
data:'', // Data overrides URL
|
142 |
+
}, function() {
|
143 |
+
code_popup(uid);
|
144 |
+
}, function() {
|
145 |
+
//alert('after');
|
146 |
+
});
|
147 |
|
148 |
+
plain.css('opacity', 0);
|
149 |
+
crayon.toolbar_neg_height = '-' + toolbar.height() + 'px';
|
150 |
+
// If a toolbar with mouseover was found
|
151 |
+
if (toolbar.filter('[settings~="mouseover"]').length != 0 && !touchscreen) {
|
152 |
+
crayon[uid].toolbar_mouseover = true;
|
153 |
+
|
154 |
+
toolbar.css('margin-top', crayon.toolbar_neg_height);
|
155 |
+
toolbar.hide();
|
156 |
+
// Overlay the toolbar if needed, only if doing so will not hide the
|
157 |
+
// whole code!
|
158 |
+
if (toolbar.filter('[settings~="overlay"]').length != 0
|
159 |
+
&& main.height() > toolbar.height() * 2) {
|
160 |
+
toolbar.css('position', 'absolute');
|
161 |
+
toolbar.css('z-index', 2);
|
162 |
+
// Hide on single click when overlayed
|
163 |
+
if (toolbar.filter('[settings~="hide"]').length != 0) {
|
164 |
+
main.click(function() { toolbar_toggle(uid, undefined, undefined, 0); });
|
165 |
+
plain.click(function() { toolbar_toggle(uid, false, undefined, 0); });
|
166 |
+
}
|
167 |
+
} else {
|
168 |
+
toolbar.css('z-index', 4);
|
169 |
+
}
|
170 |
+
// Enable delay on mouseout
|
171 |
+
if (toolbar.filter('[settings~="delay"]').length != 0) {
|
172 |
+
crayon[uid].toolbar_delay = 500;
|
173 |
+
}
|
174 |
+
// Use .hover() for chrome, but in firefox mouseover/mouseout worked best
|
175 |
+
jQuery(this).mouseenter(function() { toolbar_toggle(uid, true); })
|
176 |
+
.mouseleave(function() { toolbar_toggle(uid, false); });
|
177 |
+
|
178 |
+
} else if (touchscreen) {
|
179 |
+
toolbar.show();
|
180 |
+
}
|
181 |
+
// Plain show events
|
182 |
+
if (plain.length != 0 && !touchscreen) {
|
183 |
+
if (plain.filter('[settings~="dblclick"]').length != 0) {
|
184 |
+
main.dblclick(function() { CrayonSyntax.toggle_plain(uid); });
|
185 |
+
} else if (plain.filter('[settings~="click"]').length != 0) {
|
186 |
+
main.click(function() { CrayonSyntax.toggle_plain(uid); });
|
187 |
+
} else if (plain.filter('[settings~="mouseover"]').length != 0) {
|
188 |
+
jQuery(this).mouseenter(function() { CrayonSyntax.toggle_plain(uid, true); })
|
189 |
+
.mouseleave(function() { CrayonSyntax.toggle_plain(uid, false); });
|
190 |
+
nums_button.hide();
|
191 |
+
}
|
192 |
+
}
|
193 |
+
// Scrollbar show events
|
194 |
+
if (!touchscreen && jQuery(this).filter('[settings~="scroll-mouseover"]').length != 0) {
|
195 |
+
// Disable on touchscreen devices and when set to mouseover
|
196 |
+
main.css('overflow', 'hidden');
|
197 |
+
plain.css('overflow', 'hidden');
|
198 |
+
jQuery(this).mouseenter(function() { toggle_scroll(uid, true); })
|
199 |
+
.mouseleave(function() { toggle_scroll(uid, false); });
|
200 |
+
}
|
201 |
+
// Disable animations
|
202 |
+
if ( jQuery(this).filter('[settings~="disable-anim"]').length != 0 ) {
|
203 |
+
crayon[uid].time = 0;
|
204 |
+
}
|
205 |
+
|
206 |
+
// Determine if Mac
|
207 |
+
crayon[uid].mac = (jQuery(this).filter('[crayon-os~="mac"]').length != 0);
|
208 |
+
});
|
209 |
}
|
210 |
|
211 |
+
var make_uid = function(uid) {
|
212 |
+
if (typeof crayon[uid] == 'undefined') {
|
213 |
+
crayon[uid] = jQuery('#'+uid);
|
214 |
+
return true;
|
215 |
+
}
|
216 |
+
return false;
|
217 |
+
}
|
218 |
|
219 |
+
var code_popup = function(uid) {
|
220 |
+
if (typeof crayon[uid] == 'undefined') {
|
221 |
+
return make_uid(uid);
|
222 |
+
}
|
223 |
+
var code = crayon[uid].plain_visible ? crayon[uid].plain : crayon[uid].main;
|
224 |
+
var settings = crayon[uid].popup_settings;
|
225 |
+
settings.data = get_all_css() + '<body style="padding:0; margin:0;"><div class="' + crayon[uid].attr('class') +
|
226 |
+
' crayon-popup">' + remove_css_inline(get_jquery_str(code)) + '</div></body>';
|
227 |
+
if (typeof settings == 'undefined') {
|
228 |
+
return;
|
229 |
+
}
|
230 |
+
}
|
231 |
|
232 |
+
var get_jquery_str = function(object) {
|
233 |
+
return jQuery('<div>').append(object.clone()).remove().html();
|
|
|
|
|
|
|
|
|
|
|
|
|
234 |
}
|
235 |
|
236 |
+
var remove_css_inline = function(string) {
|
237 |
+
return string.replace(/style\s*=\s*"[^"]+"/mi, '');
|
238 |
+
}
|
239 |
|
240 |
+
// Get all CSS on the page as a string
|
241 |
+
var get_all_css = function() {
|
242 |
+
var css_str = ''
|
243 |
+
css = jQuery('link[rel="stylesheet"]').each(function() {
|
244 |
+
var string = get_jquery_str(jQuery(this));
|
245 |
+
css_str += string;
|
246 |
+
});
|
247 |
+
return css_str;
|
248 |
}
|
249 |
+
|
250 |
+
this.copy_plain = function(uid, hover) {
|
251 |
+
if (typeof crayon[uid] == 'undefined') {
|
252 |
+
return make_uid(uid);
|
253 |
+
}
|
254 |
+
|
255 |
+
var plain = crayon[uid].plain;
|
256 |
+
|
257 |
+
CrayonSyntax.toggle_plain(uid, true, true);
|
258 |
+
toolbar_toggle(uid, true);
|
259 |
+
|
260 |
+
key = crayon[uid].mac ? '\u2318' : 'CTRL';
|
261 |
+
text = 'Press ' + key + '+C to Copy, ' + key + '+P to Paste :)';
|
262 |
+
crayon_info(uid, text);
|
263 |
}
|
264 |
|
265 |
+
var crayon_info = function(uid, text, show) {
|
266 |
+
if (typeof crayon[uid] == 'undefined') {
|
267 |
+
return make_uid(uid);
|
268 |
+
}
|
269 |
+
|
270 |
+
var info = crayon[uid].info;
|
271 |
+
|
272 |
+
if (typeof text == 'undefined') {
|
273 |
+
text = '';
|
274 |
+
}
|
275 |
+
if (typeof show == 'undefined') {
|
276 |
+
show = true;
|
277 |
+
}
|
278 |
+
|
279 |
+
if (crayon_is_slide_hidden(info) && show) {
|
280 |
+
info.html('<div>' + text + '</div>');
|
281 |
+
info.css('margin-top', -info.height());
|
282 |
+
info.show();
|
283 |
+
crayon_slide(uid, info, true);
|
284 |
+
setTimeout(function() {
|
285 |
+
crayon_slide(uid, info, false);
|
286 |
+
}, 5000);
|
287 |
+
}
|
288 |
+
|
289 |
+
if (!show) {
|
290 |
crayon_slide(uid, info, false);
|
291 |
+
}
|
|
|
292 |
|
|
|
|
|
293 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
294 |
|
295 |
+
var crayon_is_slide_hidden = function(object) {
|
296 |
+
var object_neg_height = '-' + object.height() + 'px';
|
297 |
+
if (object.css('margin-top') == object_neg_height || object.css('display') == 'none') {
|
298 |
+
return true;
|
299 |
+
} else {
|
300 |
+
return false;
|
301 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
302 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
303 |
|
304 |
+
var crayon_slide = function(uid, object, show, anim_time, hide_delay) {
|
305 |
+
var object_neg_height = '-' + object.height() + 'px';
|
306 |
+
|
307 |
+
if (typeof show == 'undefined') {
|
308 |
+
if (crayon_is_slide_hidden(object)) {
|
309 |
+
show = true;
|
310 |
+
} else {
|
311 |
+
show = false;
|
312 |
+
}
|
313 |
+
}
|
314 |
+
// Instant means no time delay for showing/hiding
|
315 |
+
if (typeof anim_time == 'undefined') {
|
316 |
+
anim_time = 100;
|
317 |
+
}
|
318 |
+
if (anim_time == false) {
|
319 |
+
anim_time = false;
|
320 |
+
}
|
321 |
+
if (typeof hide_delay== 'undefined') {
|
322 |
+
hide_delay = 0;
|
323 |
+
}
|
324 |
+
object.stop(true);
|
325 |
+
if (show == true) {
|
326 |
+
object.show();
|
327 |
+
object.animate({
|
328 |
+
marginTop: 0
|
329 |
+
}, animt(anim_time, uid));
|
330 |
+
} else if (show == false) {
|
331 |
+
// Delay if fully visible
|
332 |
+
if (/*instant == false && */object.css('margin-top') == '0px' && hide_delay) {
|
333 |
+
object.delay(hide_delay);
|
334 |
+
}
|
335 |
+
object.animate({
|
336 |
+
marginTop: object_neg_height
|
337 |
+
}, animt(anim_time, uid), function() {
|
338 |
+
object.hide();
|
339 |
+
});
|
340 |
+
}
|
341 |
+
}
|
342 |
|
343 |
+
this.toggle_plain = function(uid, hover, select) {
|
344 |
+
if (typeof crayon[uid] == 'undefined') {
|
345 |
+
return make_uid(uid);
|
346 |
+
}
|
347 |
+
|
348 |
+
var main = crayon[uid].main;
|
349 |
+
var plain = crayon[uid].plain;
|
350 |
+
var plain_button = crayon[uid].plain_button;
|
351 |
+
|
352 |
+
// Reconsile height
|
353 |
+
plain.height(main.height());
|
354 |
+
plain.width(main.width());
|
355 |
|
356 |
+
if ( (main.is(':animated') || plain.is(':animated')) && typeof hover == 'undefined' ) {
|
357 |
+
return;
|
358 |
+
}
|
359 |
+
|
360 |
+
var visible, hidden;
|
361 |
+
if (typeof hover != 'undefined') {
|
362 |
+
if (hover) {
|
363 |
+
visible = main;
|
364 |
+
hidden = plain;
|
365 |
+
//crayon[uid].plain_visible = true;
|
366 |
+
} else {
|
367 |
+
visible = plain;
|
368 |
+
hidden = main;
|
369 |
+
}
|
370 |
+
} else {
|
371 |
+
if (main.css('z-index') == 1) {
|
372 |
+
visible = main;
|
373 |
+
hidden = plain;
|
374 |
+
//crayon[uid].plain_visible = true;
|
375 |
+
} else {
|
376 |
+
visible = plain;
|
377 |
+
hidden = main;
|
378 |
+
//crayon[uid].plain_visible = false;
|
379 |
+
}
|
380 |
+
}
|
381 |
+
|
382 |
+
crayon[uid].plain_visible = (hidden == plain);
|
383 |
+
|
384 |
+
// Remember scroll positions of visible
|
385 |
+
crayon[uid].top = visible.scrollTop();
|
386 |
+
crayon[uid].left = visible.scrollLeft();
|
387 |
+
|
388 |
+
/* Used to detect a change in overflow when the mouse moves out
|
389 |
+
* of the Crayon. If it does, then overflow has already been changed,
|
390 |
+
* no need to revert it after toggling plain. */
|
391 |
+
crayon[uid].scroll_changed = false;
|
392 |
+
|
393 |
+
var vis_over = visible.css('overflow');
|
394 |
+
var hid_over = hidden.css('overflow');
|
395 |
+
|
396 |
+
// Hide scrollbars during toggle to avoid Chrome weird draw error
|
397 |
+
visible.css('overflow', 'hidden');
|
398 |
+
hidden.css('overflow', 'hidden');
|
399 |
+
|
400 |
+
fix_scroll_blank(uid);
|
401 |
+
|
402 |
+
// Show hidden, hide visible
|
403 |
+
visible.stop(true);
|
404 |
+
visible.fadeTo(animt(500, uid), 0,
|
405 |
+
function() {
|
406 |
+
visible.css('z-index', 0);
|
407 |
+
if (!crayon[uid].scroll_changed) {
|
408 |
+
visible.css('overflow', vis_over);
|
409 |
+
}
|
410 |
+
});
|
411 |
+
hidden.stop(true);
|
412 |
+
hidden.fadeTo(animt(500, uid), 1,
|
413 |
+
function() {
|
414 |
+
hidden.css('z-index', 1);
|
415 |
+
if (!crayon[uid].scroll_changed) {
|
416 |
+
hidden.css('overflow', hid_over);
|
417 |
+
}
|
418 |
+
|
419 |
+
// Refresh scrollbar draw
|
420 |
+
hidden.scrollTop(crayon[uid].top + 1);
|
421 |
+
hidden.scrollTop(crayon[uid].top);
|
422 |
+
hidden.scrollLeft(crayon[uid].left + 1);
|
423 |
+
hidden.scrollLeft(crayon[uid].left);
|
424 |
+
|
425 |
+
// Give focus to plain code
|
426 |
+
if (hidden == plain) {
|
427 |
+
if (select) {
|
428 |
+
plain.select();
|
429 |
+
} else {
|
430 |
+
plain.focus();
|
431 |
+
}
|
432 |
+
}
|
433 |
+
});
|
434 |
+
|
435 |
+
// Restore scroll positions to hidden
|
436 |
+
hidden.scrollTop(crayon[uid].top);
|
437 |
+
hidden.scrollLeft(crayon[uid].left);
|
438 |
+
|
439 |
+
update_plain_button(uid);
|
440 |
+
|
441 |
+
// Hide toolbar if possible
|
442 |
+
toolbar_toggle(uid, false);
|
443 |
+
}
|
444 |
|
445 |
+
this.toggle_nums = function(uid, hide, instant) {
|
446 |
+
if (typeof crayon[uid] == 'undefined') {
|
447 |
+
return make_uid(uid);
|
448 |
+
}
|
449 |
+
|
450 |
+
if (crayon[uid].table.is(':animated')) {
|
451 |
+
return;
|
452 |
+
}
|
453 |
+
var nums_width = Math.round(crayon[uid].nums_content.width() + 1);
|
454 |
+
var neg_width = '-' + nums_width + 'px';
|
455 |
+
|
456 |
+
// Force hiding
|
457 |
+
var num_hidden;
|
458 |
+
if (typeof hide != 'undefined') {
|
459 |
+
num_hidden = false;
|
460 |
+
} else {
|
461 |
+
// Check hiding
|
462 |
+
num_hidden = (crayon[uid].table.css('margin-left') == neg_width);
|
463 |
+
}
|
|
|
|
|
|
|
464 |
|
465 |
+
var num_margin;
|
466 |
+
var table_width = crayon[uid].main.width();
|
467 |
+
if (num_hidden) {
|
468 |
+
// Show
|
469 |
+
num_margin = '0px';
|
470 |
+
crayon[uid].nums_visible = true;
|
471 |
+
} else {
|
472 |
+
// Hide
|
473 |
+
crayon[uid].table.css('margin-left', '0px');
|
474 |
+
crayon[uid].nums_visible = false;
|
475 |
+
num_margin = neg_width;
|
476 |
+
table_width += nums_width;
|
477 |
+
}
|
478 |
+
|
479 |
+
if (typeof instant != 'undefined') {
|
480 |
+
crayon[uid].table.css('margin-left', num_margin);
|
481 |
+
crayon[uid].table.width(table_width);
|
482 |
+
update_nums_button(uid);
|
483 |
+
return;
|
484 |
+
}
|
485 |
+
|
486 |
+
// Stop jerking animation from scrollbar appearing for a split second due to
|
487 |
+
// change in width. Prevents scrollbar disappearing if already visible.
|
488 |
+
h_scroll_visible = (crayon[uid].table.width() + px_to_int(crayon[uid].table.css('margin-left')) > crayon[uid].main.width());
|
489 |
+
v_scroll_visible = (crayon[uid].table.height() > crayon[uid].main.height());
|
490 |
+
if (!h_scroll_visible && !v_scroll_visible) {
|
491 |
+
crayon[uid].main.css('overflow', 'hidden');
|
492 |
+
}
|
493 |
+
crayon[uid].table.animate({
|
494 |
+
marginLeft: num_margin,
|
495 |
+
width: table_width
|
496 |
+
}, animt(200, uid), function() {
|
497 |
+
if (typeof crayon[uid] != 'undefined') {
|
498 |
+
update_nums_button(uid);
|
499 |
+
if (!h_scroll_visible && !v_scroll_visible) {
|
500 |
+
crayon[uid].main.css('overflow', 'auto');
|
501 |
+
}
|
502 |
+
}
|
503 |
+
});
|
504 |
}
|
505 |
|
506 |
+
// Convert '-10px' to -10
|
507 |
+
var px_to_int = function(pixels) {
|
508 |
+
if (typeof pixels != 'string') {
|
509 |
+
return 0;
|
510 |
+
}
|
511 |
+
var result = pixels.replace(/[^-0-9]/g, '');
|
512 |
+
if (result.length == 0) {
|
513 |
+
return 0;
|
514 |
+
} else {
|
515 |
+
return parseInt(result);
|
516 |
+
}
|
517 |
+
}
|
518 |
|
519 |
+
var update_nums_button = function(uid) {
|
520 |
+
if (typeof crayon[uid] == 'undefined' || typeof crayon[uid].nums_visible == 'undefined') {
|
521 |
+
return;
|
522 |
+
}
|
523 |
+
if (crayon[uid].nums_visible) {
|
524 |
+
crayon[uid].nums_button.removeClass(UNPRESSED);
|
525 |
+
crayon[uid].nums_button.addClass(PRESSED);
|
526 |
+
} else {
|
527 |
+
// TODO doesn't work on iPhone
|
528 |
+
crayon[uid].nums_button.removeClass(PRESSED);
|
529 |
+
crayon[uid].nums_button.addClass(UNPRESSED);
|
530 |
+
}
|
531 |
}
|
532 |
+
|
533 |
+
var update_plain_button = function(uid) {
|
534 |
+
if (typeof crayon[uid] == 'undefined' || typeof crayon[uid].plain_visible == 'undefined') {
|
535 |
+
return;
|
536 |
+
}
|
537 |
|
538 |
+
if (crayon[uid].plain_visible) {
|
539 |
+
crayon[uid].plain_button.removeClass(UNPRESSED);
|
540 |
+
crayon[uid].plain_button.addClass(PRESSED);
|
541 |
+
} else {
|
542 |
+
// TODO doesn't work on iPhone
|
543 |
+
crayon[uid].plain_button.removeClass(PRESSED);
|
544 |
+
crayon[uid].plain_button.addClass(UNPRESSED);
|
545 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
546 |
}
|
547 |
+
|
548 |
+
var toolbar_toggle = function(uid, show, anim_time, hide_delay) {
|
549 |
+
if (typeof crayon[uid] == 'undefined') {
|
550 |
+
return make_uid(uid);
|
551 |
+
} else if (!crayon[uid].toolbar_mouseover) {
|
552 |
+
return;
|
553 |
+
}
|
554 |
+
var toolbar = crayon[uid].toolbar;
|
555 |
+
var delay = crayon[uid].toolbar_delay;
|
556 |
+
|
557 |
+
if (typeof hide_delay == 'undefined') {
|
558 |
+
hide_delay = crayon[uid].toolbar_delay;
|
559 |
+
}
|
560 |
+
|
561 |
+
crayon_slide(uid, toolbar, show, anim_time, hide_delay);
|
|
|
|
|
|
|
|
|
562 |
}
|
563 |
+
|
564 |
+
var toggle_scroll = function(uid, show) {
|
565 |
+
if (typeof crayon[uid] == 'undefined') {
|
566 |
+
return make_uid(uid);
|
567 |
+
}
|
568 |
+
if (typeof show == 'undefined' /*|| crayon[uid].loading*/) {
|
569 |
+
return;
|
570 |
+
}
|
571 |
+
|
572 |
+
var main = crayon[uid].main;
|
573 |
+
var plain = crayon[uid].plain;
|
574 |
+
|
575 |
+
if (show) {
|
576 |
+
main.css('overflow', 'auto');
|
577 |
+
plain.css('overflow', 'auto');
|
578 |
+
if (typeof crayon[uid].top != 'undefined') {
|
579 |
+
visible = (main.css('z-index') == 1 ? main : plain);
|
580 |
+
// Browser will not render until scrollbar moves, move it manually
|
581 |
+
visible.scrollTop(crayon[uid].top-1);
|
582 |
+
visible.scrollTop(crayon[uid].top);
|
583 |
+
visible.scrollLeft(crayon[uid].left-1);
|
584 |
+
visible.scrollLeft(crayon[uid].left);
|
585 |
+
}
|
586 |
+
if (!crayon[uid].scroll_block_fix) {
|
587 |
+
// Fix dimensions so scrollbars stay inside
|
588 |
+
main.css('height', main.height());
|
589 |
+
main.css('width', main.width());
|
590 |
+
} else {
|
591 |
+
// Relax dimensions so scrollbars are visible
|
592 |
+
main.css('height', '');
|
593 |
+
main.css('max-height', '');
|
594 |
+
main.css('min-height', '');
|
595 |
+
main.css('width', '');
|
596 |
+
}
|
597 |
+
} else {
|
598 |
+
visible = (main.css('z-index') == 1 ? main : plain);
|
599 |
+
crayon[uid].top = visible.scrollTop();
|
600 |
+
crayon[uid].left = visible.scrollLeft();
|
601 |
+
main.css('overflow', 'hidden');
|
602 |
+
plain.css('overflow', 'hidden');
|
603 |
+
if (!crayon[uid].scroll_block_fix) {
|
604 |
+
// Restore dimensions
|
605 |
+
main.css('height', crayon[uid].main_height);
|
606 |
+
main.css('max-height', crayon[uid].main_max_height);
|
607 |
+
main.css('min-height', crayon[uid].main_min_height);
|
608 |
+
main.css('width', crayon[uid].main_width);
|
609 |
+
}
|
610 |
+
}
|
611 |
+
// Register that overflow has changed
|
612 |
+
crayon[uid].scroll_changed = true;
|
613 |
+
fix_scroll_blank(uid);
|
614 |
}
|
615 |
|
616 |
+
/* Fix weird draw error, causes blank area to appear where scrollbar once was. */
|
617 |
+
var fix_scroll_blank = function(uid) {
|
618 |
+
if (typeof crayon[uid] == 'undefined') {
|
619 |
+
return make_uid(uid);
|
620 |
+
}
|
621 |
+
var width = crayon[uid].main.width();
|
622 |
+
crayon[uid].main.width(width);
|
623 |
+
crayon[uid].main.width(width - 1);
|
624 |
+
crayon[uid].main.width(width + 1);
|
625 |
+
crayon[uid].main.width(width);
|
626 |
}
|
627 |
+
|
628 |
+
var animt = function(x, uid) {
|
629 |
+
if (x == 'fast') {
|
630 |
+
x = 200;
|
631 |
+
} else if (x == 'slow') {
|
632 |
+
x = 600;
|
633 |
+
} else if (!isNumber(x)) {
|
634 |
+
x = parseInt(x);
|
635 |
+
if (isNaN(x)) {
|
636 |
+
return 0;
|
637 |
+
}
|
638 |
+
}
|
639 |
+
return x * crayon[uid].time;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
640 |
}
|
641 |
+
|
642 |
+
var isNumber = function(x) {
|
643 |
+
return typeof x == 'number';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
644 |
}
|
645 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
646 |
}
|
647 |
|
648 |
// -->
|
readme.txt
CHANGED
@@ -118,6 +118,12 @@ Contact me at http://twitter.com/crayonsyntax or crayon.syntax@gmail.com.
|
|
118 |
|
119 |
== Changelog ==
|
120 |
|
|
|
|
|
|
|
|
|
|
|
|
|
121 |
= 1.7.3 =
|
122 |
* Added Mini Tags and Plain Tags into Crayon. http://bit.ly/rRZuzk
|
123 |
* Fixed a bug causing RSS feeds to contain malformed HTML of Crayons, now it shows plain code with correct indentations. Thanks to Артём.
|
118 |
|
119 |
== Changelog ==
|
120 |
|
121 |
+
= 1.7.5 =
|
122 |
+
* Removed jQuery.noConflict() from crayon.js. This must have been causing some trouble if anything used $.
|
123 |
+
|
124 |
+
= 1.7.4 =
|
125 |
+
* Added namespacing to crayon.js to prevent conflicts
|
126 |
+
|
127 |
= 1.7.3 =
|
128 |
* Added Mini Tags and Plain Tags into Crayon. http://bit.ly/rRZuzk
|
129 |
* Fixed a bug causing RSS feeds to contain malformed HTML of Crayons, now it shows plain code with correct indentations. Thanks to Артём.
|