jencil-rails 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in jencil-rails.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 miio <info@miio.info>
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # Jencil::Rails
2
+
3
+ jencil is markup editor. Powerd by lambdalisue
4
+
5
+ https://github.com/lambdalisue/Jencil
6
+
7
+ It gem are use jencil for Rails.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'jencil-rails'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install jencil-rails
22
+
23
+ ## Usage(Example)
24
+
25
+ 1. add application.js
26
+
27
+ ```js
28
+ //= require jencil
29
+ ```
30
+
31
+ 1. add application.css
32
+
33
+ ```css
34
+ @import 'jencil'
35
+ ```
36
+
37
+ 1. call jencil text area
38
+
39
+ ```html
40
+ <%= jencil_text_area 'demo', 'demo' =>
41
+ ```
42
+
43
+ ## Depends gems
44
+
45
+ * [jquery-rails](https://github.com/indirect/jquery-rails)
46
+ * [jquery-ui-rails](https://github.com/joliss/jquery-ui-rails)
47
+
48
+ ## Contributing
49
+
50
+ 1. Fork it
51
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
52
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
53
+ 4. Push to the branch (`git push origin my-new-feature`)
54
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,5 @@
1
+ module JencilTextAreaHelper
2
+ def jencil_text_area model, tagname
3
+ javascript_tag("$(function(){$('textarea##{model}_#{tagname}').jencil({defaultVolume2: 0.7});});").concat(text_area(model, tagname))
4
+ end
5
+ end
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'jencil/rails/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "jencil-rails"
8
+ gem.version = Jencil::Rails::VERSION
9
+ gem.authors = ["miio"]
10
+ gem.email = ["info@miio.info"]
11
+ gem.description = %q{It gem are use jencil for Rails.}
12
+ gem.summary = %q{It gem are use jencil for Rails.}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ end
@@ -0,0 +1,7 @@
1
+ module Jencil
2
+ module Rails
3
+ require 'jencil/rails/engine' if defined?(Rails)
4
+ end
5
+ end
6
+
7
+ require 'jencil/rails/jencil' if defined?(Rails)
@@ -0,0 +1,6 @@
1
+ module Jencil
2
+ module Rails
3
+ class Engine < ::Rails::Engine
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,2 @@
1
+ require "jencil/rails/engine"
2
+ require "jencil/rails/version"
@@ -0,0 +1,5 @@
1
+ module Jencil
2
+ module Rails
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,3296 @@
1
+ /**
2
+ * Jencil 0.1.2
3
+ *
4
+ * Author: lambdalisue
5
+ * URL: http://hashnote.net/
6
+ * License: MIT License
7
+ *
8
+ * Copyright (C) 2012 lambdalisue, hashnote.net allright reserved.
9
+ *
10
+ * This application include following Library inside
11
+ *
12
+ * Tabby jQuery plugin version 0.12
13
+ * Ted Devito - http://teddevito.com/demos/textarea.html
14
+ * Copyright (c) 2009 Ted Devito
15
+ *
16
+ * shortcut.js
17
+ * http://www.openjs.com/scripts/events/keyboard_shortcuts/
18
+ * Version : 2.01.B
19
+ * By Binny V A
20
+ * License : BSD
21
+ */
22
+ /**
23
+ * #{NAME} #{VERSION}
24
+ *
25
+ * Author: lambdalisue
26
+ * URL: http://hashnote.net/
27
+ * License: MIT License
28
+ *
29
+ * Copyright (C) 2012 lambdalisue, hashnote.net allright reserved.
30
+ *
31
+ * This application include following Library inside
32
+ *
33
+ * Tabby jQuery plugin version 0.12
34
+ * Ted Devito - http://teddevito.com/demos/textarea.html
35
+ * Copyright (c) 2009 Ted Devito
36
+ *
37
+ * shortcut.js
38
+ * http://www.openjs.com/scripts/events/keyboard_shortcuts/
39
+ * Version : 2.01.B
40
+ * By Binny V A
41
+ * License : BSD
42
+ */
43
+ /**
44
+ * http://www.openjs.com/scripts/events/keyboard_shortcuts/
45
+ * Version : 2.01.B
46
+ * By Binny V A
47
+ * License : BSD
48
+ */
49
+ shortcut = {
50
+ 'all_shortcuts':{},//All the shortcuts are stored in this array
51
+ 'add': function(shortcut_combination,callback,opt) {
52
+ //Provide a set of default options
53
+ var default_options = {
54
+ 'type':'keydown',
55
+ 'propagate':false,
56
+ 'disable_in_input':false,
57
+ 'target':document,
58
+ 'keycode':false
59
+ }
60
+ if(!opt) opt = default_options;
61
+ else {
62
+ for(var dfo in default_options) {
63
+ if(typeof opt[dfo] == 'undefined') opt[dfo] = default_options[dfo];
64
+ }
65
+ }
66
+
67
+ var ele = opt.target;
68
+ if(typeof opt.target == 'string') ele = document.getElementById(opt.target);
69
+ var ths = this;
70
+ shortcut_combination = shortcut_combination.toLowerCase();
71
+
72
+ //The function to be called at keypress
73
+ var func = function(e) {
74
+ e = e || window.event;
75
+
76
+ if(opt['disable_in_input']) { //Don't enable shortcut keys in Input, Textarea fields
77
+ var element;
78
+ if(e.target) element=e.target;
79
+ else if(e.srcElement) element=e.srcElement;
80
+ if(element.nodeType==3) element=element.parentNode;
81
+
82
+ if(element.tagName == 'INPUT' || element.tagName == 'TEXTAREA') return;
83
+ }
84
+
85
+ //Find Which key is pressed
86
+ if (e.keyCode) code = e.keyCode;
87
+ else if (e.which) code = e.which;
88
+ var character = String.fromCharCode(code).toLowerCase();
89
+
90
+ if(code == 188) character=","; //If the user presses , when the type is onkeydown
91
+ if(code == 190) character="."; //If the user presses , when the type is onkeydown
92
+
93
+ var keys = shortcut_combination.split("+");
94
+ //Key Pressed - counts the number of valid keypresses - if it is same as the number of keys, the shortcut function is invoked
95
+ var kp = 0;
96
+
97
+ //Work around for stupid Shift key bug created by using lowercase - as a result the shift+num combination was broken
98
+ var shift_nums = {
99
+ "`":"~",
100
+ "1":"!",
101
+ "2":"@",
102
+ "3":"#",
103
+ "4":"$",
104
+ "5":"%",
105
+ "6":"^",
106
+ "7":"&",
107
+ "8":"*",
108
+ "9":"(",
109
+ "0":")",
110
+ "-":"_",
111
+ "=":"+",
112
+ ";":":",
113
+ "'":"\"",
114
+ ",":"<",
115
+ ".":">",
116
+ "/":"?",
117
+ "\\":"|"
118
+ }
119
+ //Special Keys - and their codes
120
+ var special_keys = {
121
+ 'esc':27,
122
+ 'escape':27,
123
+ 'tab':9,
124
+ 'space':32,
125
+ 'return':13,
126
+ 'enter':13,
127
+ 'backspace':8,
128
+
129
+ 'scrolllock':145,
130
+ 'scroll_lock':145,
131
+ 'scroll':145,
132
+ 'capslock':20,
133
+ 'caps_lock':20,
134
+ 'caps':20,
135
+ 'numlock':144,
136
+ 'num_lock':144,
137
+ 'num':144,
138
+
139
+ 'pause':19,
140
+ 'break':19,
141
+
142
+ 'insert':45,
143
+ 'home':36,
144
+ 'delete':46,
145
+ 'end':35,
146
+
147
+ 'pageup':33,
148
+ 'page_up':33,
149
+ 'pu':33,
150
+
151
+ 'pagedown':34,
152
+ 'page_down':34,
153
+ 'pd':34,
154
+
155
+ 'left':37,
156
+ 'up':38,
157
+ 'right':39,
158
+ 'down':40,
159
+
160
+ 'f1':112,
161
+ 'f2':113,
162
+ 'f3':114,
163
+ 'f4':115,
164
+ 'f5':116,
165
+ 'f6':117,
166
+ 'f7':118,
167
+ 'f8':119,
168
+ 'f9':120,
169
+ 'f10':121,
170
+ 'f11':122,
171
+ 'f12':123
172
+ }
173
+
174
+ var modifiers = {
175
+ shift: { wanted:false, pressed:false},
176
+ ctrl : { wanted:false, pressed:false},
177
+ alt : { wanted:false, pressed:false},
178
+ meta : { wanted:false, pressed:false} //Meta is Mac specific
179
+ };
180
+
181
+ if(e.ctrlKey) modifiers.ctrl.pressed = true;
182
+ if(e.shiftKey) modifiers.shift.pressed = true;
183
+ if(e.altKey) modifiers.alt.pressed = true;
184
+ if(e.metaKey) modifiers.meta.pressed = true;
185
+
186
+ for(var i=0; k=keys[i],i<keys.length; i++) {
187
+ //Modifiers
188
+ if(k == 'ctrl' || k == 'control') {
189
+ kp++;
190
+ modifiers.ctrl.wanted = true;
191
+
192
+ } else if(k == 'shift') {
193
+ kp++;
194
+ modifiers.shift.wanted = true;
195
+
196
+ } else if(k == 'alt') {
197
+ kp++;
198
+ modifiers.alt.wanted = true;
199
+ } else if(k == 'meta') {
200
+ kp++;
201
+ modifiers.meta.wanted = true;
202
+ } else if(k.length > 1) { //If it is a special key
203
+ if(special_keys[k] == code) kp++;
204
+
205
+ } else if(opt['keycode']) {
206
+ if(opt['keycode'] == code) kp++;
207
+
208
+ } else { //The special keys did not match
209
+ if(character == k) kp++;
210
+ else {
211
+ if(shift_nums[character] && e.shiftKey) { //Stupid Shift key bug created by using lowercase
212
+ character = shift_nums[character];
213
+ if(character == k) kp++;
214
+ }
215
+ }
216
+ }
217
+ }
218
+
219
+ if(kp == keys.length &&
220
+ modifiers.ctrl.pressed == modifiers.ctrl.wanted &&
221
+ modifiers.shift.pressed == modifiers.shift.wanted &&
222
+ modifiers.alt.pressed == modifiers.alt.wanted &&
223
+ modifiers.meta.pressed == modifiers.meta.wanted) {
224
+ callback(e);
225
+
226
+ if(!opt['propagate']) { //Stop the event
227
+ //e.cancelBubble is supported by IE - this will kill the bubbling process.
228
+ e.cancelBubble = true;
229
+ e.returnValue = false;
230
+
231
+ //e.stopPropagation works in Firefox.
232
+ if (e.stopPropagation) {
233
+ e.stopPropagation();
234
+ e.preventDefault();
235
+ }
236
+ return false;
237
+ }
238
+ }
239
+ }
240
+ this.all_shortcuts[shortcut_combination] = {
241
+ 'callback':func,
242
+ 'target':ele,
243
+ 'event': opt['type']
244
+ };
245
+ //Attach the function with the event
246
+ if(ele.addEventListener) ele.addEventListener(opt['type'], func, false);
247
+ else if(ele.attachEvent) ele.attachEvent('on'+opt['type'], func);
248
+ else ele['on'+opt['type']] = func;
249
+ },
250
+
251
+ //Remove the shortcut - just specify the shortcut and I will remove the binding
252
+ 'remove':function(shortcut_combination) {
253
+ shortcut_combination = shortcut_combination.toLowerCase();
254
+ var binding = this.all_shortcuts[shortcut_combination];
255
+ delete(this.all_shortcuts[shortcut_combination])
256
+ if(!binding) return;
257
+ var type = binding['event'];
258
+ var ele = binding['target'];
259
+ var callback = binding['callback'];
260
+
261
+ if(ele.detachEvent) ele.detachEvent('on'+type, callback);
262
+ else if(ele.removeEventListener) ele.removeEventListener(type, callback, false);
263
+ else ele['on'+type] = false;
264
+ }
265
+ };
266
+
267
+ /**
268
+ * #{NAME} #{VERSION}
269
+ *
270
+ * Author: lambdalisue
271
+ * URL: http://hashnote.net/
272
+ * License: MIT License
273
+ *
274
+ * Copyright (C) 2012 lambdalisue, hashnote.net allright reserved.
275
+ *
276
+ * This application include following Library inside
277
+ *
278
+ * Tabby jQuery plugin version 0.12
279
+ * Ted Devito - http://teddevito.com/demos/textarea.html
280
+ * Copyright (c) 2009 Ted Devito
281
+ *
282
+ *
283
+ */
284
+ /*
285
+ * Tabby jQuery plugin version 0.12
286
+ *
287
+ * Ted Devito - http://teddevito.com/demos/textarea.html
288
+ *
289
+ * Copyright (c) 2009 Ted Devito
290
+ *
291
+ * Fix: SHIFT+TAB feature in Gecko engine at 2012/09/19 by lambdalisue
292
+ *
293
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following
294
+ * conditions are met:
295
+ *
296
+ * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
297
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer
298
+ * in the documentation and/or other materials provided with the distribution.
299
+ * 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written
300
+ * permission.
301
+ *
302
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
303
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
304
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
305
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
306
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
307
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
308
+ *
309
+ */
310
+
311
+ // create closure
312
+
313
+ (function($) {
314
+
315
+ // plugin definition
316
+
317
+ $.fn.tabby = function(options) {
318
+ //debug(this);
319
+ // build main options before element iteration
320
+ var opts = $.extend({}, $.fn.tabby.defaults, options);
321
+ var pressed = $.fn.tabby.pressed;
322
+
323
+ // iterate and reformat each matched element
324
+ return this.each(function() {
325
+ $this = $(this);
326
+
327
+ // build element specific options
328
+ var options = $.meta ? $.extend({}, opts, $this.data()) : opts;
329
+
330
+ $this.bind('keydown',function (e) {
331
+ var kc = $.fn.tabby.catch_kc(e);
332
+ if (16 == kc) pressed.shft = true;
333
+ /*
334
+ because both CTRL+TAB and ALT+TAB default to an event (changing tab/window) that
335
+ will prevent js from capturing the keyup event, we'll set a timer on releasing them.
336
+ */
337
+ if (17 == kc) {pressed.ctrl = true; setTimeout("$.fn.tabby.pressed.ctrl = false;",1000);}
338
+ if (18 == kc) {pressed.alt = true; setTimeout("$.fn.tabby.pressed.alt = false;",1000);}
339
+
340
+ if (9 == kc && !pressed.ctrl && !pressed.alt) {
341
+ e.preventDefault; // does not work in O9.63 ??
342
+ pressed.last = kc; setTimeout("$.fn.tabby.pressed.last = null;",0);
343
+ process_keypress ($(e.target).get(0), pressed.shft, options);
344
+ return false;
345
+ }
346
+
347
+ }).bind('keyup',function (e) {
348
+ if (16 == $.fn.tabby.catch_kc(e)) pressed.shft = false;
349
+ }).bind('blur',function (e) { // workaround for Opera -- http://www.webdeveloper.com/forum/showthread.php?p=806588
350
+ if (9 == pressed.last) $(e.target).one('focus',function (e) {pressed.last = null;}).get(0).focus();
351
+ });
352
+
353
+ });
354
+ };
355
+
356
+ // define and expose any extra methods
357
+ $.fn.tabby.catch_kc = function(e) { return e.keyCode ? e.keyCode : e.charCode ? e.charCode : e.which; };
358
+ $.fn.tabby.pressed = {shft : false, ctrl : false, alt : false, last: null};
359
+
360
+ // private function for debugging
361
+ function debug($obj) {
362
+ if (window.console && window.console.log)
363
+ window.console.log('textarea count: ' + $obj.size());
364
+ };
365
+
366
+ function process_keypress (o,shft,options) {
367
+ var scrollTo = o.scrollTop;
368
+ //var tabString = String.fromCharCode(9);
369
+
370
+ // gecko; o.setSelectionRange is only available when the text box has focus
371
+ if (o.setSelectionRange) gecko_tab (o, shft, options);
372
+
373
+ // ie; document.selection is always available
374
+ else if (document.selection) ie_tab (o, shft, options);
375
+
376
+ o.scrollTop = scrollTo;
377
+ }
378
+
379
+ // plugin defaults
380
+ $.fn.tabby.defaults = {tabString : String.fromCharCode(9)};
381
+
382
+ function gecko_tab (o, shft, options) {
383
+ var ss = o.selectionStart;
384
+ var es = o.selectionEnd;
385
+
386
+ // when there's no selection and we're just working with the caret, we'll add/remove the tabs at the caret, providing more control
387
+ if(ss == es) {
388
+ // SHIFT+TAB
389
+ if (shft) {
390
+ // check to the left of the caret first
391
+ //if ("\t" == o.value.substring(ss-options.tabString.length, ss)) {
392
+ if (options.tabString == o.value.substring(ss-options.tabString.length, ss)) {
393
+ o.value = o.value.substring(0, ss-options.tabString.length) + o.value.substring(ss); // put it back together omitting one character to the left
394
+ o.focus();
395
+ o.setSelectionRange(ss - options.tabString.length, ss - options.tabString.length);
396
+ }
397
+ // then check to the right of the caret
398
+ //else if ("\t" == o.value.substring(ss, ss + options.tabString.length)) {
399
+ else if (options.tabString == o.value.substring(ss, ss + options.tabString.length)) {
400
+ o.value = o.value.substring(0, ss) + o.value.substring(ss + options.tabString.length); // put it back together omitting one character to the right
401
+ o.focus();
402
+ o.setSelectionRange(ss,ss);
403
+ }
404
+ }
405
+ // TAB
406
+ else {
407
+ o.value = o.value.substring(0, ss) + options.tabString + o.value.substring(ss);
408
+ o.focus();
409
+ o.setSelectionRange(ss + options.tabString.length, ss + options.tabString.length);
410
+ }
411
+ }
412
+ // selections will always add/remove tabs from the start of the line
413
+ else {
414
+ // split the textarea up into lines and figure out which lines are included in the selection
415
+ var lines = o.value.split("\n");
416
+ var indices = new Array();
417
+ var sl = 0; // start of the line
418
+ var el = 0; // end of the line
419
+ var sel = false;
420
+ for (var i in lines) {
421
+ el = sl + lines[i].length;
422
+ indices.push({start: sl, end: el, selected: (sl <= ss && el > ss) || (el >= es && sl < es) || (sl > ss && el < es)});
423
+ sl = el + 1;// for "\n"
424
+ }
425
+
426
+ // walk through the array of lines (indices) and add tabs where appropriate
427
+ var modifier = 0;
428
+ for (var i in indices) {
429
+ if (indices[i].selected) {
430
+ var pos = indices[i].start + modifier; // adjust for tabs already inserted/removed
431
+ // SHIFT+TAB
432
+ if (shft && options.tabString == o.value.substring(pos,pos+options.tabString.length)) { // only SHIFT+TAB if there's a tab at the start of the line
433
+ o.value = o.value.substring(0,pos) + o.value.substring(pos + options.tabString.length); // omit the tabstring to the right
434
+ modifier -= options.tabString.length;
435
+ }
436
+ // TAB
437
+ else if (!shft) {
438
+ o.value = o.value.substring(0,pos) + options.tabString + o.value.substring(pos); // insert the tabstring
439
+ modifier += options.tabString.length;
440
+ }
441
+ }
442
+ }
443
+ o.focus();
444
+ var ns = ss + ((modifier > 0) ? options.tabString.length : (modifier < 0) ? -options.tabString.length : 0);
445
+ var ne = es + modifier;
446
+ o.setSelectionRange(ns,ne);
447
+ }
448
+ }
449
+
450
+ function ie_tab (o, shft, options) {
451
+ var range = document.selection.createRange();
452
+
453
+ if (o == range.parentElement()) {
454
+ // when there's no selection and we're just working with the caret, we'll add/remove the tabs at the caret, providing more control
455
+ if ('' == range.text) {
456
+ // SHIFT+TAB
457
+ if (shft) {
458
+ var bookmark = range.getBookmark();
459
+ //first try to the left by moving opening up our empty range to the left
460
+ range.moveStart('character', -options.tabString.length);
461
+ if (options.tabString == range.text) {
462
+ range.text = '';
463
+ } else {
464
+ // if that didn't work then reset the range and try opening it to the right
465
+ range.moveToBookmark(bookmark);
466
+ range.moveEnd('character', options.tabString.length);
467
+ if (options.tabString == range.text)
468
+ range.text = '';
469
+ }
470
+ // move the pointer to the start of them empty range and select it
471
+ range.collapse(true);
472
+ range.select();
473
+ }
474
+
475
+ else {
476
+ // very simple here. just insert the tab into the range and put the pointer at the end
477
+ range.text = options.tabString;
478
+ range.collapse(false);
479
+ range.select();
480
+ }
481
+ }
482
+ // selections will always add/remove tabs from the start of the line
483
+ else {
484
+
485
+ var selection_text = range.text;
486
+ var selection_len = selection_text.length;
487
+ var selection_arr = selection_text.split("\r\n");
488
+
489
+ var before_range = document.body.createTextRange();
490
+ before_range.moveToElementText(o);
491
+ before_range.setEndPoint("EndToStart", range);
492
+ var before_text = before_range.text;
493
+ var before_arr = before_text.split("\r\n");
494
+ var before_len = before_text.length; // - before_arr.length + 1;
495
+
496
+ var after_range = document.body.createTextRange();
497
+ after_range.moveToElementText(o);
498
+ after_range.setEndPoint("StartToEnd", range);
499
+ var after_text = after_range.text; // we can accurately calculate distance to the end because we're not worried about MSIE trimming a \r\n
500
+
501
+ var end_range = document.body.createTextRange();
502
+ end_range.moveToElementText(o);
503
+ end_range.setEndPoint("StartToEnd", before_range);
504
+ var end_text = end_range.text; // we can accurately calculate distance to the end because we're not worried about MSIE trimming a \r\n
505
+
506
+ var check_html = $(o).html();
507
+ $("#r3").text(before_len + " + " + selection_len + " + " + after_text.length + " = " + check_html.length);
508
+ if((before_len + end_text.length) < check_html.length) {
509
+ before_arr.push("");
510
+ before_len += 2; // for the \r\n that was trimmed
511
+ if (shft && options.tabString == selection_arr[0].substring(0,options.tabString.length))
512
+ selection_arr[0] = selection_arr[0].substring(options.tabString.length);
513
+ else if (!shft) selection_arr[0] = options.tabString + selection_arr[0];
514
+ } else {
515
+ if (shft && options.tabString == before_arr[before_arr.length-1].substring(0,options.tabString.length))
516
+ before_arr[before_arr.length-1] = before_arr[before_arr.length-1].substring(options.tabString.length);
517
+ else if (!shft) before_arr[before_arr.length-1] = options.tabString + before_arr[before_arr.length-1];
518
+ }
519
+
520
+ for (var i = 1; i < selection_arr.length; i++) {
521
+ if (shft && options.tabString == selection_arr[i].substring(0,options.tabString.length))
522
+ selection_arr[i] = selection_arr[i].substring(options.tabString.length);
523
+ else if (!shft) selection_arr[i] = options.tabString + selection_arr[i];
524
+ }
525
+
526
+ if (1 == before_arr.length && 0 == before_len) {
527
+ if (shft && options.tabString == selection_arr[0].substring(0,options.tabString.length))
528
+ selection_arr[0] = selection_arr[0].substring(options.tabString.length);
529
+ else if (!shft) selection_arr[0] = options.tabString + selection_arr[0];
530
+ }
531
+
532
+ if ((before_len + selection_len + after_text.length) < check_html.length) {
533
+ selection_arr.push("");
534
+ selection_len += 2; // for the \r\n that was trimmed
535
+ }
536
+
537
+ before_range.text = before_arr.join("\r\n");
538
+ range.text = selection_arr.join("\r\n");
539
+
540
+ var new_range = document.body.createTextRange();
541
+ new_range.moveToElementText(o);
542
+
543
+ if (0 < before_len) new_range.setEndPoint("StartToEnd", before_range);
544
+ else new_range.setEndPoint("StartToStart", before_range);
545
+ new_range.setEndPoint("EndToEnd", range);
546
+
547
+ new_range.select();
548
+
549
+ }
550
+ }
551
+ }
552
+
553
+ // end of closure
554
+ })(jQuery);
555
+
556
+
557
+ (function() {
558
+ var ActionButton, AjaxViewer, Bar, BaseEditor, BaseHelper, BaseViewer, Button, Caretaker, CommandButton, DefaultProfile, DimainPanel, Fullscreen, FullscreenButton, HelperButton, HorizontalPanel, HorizontalSplitter, HtmlEditor, HtmlHelper, HtmlProfile, HtmlViewer, MonomainPanel, MultiplePanel, Originator, Panel, RedoButton, Selection, Separator, Splitter, Statusbar, TemplateHelper, TemplateViewer, TextEditor, Toolbar, TrimainPanel, UndoButton, VerticalPanel, VerticalSplitter, ViewerButton, Widget, Workspace, Wrapper, animate, autoIndentable, autoIndentableHtml, buttonFactory, curtainFactory, evolute, headerMarkup, translate,
559
+ __slice = [].slice,
560
+ __hasProp = {}.hasOwnProperty,
561
+ __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
562
+
563
+ window.namespace = function(target, name, block) {
564
+ var item, top, _i, _len, _ref, _ref1;
565
+ if (arguments.length < 3) {
566
+ _ref = [(typeof exports !== 'undefined' ? exports : window)].concat(__slice.call(arguments)), target = _ref[0], name = _ref[1], block = _ref[2];
567
+ }
568
+ top = target;
569
+ _ref1 = name.split('.');
570
+ for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
571
+ item = _ref1[_i];
572
+ target = target[item] || (target[item] = {});
573
+ }
574
+ return block(target, top);
575
+ };
576
+
577
+ Originator = (function() {
578
+
579
+ function Originator() {}
580
+
581
+ Originator.prototype.createMemento = function() {
582
+ throw new Error("NotImplementedError");
583
+ };
584
+
585
+ Originator.prototype.setMemento = function(memento) {
586
+ throw new Error("NotImplementedError");
587
+ };
588
+
589
+ return Originator;
590
+
591
+ })();
592
+
593
+ Caretaker = (function() {
594
+
595
+ function Caretaker(originator) {
596
+ this._originator = originator;
597
+ this._undoStack = [];
598
+ this._redoStack = [];
599
+ }
600
+
601
+ Caretaker.prototype.originator = function(originator) {
602
+ if (originator != null) {
603
+ this._originator = originator;
604
+ return this;
605
+ }
606
+ return originator;
607
+ };
608
+
609
+ Caretaker.prototype.save = function(memento) {
610
+ memento = memento || this.originator().createMemento();
611
+ this._undoStack.push(memento);
612
+ return this._redoStack = [];
613
+ };
614
+
615
+ Caretaker.prototype.undo = function() {
616
+ var originator;
617
+ if (!this.canUndo()) {
618
+ return false;
619
+ }
620
+ originator = this.originator();
621
+ this._redoStack.push(originator.createMemento());
622
+ originator.setMemento(this._undoStack.pop());
623
+ if (typeof originator.focus === "function") {
624
+ originator.focus();
625
+ }
626
+ return true;
627
+ };
628
+
629
+ Caretaker.prototype.redo = function() {
630
+ var originator;
631
+ if (!this.canRedo()) {
632
+ return false;
633
+ }
634
+ originator = this.originator();
635
+ this._undoStack.push(originator.createMemento());
636
+ originator.setMemento(this._redoStack.pop());
637
+ if (typeof originator.focus === "function") {
638
+ originator.focus();
639
+ }
640
+ return true;
641
+ };
642
+
643
+ Caretaker.prototype.canUndo = function() {
644
+ return this._undoStack.length > 0;
645
+ };
646
+
647
+ Caretaker.prototype.canRedo = function() {
648
+ return this._redoStack.length > 0;
649
+ };
650
+
651
+ return Caretaker;
652
+
653
+ })();
654
+
655
+ Selection = (function() {
656
+
657
+ function Selection(document, element) {
658
+ this.document = document;
659
+ this.element = element;
660
+ this;
661
+
662
+ }
663
+
664
+ Selection.prototype._getCaret = function() {
665
+ var caret, clone, e, range, s;
666
+ if (this.document.selection != null) {
667
+ range = this.document.selection.createRange();
668
+ clone = range.duplicate();
669
+ clone.moveToElementText(this.element);
670
+ clone.setEndPoint('EndToEnd', range);
671
+ s = clone.text.length - range.text.length;
672
+ e = s + range.text.length;
673
+ } else if (this.element.setSelectionRange != null) {
674
+ s = this.element.selectionStart;
675
+ e = this.element.selectionEnd;
676
+ }
677
+ caret = [s, e];
678
+ caret.isCollapse = s === e;
679
+ return caret;
680
+ };
681
+
682
+ Selection.prototype._setCaret = function(start, end) {
683
+ var range, scrollTop;
684
+ scrollTop = this.element.scrollTop;
685
+ if (this.element.setSelectionRange != null) {
686
+ this.element.setSelectionRange(start, end);
687
+ } else if (this.element.createTextRange) {
688
+ range = this.element.createTextRange();
689
+ range.collapse(true);
690
+ range.moveStart('character', start);
691
+ range.moveEnd('character', end - start);
692
+ range.select();
693
+ }
694
+ this.element.focus();
695
+ this.element.scrollTop = scrollTop;
696
+ return this;
697
+ };
698
+
699
+ Selection.prototype.caret = function(start, end) {
700
+ if ((start != null) && typeof start === 'array') {
701
+ end = start[1];
702
+ start = start[0];
703
+ }
704
+ if ((start != null) && !(end != null)) {
705
+ end = start;
706
+ }
707
+ if ((start != null) && (end != null)) {
708
+ return this._setCaret(start, end);
709
+ }
710
+ return this._getCaret();
711
+ };
712
+
713
+ Selection.prototype.caretOffset = function(offset) {
714
+ var caret;
715
+ caret = this.caret();
716
+ return this.caret(caret[0] + offset);
717
+ };
718
+
719
+ Selection.prototype._replace = function(str, start, end) {
720
+ var a, b, scrollTop;
721
+ scrollTop = this.element.scrollTop;
722
+ b = this.element.value.substring(0, start);
723
+ a = this.element.value.substring(end);
724
+ this.element.value = b + str + a;
725
+ this.element.scrollTop = scrollTop;
726
+ return this;
727
+ };
728
+
729
+ Selection.prototype._getText = function() {
730
+ var e, range, s, _ref;
731
+ if (this.document.selection != null) {
732
+ range = this.document.selection.createRange();
733
+ return range.text;
734
+ } else if (this.element.setSelectionRange) {
735
+ _ref = this.caret(), s = _ref[0], e = _ref[1];
736
+ return this.element.value.substring(s, e);
737
+ }
738
+ return null;
739
+ };
740
+
741
+ Selection.prototype._setText = function(str, keepSelection) {
742
+ var e, s, scrollTop, _ref;
743
+ scrollTop = this.element.scrollTop;
744
+ _ref = this.caret(), s = _ref[0], e = _ref[1];
745
+ this._replace(str, s, e);
746
+ e = s + str.length;
747
+ if (!keepSelection) {
748
+ s = e;
749
+ }
750
+ this.caret(s, e);
751
+ this.element.focus();
752
+ this.element.scrollTop = scrollTop;
753
+ return this;
754
+ };
755
+
756
+ Selection.prototype.text = function(str, keepSelection) {
757
+ if (str != null) {
758
+ return this._setText(str, keepSelection);
759
+ }
760
+ return this._getText();
761
+ };
762
+
763
+ Selection.prototype.insertBefore = function(str, keepSelection) {
764
+ var e, s, scrollTop, text, _ref;
765
+ scrollTop = this.element.scrollTop;
766
+ _ref = this.caret(), s = _ref[0], e = _ref[1];
767
+ text = this.text();
768
+ this._replace(str + text, s, e);
769
+ e = s + str.length;
770
+ if (!keepSelection) {
771
+ s = e;
772
+ }
773
+ this.caret(s, e);
774
+ this.element.focus();
775
+ this.element.scrollTop = scrollTop;
776
+ return this;
777
+ };
778
+
779
+ Selection.prototype.insertAfter = function(str, keepSelection) {
780
+ var e, s, scrollTop, text, _ref;
781
+ scrollTop = this.element.scrollTop;
782
+ _ref = this.caret(), s = _ref[0], e = _ref[1];
783
+ text = this.text();
784
+ this._replace(text + str, s, e);
785
+ s = e;
786
+ e = e + str.length;
787
+ if (!keepSelection) {
788
+ s = e;
789
+ }
790
+ this.caret(s, e);
791
+ this.element.focus();
792
+ this.element.scrollTop = scrollTop;
793
+ return this;
794
+ };
795
+
796
+ Selection.prototype.enclose = function(lhs, rhs, keepSelection) {
797
+ var e, s, scrollTop, str, text, _ref;
798
+ scrollTop = this.element.scrollTop;
799
+ text = this.text();
800
+ if (text.indexOf(lhs) === 0 && text.lastIndexOf(rhs) === (text.length - rhs.length)) {
801
+ str = text.substring(lhs.length, text.length - rhs.length);
802
+ this.text(str, keepSelection);
803
+ } else {
804
+ _ref = this.caret(), s = _ref[0], e = _ref[1];
805
+ this._replace(lhs + text + rhs, s, e);
806
+ e = s + lhs.length + text.length + rhs.length;
807
+ if (!keepSelection) {
808
+ s = e;
809
+ }
810
+ this.caret(s, e);
811
+ }
812
+ this.element.focus();
813
+ this.element.scrollTop = scrollTop;
814
+ return this;
815
+ };
816
+
817
+ Selection.prototype._getLineCaretOfCaret = function(caret) {
818
+ var e, s, value;
819
+ value = this.element.value;
820
+ s = value.lastIndexOf("\n", caret - 1) + 1;
821
+ e = value.indexOf("\n", caret);
822
+ if (e === -1) {
823
+ e = value.length;
824
+ }
825
+ return [s, e];
826
+ };
827
+
828
+ Selection.prototype._getLineCaret = function() {
829
+ return this._getLineCaretOfCaret(this.caret()[0]);
830
+ };
831
+
832
+ Selection.prototype._getLine = function() {
833
+ var e, s, _ref;
834
+ _ref = this._getLineCaret(), s = _ref[0], e = _ref[1];
835
+ return this.element.value.substring(s, e);
836
+ };
837
+
838
+ Selection.prototype._setLine = function(line, keepSelection) {
839
+ var e, s, scrollTop, _ref;
840
+ scrollTop = this.element.scrollTop;
841
+ _ref = this._getLineCaret(), s = _ref[0], e = _ref[1];
842
+ this._replace(line, s, e);
843
+ e = s + line.length;
844
+ if (!keepSelection) {
845
+ s = e;
846
+ }
847
+ this.caret(s, e);
848
+ this.element.focus();
849
+ this.element.scrollTop = scrollTop;
850
+ return this;
851
+ };
852
+
853
+ Selection.prototype.line = function(value, keepSelection) {
854
+ if (value != null) {
855
+ return this._setLine(value, keepSelection);
856
+ }
857
+ return this._getLine();
858
+ };
859
+
860
+ Selection.prototype.selectWholeLine = function(caret) {
861
+ var e, s, _ref;
862
+ _ref = this._getLineCaretOfCaret(caret), s = _ref[0], e = _ref[1];
863
+ return this.caret(s, e);
864
+ };
865
+
866
+ Selection.prototype.selectWholeCurrentLine = function() {
867
+ var e, s, _ref;
868
+ _ref = this._getLineCaretOfCaret(this.caret()[0]), s = _ref[0], e = _ref[1];
869
+ return this.caret(s, e);
870
+ };
871
+
872
+ return Selection;
873
+
874
+ })();
875
+
876
+ /*
877
+ Evolution
878
+
879
+ Extend jQueryObj
880
+
881
+ Author: lambdalisue
882
+ License: MIT License
883
+ */
884
+
885
+
886
+ evolute = (function() {
887
+ var absoluteX, absoluteY, contentX, contentY, maxHeight, maxWidth, minHeight, minWidth, ncss, nonContentHeight, nonContentWidth, outerHeight, outerWidth, relativeX, relativeY;
888
+ nonContentWidth = function(includeMargin) {
889
+ if (includeMargin == null) {
890
+ includeMargin = false;
891
+ }
892
+ return this.outerWidth(includeMargin) - this.width();
893
+ };
894
+ nonContentHeight = function(includeMargin) {
895
+ if (includeMargin == null) {
896
+ includeMargin = false;
897
+ }
898
+ return this.outerHeight(includeMargin) - this.height();
899
+ };
900
+ outerWidth = function(includeMargin, value) {
901
+ var offset;
902
+ if (includeMargin == null) {
903
+ includeMargin = false;
904
+ }
905
+ if (typeof includeMargin === 'number') {
906
+ value = includeMargin;
907
+ includeMargin = false;
908
+ }
909
+ if (value != null) {
910
+ offset = this.nonContentWidth(includeMargin);
911
+ return this.width(value - offset);
912
+ }
913
+ return this._outerWidth(includeMargin);
914
+ };
915
+ outerHeight = function(includeMargin, value) {
916
+ var offset;
917
+ if (includeMargin == null) {
918
+ includeMargin = false;
919
+ }
920
+ if (typeof includeMargin === 'number') {
921
+ value = includeMargin;
922
+ includeMargin = false;
923
+ }
924
+ if (value != null) {
925
+ offset = this.nonContentHeight(includeMargin);
926
+ return this.height(value - offset);
927
+ }
928
+ return this._outerHeight(includeMargin);
929
+ };
930
+ nonContentWidth = function(includeMargin) {
931
+ if (includeMargin == null) {
932
+ includeMargin = false;
933
+ }
934
+ return this.outerWidth(includeMargin) - this.width();
935
+ };
936
+ nonContentHeight = function(includeMargin) {
937
+ if (includeMargin == null) {
938
+ includeMargin = false;
939
+ }
940
+ return this.outerHeight(includeMargin) - this.height();
941
+ };
942
+ ncss = function(propertyName, defaultValue) {
943
+ var value;
944
+ if (defaultValue == null) {
945
+ defaultValue = null;
946
+ }
947
+ value = this.css(propertyName);
948
+ if (value === '' || value === 'none' || value === null || value === (void 0) || value === NaN) {
949
+ return defaultValue;
950
+ }
951
+ value = parseInt(value, 10);
952
+ return value;
953
+ };
954
+ minWidth = function() {
955
+ return this.ncss('min-width');
956
+ };
957
+ minHeight = function() {
958
+ return this.ncss('min-height');
959
+ };
960
+ maxWidth = function() {
961
+ return this.ncss('max-width');
962
+ };
963
+ maxHeight = function() {
964
+ return this.ncss('max-height');
965
+ };
966
+ contentX = function(includeMargin) {
967
+ var borderLeft, marginLeft, paddingLeft;
968
+ if (includeMargin == null) {
969
+ includeMargin = false;
970
+ }
971
+ marginLeft = includeMargin ? this.ncss('margin-left') : 0;
972
+ borderLeft = this.ncss('border-left-width');
973
+ paddingLeft = this.ncss('padding-left');
974
+ return marginLeft + borderLeft + paddingLeft;
975
+ };
976
+ contentY = function(includeMargin) {
977
+ var borderTop, marginTop, paddingTop;
978
+ if (includeMargin == null) {
979
+ includeMargin = false;
980
+ }
981
+ marginTop = includeMargin ? this.ncss('margin-top') : 0;
982
+ borderTop = this.ncss('border-top-width');
983
+ paddingTop = this.ncss('padding-top');
984
+ return marginTop + borderTop + paddingTop;
985
+ };
986
+ absoluteX = function(value) {
987
+ var offset;
988
+ offset = this.offset();
989
+ if (value != null) {
990
+ offset.left = value;
991
+ return this.offset(offset);
992
+ }
993
+ return offset.left;
994
+ };
995
+ absoluteY = function(value) {
996
+ var offset;
997
+ offset = this.offset();
998
+ if (value != null) {
999
+ offset.top = value;
1000
+ return this.offset(offset);
1001
+ }
1002
+ return offset.top;
1003
+ };
1004
+ relativeX = function(includeMargin, value) {
1005
+ var offset, parent;
1006
+ if (includeMargin == null) {
1007
+ includeMargin = false;
1008
+ }
1009
+ if (typeof includeMargin === 'number') {
1010
+ value = includeMargin;
1011
+ includeMargin = false;
1012
+ }
1013
+ parent = evolute(this.parent());
1014
+ offset = parent.absoluteX() + parent.contentX(includeMargin);
1015
+ if (value != null) {
1016
+ return this.absoluteX(value + offset);
1017
+ }
1018
+ return this.absoluteX() - offset;
1019
+ };
1020
+ relativeY = function(includeMargin, value) {
1021
+ var offset, parent;
1022
+ if (includeMargin == null) {
1023
+ includeMargin = false;
1024
+ }
1025
+ if (typeof includeMargin === 'number') {
1026
+ value = includeMargin;
1027
+ includeMargin = false;
1028
+ }
1029
+ parent = evolute(this.parent());
1030
+ offset = parent.absoluteY() + parent.contentY(includeMargin);
1031
+ if (value != null) {
1032
+ return this.absoluteY(value + offset);
1033
+ }
1034
+ return this.absoluteY() - offset;
1035
+ };
1036
+ evolute = function(jQueryObj) {
1037
+ if (jQueryObj.__evoluted__ === true) {
1038
+ return jQueryObj;
1039
+ }
1040
+ jQueryObj._outerWidth = jQueryObj.outerWidth;
1041
+ jQueryObj._outerHeight = jQueryObj.outerHeight;
1042
+ jQueryObj.nonContentWidth = nonContentWidth;
1043
+ jQueryObj.nonContentHeight = nonContentHeight;
1044
+ jQueryObj.outerWidth = outerWidth;
1045
+ jQueryObj.outerHeight = outerHeight;
1046
+ jQueryObj.nonContentWidth = nonContentWidth;
1047
+ jQueryObj.nonContentHeight = nonContentHeight;
1048
+ jQueryObj.ncss = ncss;
1049
+ jQueryObj.minWidth = minWidth;
1050
+ jQueryObj.minHeight = minHeight;
1051
+ jQueryObj.maxWidth = maxWidth;
1052
+ jQueryObj.maxHeight = maxHeight;
1053
+ jQueryObj.contentX = contentX;
1054
+ jQueryObj.contentY = contentY;
1055
+ jQueryObj.absoluteX = absoluteX;
1056
+ jQueryObj.absoluteY = absoluteY;
1057
+ jQueryObj.relativeX = relativeX;
1058
+ jQueryObj.relativeY = relativeY;
1059
+ jQueryObj.__evoluted__ = true;
1060
+ return jQueryObj;
1061
+ };
1062
+ return evolute;
1063
+ })();
1064
+
1065
+ curtainFactory = function(element) {
1066
+ var curtain;
1067
+ element.css('position', 'relative');
1068
+ curtain = $('<div>').appendTo(element).hide().css({
1069
+ 'position': 'absolute',
1070
+ 'top': '0',
1071
+ 'left': '0',
1072
+ 'overflow': 'hidden',
1073
+ 'z-index': 99999
1074
+ });
1075
+ curtain.on = function() {
1076
+ curtain.refresh();
1077
+ return curtain.show();
1078
+ };
1079
+ curtain.refresh = function() {
1080
+ curtain.width(element.outerWidth(true));
1081
+ return curtain.height(element.outerHeight(true));
1082
+ };
1083
+ curtain.off = function() {
1084
+ return curtain.hide();
1085
+ };
1086
+ return curtain;
1087
+ };
1088
+
1089
+ /*
1090
+ animation
1091
+
1092
+ Animate value via easing function
1093
+
1094
+ The following library is required to use this library
1095
+
1096
+ - jQuery
1097
+
1098
+ Author: lambdalisue (lambdalisue@hashnote.net)
1099
+ License: MIT License
1100
+
1101
+ Copyright(C) 2012 lambdalisue, hasnote.net allright reserved
1102
+ */
1103
+
1104
+
1105
+ animate = (function() {
1106
+ var defaultOptions, now;
1107
+ now = function() {
1108
+ return (new Date()).getTime();
1109
+ };
1110
+ defaultOptions = {
1111
+ start: 0,
1112
+ end: 100,
1113
+ duration: 1000,
1114
+ callbackEach: null,
1115
+ callbackDone: null,
1116
+ easing: jQuery.easing.swing
1117
+ };
1118
+ return function(options) {
1119
+ var difference, startTime, step;
1120
+ options = jQuery.extend(defaultOptions, options);
1121
+ startTime = now();
1122
+ difference = options.end - options.start;
1123
+ step = function() {
1124
+ var epoch, x;
1125
+ epoch = now() - startTime;
1126
+ x = options.easing(epoch / options.duration, epoch, 0, 1, options.duration);
1127
+ x = x * difference + options.start;
1128
+ options.callbackEach(x, epoch);
1129
+ if (epoch < options.duration) {
1130
+ return setTimeout(step, 1);
1131
+ } else {
1132
+ options.callbackEach(options.end, options.duration);
1133
+ return typeof options.callbackDone === "function" ? options.callbackDone() : void 0;
1134
+ }
1135
+ };
1136
+ return step();
1137
+ };
1138
+ })();
1139
+
1140
+ /*
1141
+ autoindent
1142
+
1143
+ Enable auto indentation feature in textarea
1144
+ It is suitable with jquery.tabby.js which enable tab indentation in textarea
1145
+
1146
+ The following library is required to use this library
1147
+
1148
+ - jQuery
1149
+ - selection
1150
+
1151
+ Note:
1152
+ You should use this library as CoffeeScript that's why I didn't
1153
+ add `autoIndentable` in window namespace
1154
+
1155
+ Usage:
1156
+
1157
+ textarea = $('textarea')
1158
+ textarea = autoIndentable(textarea)
1159
+
1160
+ # auto indent feature is enable at default.
1161
+ # you can disable it with
1162
+ textarea.autoIndent.disable()
1163
+
1164
+ # and enable again with
1165
+ textarea.autoIndent.enable()
1166
+
1167
+ # and also, you can add some pre/post callback
1168
+ # which is called pre/post step of adding newline
1169
+ # and white spaces with
1170
+ textarea.autoIndent.pre = (e, line) ->
1171
+ # e = Event object of jQuery
1172
+ # line = current line of caret exists
1173
+ console.log "This function is called before newline adding"
1174
+ textarea.autoIndent.post = (e, line, indent, insert) ->
1175
+ # e = Event object of jQuery
1176
+ # line = current line of caret exists
1177
+ # indent = leading white spaces of current line
1178
+ # insert = newline and indent which is added after the caret
1179
+ console.log "This function is called after newline adding"
1180
+
1181
+ Author: lambdalisue (lambdalisue@hashnote.net)
1182
+ License: MIT License
1183
+
1184
+ Copyright(C) 2012 lambdalisue, hasnote.net allright reserved
1185
+ */
1186
+
1187
+
1188
+ autoIndentable = (function() {
1189
+ var autoIndent;
1190
+ autoIndent = function(e) {
1191
+ var indent, insert, line, _ref, _ref1;
1192
+ if (e.which !== 13) {
1193
+ return;
1194
+ }
1195
+ line = this.selection.line();
1196
+ if ((_ref = this.autoIndent.pre) != null) {
1197
+ _ref.call(this, e, line);
1198
+ }
1199
+ indent = line.replace(/^([\t\s]*).*$/, "$1");
1200
+ insert = "\n" + indent;
1201
+ this.selection.insertAfter(insert, false);
1202
+ if ((_ref1 = this.autoIndent.post) != null) {
1203
+ _ref1.call(this, e, line, indent, insert);
1204
+ }
1205
+ e.stopPropagation();
1206
+ e.stopImmediatePropagation();
1207
+ e.preventDefault();
1208
+ this.focus();
1209
+ return false;
1210
+ };
1211
+ return function(textarea, pre, post) {
1212
+ if (!(textarea instanceof jQuery)) {
1213
+ textarea = $(textarea);
1214
+ }
1215
+ if (!(textarea.selection != null)) {
1216
+ textarea.selection = new Selection(document, textarea.get(0));
1217
+ }
1218
+ textarea.autoIndent = function(e) {
1219
+ return autoIndent.call(textarea, e);
1220
+ };
1221
+ textarea.autoIndent.enable = function() {
1222
+ textarea.on('keydown', textarea.autoIndent);
1223
+ return textarea;
1224
+ };
1225
+ textarea.autoIndent.disable = function() {
1226
+ textarea.off('keydown', textarea.autoIndent);
1227
+ return textarea;
1228
+ };
1229
+ if (pre != null) {
1230
+ textarea.autoIndent.pre = function(e, line) {
1231
+ return pre.call(textarea, e, line);
1232
+ };
1233
+ }
1234
+ if (post != null) {
1235
+ textarea.autoIndent.post = function(e, line, indent, insert) {
1236
+ return post.call(textarea, e, line, indent, insert);
1237
+ };
1238
+ }
1239
+ return textarea.autoIndent.enable();
1240
+ };
1241
+ })();
1242
+
1243
+ if (window.i18n != null) {
1244
+ translate = function(key) {
1245
+ return i18n.t(key, {
1246
+ defaultValue: key
1247
+ });
1248
+ };
1249
+ } else {
1250
+ translate = function(key) {
1251
+ return key;
1252
+ };
1253
+ }
1254
+
1255
+ DefaultProfile = {
1256
+ mainPanelClass: null,
1257
+ editorClass: null,
1258
+ viewerClass: null,
1259
+ helperClass: null,
1260
+ toolbarButtons: [],
1261
+ statusbarButtons: [],
1262
+ defaultVolume: null,
1263
+ defaultVolume2: null
1264
+ };
1265
+
1266
+ this.Jencil = (function() {
1267
+
1268
+ function Jencil(textarea, options) {
1269
+ var _this = this;
1270
+ this.options = jQuery.extend({
1271
+ 'profile': 'Html',
1272
+ 'profiles': {
1273
+ 'Html': Jencil.profiles.HtmlProfile
1274
+ },
1275
+ 'resizable': true,
1276
+ 'enableTabIndent': true,
1277
+ 'enableAutoIndent': true,
1278
+ 'tabString': ' ',
1279
+ 'defaultVolume': null,
1280
+ 'defaultVolume2': null,
1281
+ 'width': 640,
1282
+ 'height': 620,
1283
+ 'editorTemplatePath': null,
1284
+ 'viewerTemplatePath': null,
1285
+ 'helperTemplatePath': null
1286
+ }, options);
1287
+ this.element = textarea.hide();
1288
+ this.caretaker = new Caretaker();
1289
+ this.caretaker.originator = function() {
1290
+ return _this.editor();
1291
+ };
1292
+ this.wrapper = new Wrapper(this, this.options.width, this.options.height);
1293
+ this.fullscreen = new Fullscreen(this);
1294
+ this.element.after(this.wrapper.element).after(this.fullscreen.element);
1295
+ this.wrapper.init();
1296
+ this.wrapper.adjust();
1297
+ this.caretaker.save();
1298
+ }
1299
+
1300
+ Jencil.prototype.editor = function() {
1301
+ return this.wrapper.workspace.mainPanel.editorPanel || null;
1302
+ };
1303
+
1304
+ Jencil.prototype.viewer = function() {
1305
+ return this.wrapper.workspace.mainPanel.viewerPanel || null;
1306
+ };
1307
+
1308
+ Jencil.prototype.helper = function() {
1309
+ return this.wrapper.workspace.mainPanel.helperPanel || null;
1310
+ };
1311
+
1312
+ return Jencil;
1313
+
1314
+ })();
1315
+
1316
+ $.fn.jencil = function(options) {
1317
+ return new Jencil($(this), options);
1318
+ };
1319
+
1320
+ namespace('Jencil.profiles', function(exports) {
1321
+ return exports.DefaultProfile = DefaultProfile;
1322
+ });
1323
+
1324
+ namespace('Jencil.utils', function(exports) {
1325
+ return exports.namespace = namespace;
1326
+ });
1327
+
1328
+ namespace('Jencil', function(exports) {
1329
+ return exports.t = translate;
1330
+ });
1331
+
1332
+ Widget = (function() {
1333
+
1334
+ function Widget(core, selector, context) {
1335
+ this.core = core;
1336
+ if (selector == null) {
1337
+ selector = '<div>';
1338
+ }
1339
+ if (selector instanceof jQuery) {
1340
+ this.element = selector;
1341
+ } else {
1342
+ this.element = $(selector, context);
1343
+ }
1344
+ this.element = evolute(this.element);
1345
+ }
1346
+
1347
+ Widget.prototype.init = function() {
1348
+ return this;
1349
+ };
1350
+
1351
+ Widget.prototype.adjust = function() {
1352
+ return this;
1353
+ };
1354
+
1355
+ return Widget;
1356
+
1357
+ })();
1358
+
1359
+ Panel = (function(_super) {
1360
+
1361
+ __extends(Panel, _super);
1362
+
1363
+ function Panel(core, selector, context) {
1364
+ if (selector == null) {
1365
+ selector = '<div>';
1366
+ }
1367
+ Panel.__super__.constructor.call(this, core, selector, context);
1368
+ this.element.addClass('panel');
1369
+ }
1370
+
1371
+ return Panel;
1372
+
1373
+ })(Widget);
1374
+
1375
+ MultiplePanel = (function(_super) {
1376
+
1377
+ __extends(MultiplePanel, _super);
1378
+
1379
+ function MultiplePanel(core, fst, snd, splitter) {
1380
+ var hide, show,
1381
+ _this = this;
1382
+ this.fst = fst;
1383
+ this.snd = snd;
1384
+ this.splitter = splitter;
1385
+ MultiplePanel.__super__.constructor.call(this, core);
1386
+ this.element.addClass('multiple');
1387
+ this.element.append(this.fst.element);
1388
+ this.element.append(this.splitter.element);
1389
+ this.element.append(this.snd.element);
1390
+ show = function(callback) {
1391
+ if (!this.element.is(':visible')) {
1392
+ return this.toggle(callback, null);
1393
+ }
1394
+ };
1395
+ hide = function(callback) {
1396
+ if (this.element.is(':visible')) {
1397
+ return this.toggle(null, callback);
1398
+ }
1399
+ };
1400
+ this.fst.toggle = function(callbackOn, callbackOff) {
1401
+ return _this._togglePanel(0, callbackOn, callbackOff);
1402
+ };
1403
+ this.fst.show = show;
1404
+ this.fst.hide = hide;
1405
+ this.snd.toggle = function(callbackOn, callbackOff) {
1406
+ return _this._togglePanel(1, callbackOn, callbackOff);
1407
+ };
1408
+ this.snd.show = show;
1409
+ this.snd.hide = hide;
1410
+ this.splitter.element.dblclick(function() {
1411
+ return _this.snd.toggle();
1412
+ });
1413
+ }
1414
+
1415
+ MultiplePanel.prototype.init = function() {
1416
+ this.splitter.init();
1417
+ this.fst.init();
1418
+ return this.snd.init();
1419
+ };
1420
+
1421
+ MultiplePanel.prototype._togglePanel = function(to, callbackOn, callbackOff) {
1422
+ var callbackDone, end, volume, _callbackDone,
1423
+ _this = this;
1424
+ if (MultiplePanel._animating) {
1425
+ return;
1426
+ }
1427
+ volume = this.splitter.volume();
1428
+ callbackDone = null;
1429
+ if ((0 < volume && volume < 1)) {
1430
+ end = to;
1431
+ this.splitter._previousVolume = volume;
1432
+ _callbackDone = callbackOff;
1433
+ } else {
1434
+ end = this.splitter._previousVolume || this.splitter.defaultVolume;
1435
+ if (end === to) {
1436
+ end = 0.5;
1437
+ }
1438
+ _callbackDone = callbackOn;
1439
+ }
1440
+ MultiplePanel._animating = true;
1441
+ callbackDone = function() {
1442
+ MultiplePanel._animating = false;
1443
+ return typeof _callbackDone === "function" ? _callbackDone() : void 0;
1444
+ };
1445
+ return animate({
1446
+ start: volume,
1447
+ end: end,
1448
+ duration: 500,
1449
+ callbackEach: function(value, epoch) {
1450
+ return _this.splitter.volume(value);
1451
+ },
1452
+ callbackDone: callbackDone
1453
+ });
1454
+ };
1455
+
1456
+ return MultiplePanel;
1457
+
1458
+ })(Panel);
1459
+
1460
+ VerticalPanel = (function(_super) {
1461
+
1462
+ __extends(VerticalPanel, _super);
1463
+
1464
+ function VerticalPanel(core, fst, snd, defaultVolume) {
1465
+ var splitter;
1466
+ if (defaultVolume == null) {
1467
+ defaultVolume = 0.5;
1468
+ }
1469
+ splitter = new VerticalSplitter(core, fst, snd, defaultVolume);
1470
+ VerticalPanel.__super__.constructor.call(this, core, fst, snd, splitter);
1471
+ this.element.addClass('vertical');
1472
+ }
1473
+
1474
+ VerticalPanel.prototype.adjust = function() {
1475
+ this.fst.element.outerHeight(true, this.element.height());
1476
+ this.snd.element.outerHeight(true, this.element.height());
1477
+ this.splitter.element.outerHeight(true, this.element.height());
1478
+ this.splitter.adjust();
1479
+ return this;
1480
+ };
1481
+
1482
+ return VerticalPanel;
1483
+
1484
+ })(MultiplePanel);
1485
+
1486
+ HorizontalPanel = (function(_super) {
1487
+
1488
+ __extends(HorizontalPanel, _super);
1489
+
1490
+ function HorizontalPanel(core, fst, snd, defaultVolume) {
1491
+ var splitter;
1492
+ if (defaultVolume == null) {
1493
+ defaultVolume = 0.5;
1494
+ }
1495
+ splitter = new HorizontalSplitter(core, fst, snd, defaultVolume);
1496
+ HorizontalPanel.__super__.constructor.call(this, core, fst, snd, splitter);
1497
+ this.element.addClass('horizontal');
1498
+ }
1499
+
1500
+ HorizontalPanel.prototype.adjust = function() {
1501
+ this.fst.element.outerWidth(true, this.element.width());
1502
+ this.snd.element.outerWidth(true, this.element.width());
1503
+ this.splitter.element.outerWidth(true, this.element.width());
1504
+ this.splitter.adjust();
1505
+ return this;
1506
+ };
1507
+
1508
+ return HorizontalPanel;
1509
+
1510
+ })(MultiplePanel);
1511
+
1512
+ namespace('Jencil.ui.widgets', function(exports) {
1513
+ return exports.Widget = Widget;
1514
+ });
1515
+
1516
+ namespace('Jencil.ui.widgets.panels', function(exports) {
1517
+ exports.Panel = Panel;
1518
+ exports.MultiplePanel = MultiplePanel;
1519
+ exports.VerticalPanel = VerticalPanel;
1520
+ return exports.HorizontalPanel = HorizontalPanel;
1521
+ });
1522
+
1523
+ Splitter = (function(_super) {
1524
+
1525
+ __extends(Splitter, _super);
1526
+
1527
+ function Splitter(core, fst, snd, defaultVolume) {
1528
+ var mousemove, mouseup,
1529
+ _this = this;
1530
+ this.fst = fst;
1531
+ this.snd = snd;
1532
+ this.defaultVolume = defaultVolume != null ? defaultVolume : 0.5;
1533
+ Splitter.__super__.constructor.call(this, core);
1534
+ this.element.addClass('splitter');
1535
+ this._volume = this.defaultVolume;
1536
+ mousemove = function(e) {
1537
+ var _ref, _ref1;
1538
+ _this.mousemove(e);
1539
+ if ((_ref = _this.fst.curtain) != null) {
1540
+ if (typeof _ref.refresh === "function") {
1541
+ _ref.refresh();
1542
+ }
1543
+ }
1544
+ if ((_ref1 = _this.snd.curtain) != null) {
1545
+ if (typeof _ref1.refresh === "function") {
1546
+ _ref1.refresh();
1547
+ }
1548
+ }
1549
+ e.stopPropagation();
1550
+ e.stopImmediatePropagation();
1551
+ return e.preventDefault();
1552
+ };
1553
+ mouseup = function(e) {
1554
+ var $window, _ref, _ref1;
1555
+ $window = $(window);
1556
+ $window.unbind('mousemove', mousemove);
1557
+ $window.unbind('mouseup', mouseup);
1558
+ if ((_ref = _this.fst.curtain) != null) {
1559
+ if (typeof _ref.off === "function") {
1560
+ _ref.off();
1561
+ }
1562
+ }
1563
+ if ((_ref1 = _this.snd.curtain) != null) {
1564
+ if (typeof _ref1.off === "function") {
1565
+ _ref1.off();
1566
+ }
1567
+ }
1568
+ e.stopPropagation();
1569
+ e.stopImmediatePropagation();
1570
+ return e.preventDefault();
1571
+ };
1572
+ this.element.mousedown(function(e) {
1573
+ var $window, _ref, _ref1;
1574
+ $window = $(window);
1575
+ $window.mousemove(mousemove);
1576
+ $window.mouseup(mouseup);
1577
+ if ((_ref = _this.fst.curtain) != null) {
1578
+ if (typeof _ref.on === "function") {
1579
+ _ref.on();
1580
+ }
1581
+ }
1582
+ if ((_ref1 = _this.snd.curtain) != null) {
1583
+ if (typeof _ref1.on === "function") {
1584
+ _ref1.on();
1585
+ }
1586
+ }
1587
+ e.stopPropagation();
1588
+ e.stopImmediatePropagation();
1589
+ return e.preventDefault();
1590
+ });
1591
+ }
1592
+
1593
+ Splitter.prototype.init = function() {
1594
+ return this.container = evolute(this.element.parent());
1595
+ };
1596
+
1597
+ Splitter.prototype.volume = function(value, skip) {
1598
+ if (skip == null) {
1599
+ skip = false;
1600
+ }
1601
+ if (value != null) {
1602
+ this._volume = value;
1603
+ if (!skip) {
1604
+ this.adjust();
1605
+ }
1606
+ return this;
1607
+ }
1608
+ return this._volume;
1609
+ };
1610
+
1611
+ Splitter.prototype.value = function(value, skip) {
1612
+ var valueWidth, volume;
1613
+ if (skip == null) {
1614
+ skip = false;
1615
+ }
1616
+ valueWidth = this.valueWidth();
1617
+ if (value != null) {
1618
+ volume = value / valueWidth;
1619
+ return this.volume(volume, skip);
1620
+ }
1621
+ return this.volume() * valueWidth;
1622
+ };
1623
+
1624
+ Splitter.prototype.regulateValue = function(value) {
1625
+ var maxValue, minValue;
1626
+ minValue = this.minValue();
1627
+ maxValue = this.maxValue();
1628
+ if (value < minValue) {
1629
+ value = minValue;
1630
+ }
1631
+ if (value > maxValue) {
1632
+ value = maxValue;
1633
+ }
1634
+ return value;
1635
+ };
1636
+
1637
+ return Splitter;
1638
+
1639
+ })(Widget);
1640
+
1641
+ VerticalSplitter = (function(_super) {
1642
+
1643
+ __extends(VerticalSplitter, _super);
1644
+
1645
+ function VerticalSplitter(core, fst, snd, defaultVolume) {
1646
+ var _ref, _ref1;
1647
+ VerticalSplitter.__super__.constructor.call(this, core, fst, snd, defaultVolume);
1648
+ this.element.addClass('vertical');
1649
+ this.fst.element.addClass('left');
1650
+ this.snd.element.addClass('right');
1651
+ this.fst.element.css({
1652
+ 'float': 'left'
1653
+ });
1654
+ this.snd.element.css({
1655
+ 'float': 'left'
1656
+ });
1657
+ if ((_ref = this.fst.curtain) != null) {
1658
+ _ref.css('pointer', 'col-resize');
1659
+ }
1660
+ if ((_ref1 = this.snd.curtain) != null) {
1661
+ _ref1.css('pointer', 'col-resize');
1662
+ }
1663
+ }
1664
+
1665
+ VerticalSplitter.prototype.mousemove = function(e) {
1666
+ var offset, value;
1667
+ offset = this.container.absoluteX() + this.container.contentX(true);
1668
+ value = e.pageX - offset;
1669
+ value = this.regulateValue(value);
1670
+ return this.value(value);
1671
+ };
1672
+
1673
+ VerticalSplitter.prototype.valueWidth = function() {
1674
+ return this.container.width();
1675
+ };
1676
+
1677
+ VerticalSplitter.prototype.minValue = function() {
1678
+ var m1, m2;
1679
+ m1 = this.fst.element.minWidth() + this.fst.element.nonContentWidth();
1680
+ m2 = this.snd.element.maxWidth() + this.snd.element.nonContentWidth();
1681
+ if (m2 != null) {
1682
+ m2 = this.valueWidth() - m2;
1683
+ }
1684
+ if ((m1 != null) && (m2 != null)) {
1685
+ return Math.min(m1, m2);
1686
+ }
1687
+ return m1 || m2 || 0;
1688
+ };
1689
+
1690
+ VerticalSplitter.prototype.maxValue = function() {
1691
+ var m1, m2, valueWidth;
1692
+ valueWidth = this.valueWidth();
1693
+ m1 = this.fst.element.maxWidth() + this.fst.element.nonContentWidth();
1694
+ m2 = this.snd.element.minWidth() + this.snd.element.nonContentWidth();
1695
+ if (m2 != null) {
1696
+ m2 = valueWidth - m2;
1697
+ }
1698
+ if ((m1 != null) && (m2 != null)) {
1699
+ return Math.max(m1, m2);
1700
+ }
1701
+ return m1 || m2 || valueWidth;
1702
+ };
1703
+
1704
+ VerticalSplitter.prototype.adjust = function() {
1705
+ var fstValue, sndValue, value, valueWidth;
1706
+ value = this.value();
1707
+ valueWidth = this.valueWidth();
1708
+ fstValue = value - this.fst.element.nonContentWidth(true);
1709
+ sndValue = (valueWidth - value) - this.snd.element.nonContentWidth(true);
1710
+ if (fstValue <= 0) {
1711
+ if (this.fst.element.is(':visible')) {
1712
+ this.fst.element.hide();
1713
+ }
1714
+ if (!this.snd.element.is(':visible')) {
1715
+ this.snd.element.show();
1716
+ }
1717
+ this.snd.element.outerWidth(true, valueWidth);
1718
+ this._value = value = 0;
1719
+ } else if (sndValue <= 0) {
1720
+ if (!this.fst.element.is(':visible')) {
1721
+ this.fst.element.show();
1722
+ }
1723
+ if (this.snd.element.is(':visible')) {
1724
+ this.snd.element.hide();
1725
+ }
1726
+ this.fst.element.outerWidth(true, valueWidth);
1727
+ this._value = value = valueWidth;
1728
+ } else {
1729
+ if (!this.fst.element.is(':visible')) {
1730
+ this.fst.element.show();
1731
+ }
1732
+ if (!this.snd.element.is(':visible')) {
1733
+ this.snd.element.show();
1734
+ }
1735
+ this.fst.element.width(fstValue);
1736
+ this.snd.element.width(sndValue);
1737
+ }
1738
+ this.fst.adjust();
1739
+ this.snd.adjust();
1740
+ this.element.relativeX(value - this.element.outerWidth() / 2);
1741
+ return this;
1742
+ };
1743
+
1744
+ return VerticalSplitter;
1745
+
1746
+ })(Splitter);
1747
+
1748
+ HorizontalSplitter = (function(_super) {
1749
+
1750
+ __extends(HorizontalSplitter, _super);
1751
+
1752
+ function HorizontalSplitter(core, fst, snd, defaultVolume) {
1753
+ var _ref, _ref1;
1754
+ HorizontalSplitter.__super__.constructor.call(this, core, fst, snd, defaultVolume);
1755
+ this.element.addClass('horizontal');
1756
+ this.fst.element.addClass('top');
1757
+ this.snd.element.addClass('bottom');
1758
+ if ((_ref = this.fst.curtain) != null) {
1759
+ _ref.css('pointer', 'raw-resize');
1760
+ }
1761
+ if ((_ref1 = this.snd.curtain) != null) {
1762
+ _ref1.css('pointer', 'raw-resize');
1763
+ }
1764
+ }
1765
+
1766
+ HorizontalSplitter.prototype.mousemove = function(e) {
1767
+ var offset, value;
1768
+ offset = this.container.absoluteY() + this.container.contentY(true);
1769
+ value = e.pageY - offset;
1770
+ value = this.regulateValue(value);
1771
+ return this.value(value);
1772
+ };
1773
+
1774
+ HorizontalSplitter.prototype.valueWidth = function() {
1775
+ return this.container.height();
1776
+ };
1777
+
1778
+ HorizontalSplitter.prototype.minValue = function() {
1779
+ var m1, m2;
1780
+ m1 = this.fst.element.minHeight() + this.fst.element.nonContentHeight();
1781
+ m2 = this.snd.element.maxHeight() + this.snd.element.nonContentHeight();
1782
+ if (m2 != null) {
1783
+ m2 = this.valueWidth() - m2;
1784
+ }
1785
+ if ((m1 != null) && (m2 != null)) {
1786
+ return Math.min(m1, m2);
1787
+ }
1788
+ return m1 || m2 || 0;
1789
+ };
1790
+
1791
+ HorizontalSplitter.prototype.maxValue = function() {
1792
+ var m1, m2, valueWidth;
1793
+ valueWidth = this.valueWidth();
1794
+ m1 = this.fst.element.maxHeight() + this.fst.element.nonContentHeight();
1795
+ m2 = this.snd.element.minHeight() + this.snd.element.nonContentHeight();
1796
+ if (m2 != null) {
1797
+ m2 = valueWidth - m2;
1798
+ }
1799
+ if ((m1 != null) && (m2 != null)) {
1800
+ return Math.max(m1, m2);
1801
+ }
1802
+ return m1 || m2 || valueWidth;
1803
+ };
1804
+
1805
+ HorizontalSplitter.prototype.adjust = function() {
1806
+ var fstValue, sndValue, value, valueWidth;
1807
+ value = this.value();
1808
+ valueWidth = this.valueWidth();
1809
+ fstValue = value - this.fst.element.nonContentHeight(true);
1810
+ sndValue = (valueWidth - value) - this.snd.element.nonContentHeight(true);
1811
+ if (fstValue <= 0) {
1812
+ if (this.fst.element.is(':visible')) {
1813
+ this.fst.element.hide();
1814
+ }
1815
+ if (!this.snd.element.is(':visible')) {
1816
+ this.snd.element.show();
1817
+ }
1818
+ this.snd.element.outerHeight(true, valueWidth);
1819
+ this._value = value = 0;
1820
+ } else if (sndValue <= 0) {
1821
+ if (!this.fst.element.is(':visible')) {
1822
+ this.fst.element.show();
1823
+ }
1824
+ if (this.snd.element.is(':visible')) {
1825
+ this.snd.element.hide();
1826
+ }
1827
+ this.fst.element.outerHeight(true, valueWidth);
1828
+ this._value = value = valueWidth;
1829
+ } else {
1830
+ if (!this.fst.element.is(':visible')) {
1831
+ this.fst.element.show();
1832
+ }
1833
+ if (!this.snd.element.is(':visible')) {
1834
+ this.snd.element.show();
1835
+ }
1836
+ this.fst.element.height(fstValue);
1837
+ this.snd.element.height(sndValue);
1838
+ }
1839
+ this.fst.adjust();
1840
+ this.snd.adjust();
1841
+ this.element.relativeY(value - this.element.outerHeight() / 2);
1842
+ return this;
1843
+ };
1844
+
1845
+ return HorizontalSplitter;
1846
+
1847
+ })(Splitter);
1848
+
1849
+ namespace('Jencil.ui.widgets.splitters', function(exports) {
1850
+ exports.Splitter = Splitter;
1851
+ exports.VerticalSplitter = VerticalSplitter;
1852
+ return exports.HorizontalSplitter = HorizontalSplitter;
1853
+ });
1854
+
1855
+ BaseEditor = (function(_super) {
1856
+
1857
+ __extends(BaseEditor, _super);
1858
+
1859
+ function BaseEditor(core, selector, context) {
1860
+ if (selector == null) {
1861
+ selector = '<div>';
1862
+ }
1863
+ BaseEditor.__super__.constructor.call(this, core, selector, context);
1864
+ this.element.addClass('editor');
1865
+ this._changeCallbacks = [];
1866
+ }
1867
+
1868
+ BaseEditor.prototype.val = function(value) {
1869
+ throw new Error("NotImplementedError");
1870
+ };
1871
+
1872
+ BaseEditor.prototype.change = function(callback) {
1873
+ var _i, _len, _ref;
1874
+ if (callback != null) {
1875
+ this._changeCallbacks.push(callback);
1876
+ return this;
1877
+ }
1878
+ _ref = this._changeCallbacks;
1879
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
1880
+ callback = _ref[_i];
1881
+ callback.call(this, this.val());
1882
+ }
1883
+ return this;
1884
+ };
1885
+
1886
+ BaseEditor.prototype.h1 = null;
1887
+
1888
+ BaseEditor.prototype.h2 = null;
1889
+
1890
+ BaseEditor.prototype.h3 = null;
1891
+
1892
+ BaseEditor.prototype.h4 = null;
1893
+
1894
+ BaseEditor.prototype.h5 = null;
1895
+
1896
+ BaseEditor.prototype.h6 = null;
1897
+
1898
+ BaseEditor.prototype.bold = null;
1899
+
1900
+ BaseEditor.prototype.italic = null;
1901
+
1902
+ BaseEditor.prototype.underline = null;
1903
+
1904
+ BaseEditor.prototype.strike = null;
1905
+
1906
+ BaseEditor.prototype.superscript = null;
1907
+
1908
+ BaseEditor.prototype.subscript = null;
1909
+
1910
+ BaseEditor.prototype.anchor = null;
1911
+
1912
+ BaseEditor.prototype.image = null;
1913
+
1914
+ BaseEditor.prototype.unorderedList = null;
1915
+
1916
+ BaseEditor.prototype.orderedList = null;
1917
+
1918
+ return BaseEditor;
1919
+
1920
+ })(Panel);
1921
+
1922
+ TextEditor = (function(_super) {
1923
+
1924
+ __extends(TextEditor, _super);
1925
+
1926
+ function TextEditor(core, selector, context) {
1927
+ var _this = this;
1928
+ if (selector == null) {
1929
+ selector = '<div>';
1930
+ }
1931
+ TextEditor.__super__.constructor.call(this, core, selector, context);
1932
+ this.textarea = $('<textarea>').appendTo(this.element).css({
1933
+ 'margin': '0',
1934
+ 'padding': '0',
1935
+ 'border': 'none',
1936
+ 'outline': 'none',
1937
+ 'resize': 'none'
1938
+ });
1939
+ this.textarea = evolute(this.textarea);
1940
+ this.textarea.on('keydown', function(e) {
1941
+ if (e.which !== 13) {
1942
+ return;
1943
+ }
1944
+ return _this.core.caretaker.save();
1945
+ });
1946
+ if (($.fn.tabby != null) && this.core.options.enableTabIndent) {
1947
+ this.textarea.tabby({
1948
+ 'tabString': this.core.options.tabString
1949
+ });
1950
+ }
1951
+ this.textarea = autoIndentable(this.textarea);
1952
+ if (!this.core.options.enableAutoIndent) {
1953
+ this.textarea.autoIndent.disable();
1954
+ }
1955
+ this.textarea.on('keypress keyup click blur', function() {
1956
+ return _this.change();
1957
+ });
1958
+ }
1959
+
1960
+ TextEditor.prototype.val = function(value) {
1961
+ if (value != null) {
1962
+ this.textarea.val(value);
1963
+ this.change();
1964
+ return this;
1965
+ }
1966
+ return this.textarea.val();
1967
+ };
1968
+
1969
+ TextEditor.prototype.focus = function() {
1970
+ this.textarea.focus();
1971
+ return this;
1972
+ };
1973
+
1974
+ TextEditor.prototype.createMemento = function() {
1975
+ return this.val();
1976
+ };
1977
+
1978
+ TextEditor.prototype.setMemento = function(memento) {
1979
+ return this.val(memento);
1980
+ };
1981
+
1982
+ TextEditor.prototype.adjust = function() {
1983
+ this.textarea.outerWidth(this.element.width());
1984
+ this.textarea.outerHeight(this.element.height());
1985
+ return this;
1986
+ };
1987
+
1988
+ TextEditor.prototype.selection = function(str, keepSelection) {
1989
+ if (keepSelection == null) {
1990
+ keepSelection = true;
1991
+ }
1992
+ if (str != null) {
1993
+ this.textarea.selection.text(str, keepSelection);
1994
+ this.core.caretaker.save();
1995
+ return this.change();
1996
+ }
1997
+ return this.textarea.selection.text();
1998
+ };
1999
+
2000
+ TextEditor.prototype.enclose = function(b, a, keepSelection) {
2001
+ var caret;
2002
+ if (keepSelection == null) {
2003
+ keepSelection = true;
2004
+ }
2005
+ caret = this.textarea.selection.caret();
2006
+ if (caret[0] === caret[1]) {
2007
+ this.textarea.selection.selectWholeCurrentLine();
2008
+ }
2009
+ this.textarea.selection.enclose(b, a, keepSelection);
2010
+ this.core.caretaker.save();
2011
+ return this.change();
2012
+ };
2013
+
2014
+ TextEditor.prototype.insertBefore = function(str, keepSelection) {
2015
+ var caret;
2016
+ if (keepSelection == null) {
2017
+ keepSelection = true;
2018
+ }
2019
+ caret = this.textarea.selection.caret();
2020
+ if (caret[0] === caret[1]) {
2021
+ this.textarea.selection.selectWholeCurrentLine();
2022
+ }
2023
+ this.textarea.selection.insertBefore(str, keepSelection);
2024
+ this.core.caretaker.save();
2025
+ return this.change();
2026
+ };
2027
+
2028
+ TextEditor.prototype.insertAfter = function(str, keepSelection) {
2029
+ var caret;
2030
+ if (keepSelection == null) {
2031
+ keepSelection = true;
2032
+ }
2033
+ caret = this.textarea.selection.caret();
2034
+ if (caret[0] === caret[1]) {
2035
+ this.textarea.selection.selectWholeCurrentLine();
2036
+ }
2037
+ this.textarea.selection.insertAfter(str, keepSelection);
2038
+ this.core.caretaker.save();
2039
+ return this.change();
2040
+ };
2041
+
2042
+ return TextEditor;
2043
+
2044
+ })(BaseEditor);
2045
+
2046
+ namespace('Jencil.ui.widgets.editors', function(exports) {
2047
+ exports.BaseEditor = BaseEditor;
2048
+ return exports.TextEditor = TextEditor;
2049
+ });
2050
+
2051
+ BaseViewer = (function(_super) {
2052
+
2053
+ __extends(BaseViewer, _super);
2054
+
2055
+ function BaseViewer(core, selector, context) {
2056
+ if (selector == null) {
2057
+ selector = '<div>';
2058
+ }
2059
+ BaseViewer.__super__.constructor.call(this, core, selector, context);
2060
+ this.element.addClass('viewer');
2061
+ }
2062
+
2063
+ BaseViewer.prototype.update = function(value, force) {
2064
+ throw new Error("NotImplementedError");
2065
+ };
2066
+
2067
+ return BaseViewer;
2068
+
2069
+ })(Panel);
2070
+
2071
+ TemplateViewer = (function(_super) {
2072
+
2073
+ __extends(TemplateViewer, _super);
2074
+
2075
+ function TemplateViewer(core) {
2076
+ TemplateViewer.__super__.constructor.call(this, core);
2077
+ this.templatePath = this.core.options.viewerTemplatePath;
2078
+ this.element.css({
2079
+ 'position': 'relative'
2080
+ });
2081
+ this.curtain = curtainFactory(this.element);
2082
+ this.iframe = $('<iframe>').appendTo(this.element).css({
2083
+ margin: '0',
2084
+ padding: '0',
2085
+ border: 'none',
2086
+ outline: 'none',
2087
+ resize: 'none',
2088
+ width: '100%',
2089
+ height: '100%',
2090
+ overflow: 'visible'
2091
+ });
2092
+ this.iframe.attr('frameborder', 0);
2093
+ this.iframe = evolute(this.iframe);
2094
+ this.iframe.init = function() {
2095
+ var iframe;
2096
+ iframe = this.get(0);
2097
+ if (iframe.contentDocument != null) {
2098
+ this.document = iframe.contentDocument;
2099
+ } else {
2100
+ this.document = iframe.contentWindow.document;
2101
+ }
2102
+ return this.document.write('<body></body>');
2103
+ };
2104
+ this.iframe.write = function(value) {
2105
+ var scrollTop;
2106
+ if (this.document != null) {
2107
+ try {
2108
+ scrollTop = this.document.documentElement.scrollTop;
2109
+ } catch (e) {
2110
+ scrollTop = 0;
2111
+ }
2112
+ this.document.open();
2113
+ this.document.write(value);
2114
+ this.document.close();
2115
+ $("a", $(this.document)).attr('target', '_blank');
2116
+ this.document.documentElement.scrollTop = scrollTop;
2117
+ this.width(this.document.scrollLeft);
2118
+ this.height(this.document.scrollTop);
2119
+ return true;
2120
+ }
2121
+ return false;
2122
+ };
2123
+ this.iframe.loadTemplate = function(templatePath, value) {
2124
+ var _this = this;
2125
+ return $.ajax({
2126
+ url: templatePath,
2127
+ success: function(data) {
2128
+ _this._template = data;
2129
+ return _this.write(value);
2130
+ }
2131
+ });
2132
+ };
2133
+ }
2134
+
2135
+ TemplateViewer.prototype.init = function() {
2136
+ return this.iframe.init();
2137
+ };
2138
+
2139
+ TemplateViewer.prototype.update = function(value, force) {
2140
+ if (this.iframe._template != null) {
2141
+ value = this.iframe._template.replace("{{content}}", value);
2142
+ } else if (this.templatePath != null) {
2143
+ this.iframe.loadTemplate(this.templatePath, value);
2144
+ }
2145
+ return this.iframe.write(value);
2146
+ };
2147
+
2148
+ TemplateViewer.prototype.adjust = function() {
2149
+ this.iframe.outerWidth(this.element.width());
2150
+ this.iframe.outerHeight(this.element.height());
2151
+ return this;
2152
+ };
2153
+
2154
+ return TemplateViewer;
2155
+
2156
+ })(BaseViewer);
2157
+
2158
+ AjaxViewer = (function(_super) {
2159
+
2160
+ __extends(AjaxViewer, _super);
2161
+
2162
+ function AjaxViewer(core, config) {
2163
+ this.config = config;
2164
+ AjaxViewer.__super__.constructor.call(this, core);
2165
+ this.config = jQuery.extend({
2166
+ type: 'GET',
2167
+ dataType: 'text',
2168
+ data: function(value) {
2169
+ return encodeURIComponent(value);
2170
+ },
2171
+ url: null
2172
+ }, this.config);
2173
+ }
2174
+
2175
+ AjaxViewer.prototype.update = function(value, force) {
2176
+ var _this = this;
2177
+ if (this._valueCache !== value || force) {
2178
+ this._valueCache = value;
2179
+ return $.ajax({
2180
+ type: this.config.type,
2181
+ dataType: this.config.dataType,
2182
+ data: JSON.stringify(this.config.data(value)),
2183
+ url: this.config.url,
2184
+ success: function(value) {
2185
+ if (_this.iframe._template != null) {
2186
+ value = _this.iframe._template.replace("{{content}}", value);
2187
+ } else if (_this.templatePath != null) {
2188
+ _this.iframe.loadTemplate(_this.templatePath, value);
2189
+ }
2190
+ return _this.iframe.write(value);
2191
+ }
2192
+ });
2193
+ }
2194
+ };
2195
+
2196
+ return AjaxViewer;
2197
+
2198
+ })(TemplateViewer);
2199
+
2200
+ namespace('Jencil.ui.widgets.viewers', function(exports) {
2201
+ exports.BaseViewer = BaseViewer;
2202
+ exports.TemplateViewer = TemplateViewer;
2203
+ return exports.AjaxViewer = AjaxViewer;
2204
+ });
2205
+
2206
+ BaseHelper = (function(_super) {
2207
+
2208
+ __extends(BaseHelper, _super);
2209
+
2210
+ function BaseHelper(core, selector, context) {
2211
+ if (selector == null) {
2212
+ selector = '<div>';
2213
+ }
2214
+ BaseHelper.__super__.constructor.call(this, core, selector, context);
2215
+ this.element.addClass('helper');
2216
+ }
2217
+
2218
+ return BaseHelper;
2219
+
2220
+ })(Panel);
2221
+
2222
+ TemplateHelper = (function(_super) {
2223
+
2224
+ __extends(TemplateHelper, _super);
2225
+
2226
+ function TemplateHelper(core) {
2227
+ TemplateHelper.__super__.constructor.call(this, core);
2228
+ this.templatePath = this.core.options.helperTemplatePath;
2229
+ this.element.css({
2230
+ 'position': 'relative'
2231
+ });
2232
+ this.curtain = curtainFactory(this.element);
2233
+ this.iframe = $('<iframe>').appendTo(this.element).css({
2234
+ margin: '0',
2235
+ padding: '0',
2236
+ border: 'none',
2237
+ outline: 'none',
2238
+ resize: 'none',
2239
+ width: '100%',
2240
+ height: '100%',
2241
+ overflow: 'visible'
2242
+ });
2243
+ this.iframe.attr('frameborder', 0);
2244
+ this.iframe = evolute(this.iframe);
2245
+ this.iframe.init = function() {
2246
+ var iframe;
2247
+ iframe = this.get(0);
2248
+ if (iframe.contentDocument != null) {
2249
+ this.document = iframe.contentDocument;
2250
+ } else {
2251
+ this.document = iframe.contentWindow.document;
2252
+ }
2253
+ return this.document.write('<body></body>');
2254
+ };
2255
+ this.iframe.write = function(value) {
2256
+ var scrollTop;
2257
+ if (this.document != null) {
2258
+ try {
2259
+ scrollTop = this.document.documentElement.scrollTop;
2260
+ } catch (e) {
2261
+ scrollTop = 0;
2262
+ }
2263
+ this.document.open();
2264
+ this.document.write(value);
2265
+ this.document.close();
2266
+ this.document.documentElement.scrollTop = scrollTop;
2267
+ this.width(this.document.scrollLeft);
2268
+ this.height(this.document.scrollTop);
2269
+ return true;
2270
+ }
2271
+ return false;
2272
+ };
2273
+ this.iframe.loadTemplate = function(templatePath) {
2274
+ var _this = this;
2275
+ return $.ajax({
2276
+ url: templatePath,
2277
+ success: function(data) {
2278
+ return _this.write(data);
2279
+ }
2280
+ });
2281
+ };
2282
+ }
2283
+
2284
+ TemplateHelper.prototype.init = function() {
2285
+ this.iframe.init();
2286
+ if (this.templatePath != null) {
2287
+ return this.iframe.loadTemplate(this.templatePath);
2288
+ }
2289
+ };
2290
+
2291
+ TemplateHelper.prototype.adjust = function() {
2292
+ this.iframe.outerWidth(this.element.width());
2293
+ this.iframe.outerHeight(this.element.height());
2294
+ return this;
2295
+ };
2296
+
2297
+ return TemplateHelper;
2298
+
2299
+ })(BaseHelper);
2300
+
2301
+ namespace('Jencil.ui.widgets.helpers', function(exports) {
2302
+ exports.BaseHelper = BaseHelper;
2303
+ return exports.TemplateHelper = TemplateHelper;
2304
+ });
2305
+
2306
+ Separator = (function(_super) {
2307
+
2308
+ __extends(Separator, _super);
2309
+
2310
+ function Separator(core) {
2311
+ Separator.__super__.constructor.call(this, core, '<span>');
2312
+ this.element.addClass('separator');
2313
+ }
2314
+
2315
+ return Separator;
2316
+
2317
+ })(Widget);
2318
+
2319
+ Button = (function(_super) {
2320
+
2321
+ __extends(Button, _super);
2322
+
2323
+ function Button(core, name, text, title) {
2324
+ this.name = name;
2325
+ this.text = text;
2326
+ this.title = title;
2327
+ Button.__super__.constructor.call(this, core, '<a>');
2328
+ this.text = Jencil.t(this.text || this.name);
2329
+ this.title = Jencil.t(this.title || this.text);
2330
+ this.element.addClass('button').addClass(name);
2331
+ this.element.append($("<span>" + this.text + "</span>"));
2332
+ this.element.attr('title', this.title);
2333
+ }
2334
+
2335
+ Button.prototype.enable = function() {
2336
+ return this.element.removeClass('disable');
2337
+ };
2338
+
2339
+ Button.prototype.disable = function() {
2340
+ return this.element.addClass('disable');
2341
+ };
2342
+
2343
+ Button.prototype.validate = function() {
2344
+ return this;
2345
+ };
2346
+
2347
+ return Button;
2348
+
2349
+ })(Widget);
2350
+
2351
+ ActionButton = (function(_super) {
2352
+
2353
+ __extends(ActionButton, _super);
2354
+
2355
+ function ActionButton(core, name, text, title, callback, shortcut) {
2356
+ var _this = this;
2357
+ this.shortcut = shortcut;
2358
+ ActionButton.__super__.constructor.call(this, core, name, text, title);
2359
+ this.callback = function() {
2360
+ if (!_this.element.hasClass('disable')) {
2361
+ return callback();
2362
+ }
2363
+ };
2364
+ this.callback.raw = callback;
2365
+ this.element.click(function() {
2366
+ return _this.callback();
2367
+ });
2368
+ if ((this.shortcut != null) && (window.shortcut != null)) {
2369
+ window.shortcut.add(this.shortcut, function(e) {
2370
+ return _this.callback();
2371
+ });
2372
+ this.element.attr('title', "" + this.title + " (" + this.shortcut + ")");
2373
+ }
2374
+ }
2375
+
2376
+ return ActionButton;
2377
+
2378
+ })(Button);
2379
+
2380
+ CommandButton = (function(_super) {
2381
+
2382
+ __extends(CommandButton, _super);
2383
+
2384
+ function CommandButton(core, name, text, title, command, shortcut) {
2385
+ var callback;
2386
+ this.command = command;
2387
+ callback = function() {
2388
+ var editor;
2389
+ editor = core.editor();
2390
+ return editor[command].call(editor);
2391
+ };
2392
+ CommandButton.__super__.constructor.call(this, core, name, text, title, callback, shortcut);
2393
+ }
2394
+
2395
+ CommandButton.prototype.init = function() {
2396
+ return this.validate();
2397
+ };
2398
+
2399
+ CommandButton.prototype.validate = function() {
2400
+ var editor;
2401
+ editor = this.core.editor();
2402
+ if (!(editor[this.command] != null)) {
2403
+ this.disable();
2404
+ }
2405
+ return this;
2406
+ };
2407
+
2408
+ CommandButton.factory = function(core, args) {
2409
+ var command, name, shortcut, text, title;
2410
+ name = text = title = command = shortcut = null;
2411
+ switch (args.length) {
2412
+ case 5:
2413
+ name = args[0];
2414
+ text = args[1];
2415
+ title = args[2];
2416
+ command = args[3];
2417
+ shortcut = args[4];
2418
+ break;
2419
+ case 4:
2420
+ name = args[0];
2421
+ text = title = args[1];
2422
+ command = args[2];
2423
+ shortcut = args[3];
2424
+ break;
2425
+ case 3:
2426
+ name = command = args[0];
2427
+ text = title = args[1];
2428
+ shortcut = args[2];
2429
+ break;
2430
+ case 2:
2431
+ name = command = args[0];
2432
+ text = title = args[1];
2433
+ shortcut = null;
2434
+ break;
2435
+ case 1:
2436
+ name = command = text = title = args[0];
2437
+ shortcut = null;
2438
+ }
2439
+ return new CommandButton(core, name, text, title, command, shortcut);
2440
+ };
2441
+
2442
+ return CommandButton;
2443
+
2444
+ })(ActionButton);
2445
+
2446
+ UndoButton = (function(_super) {
2447
+
2448
+ __extends(UndoButton, _super);
2449
+
2450
+ function UndoButton(core) {
2451
+ var callback,
2452
+ _this = this;
2453
+ callback = function(e) {
2454
+ return _this.core.caretaker.undo();
2455
+ };
2456
+ UndoButton.__super__.constructor.call(this, core, 'undo', 'Undo', 'Undo', callback, 'Ctrl+Z');
2457
+ }
2458
+
2459
+ UndoButton.prototype.init = function() {
2460
+ var check,
2461
+ _this = this;
2462
+ check = function() {
2463
+ if (!_this.core.caretaker.canUndo()) {
2464
+ _this.disable();
2465
+ } else {
2466
+ _this.enable();
2467
+ }
2468
+ return setTimeout(check, 100);
2469
+ };
2470
+ return check();
2471
+ };
2472
+
2473
+ return UndoButton;
2474
+
2475
+ })(ActionButton);
2476
+
2477
+ RedoButton = (function(_super) {
2478
+
2479
+ __extends(RedoButton, _super);
2480
+
2481
+ function RedoButton(core) {
2482
+ var callback,
2483
+ _this = this;
2484
+ callback = function(e) {
2485
+ return _this.core.caretaker.redo();
2486
+ };
2487
+ RedoButton.__super__.constructor.call(this, core, 'redo', 'Redo', 'Redo', callback, 'Ctrl+Shift+Z');
2488
+ }
2489
+
2490
+ RedoButton.prototype.init = function() {
2491
+ var check,
2492
+ _this = this;
2493
+ check = function() {
2494
+ if (!_this.core.caretaker.canRedo()) {
2495
+ _this.disable();
2496
+ } else {
2497
+ _this.enable();
2498
+ }
2499
+ return setTimeout(check, 100);
2500
+ };
2501
+ return check();
2502
+ };
2503
+
2504
+ return RedoButton;
2505
+
2506
+ })(ActionButton);
2507
+
2508
+ FullscreenButton = (function(_super) {
2509
+
2510
+ __extends(FullscreenButton, _super);
2511
+
2512
+ function FullscreenButton(core) {
2513
+ var callback,
2514
+ _this = this;
2515
+ callback = function(e) {
2516
+ return _this.core.fullscreen.toggle();
2517
+ };
2518
+ FullscreenButton.__super__.constructor.call(this, core, 'fullscreen', 'Toggle fullscreen', 'Fullscreen', callback, 'Ctrl+F');
2519
+ }
2520
+
2521
+ FullscreenButton.prototype.init = function() {
2522
+ var check,
2523
+ _this = this;
2524
+ check = function() {
2525
+ if (_this.core.fullscreen.element.is(':visible')) {
2526
+ _this.element.addClass('hide');
2527
+ } else {
2528
+ _this.element.removeClass('hide');
2529
+ }
2530
+ return setTimeout(check, 100);
2531
+ };
2532
+ return check();
2533
+ };
2534
+
2535
+ return FullscreenButton;
2536
+
2537
+ })(ActionButton);
2538
+
2539
+ ViewerButton = (function(_super) {
2540
+
2541
+ __extends(ViewerButton, _super);
2542
+
2543
+ function ViewerButton(core) {
2544
+ var callback,
2545
+ _this = this;
2546
+ callback = function(e) {
2547
+ return _this.core.viewer().toggle();
2548
+ };
2549
+ ViewerButton.__super__.constructor.call(this, core, 'viewer', 'Quick view', 'Quick view', callback, 'Ctrl+Q');
2550
+ }
2551
+
2552
+ ViewerButton.prototype.validate = function() {
2553
+ if (!this.core.viewer()) {
2554
+ this.disable();
2555
+ return false;
2556
+ }
2557
+ return true;
2558
+ };
2559
+
2560
+ ViewerButton.prototype.init = function() {
2561
+ var check,
2562
+ _this = this;
2563
+ if (!this.validate()) {
2564
+ return;
2565
+ }
2566
+ check = function() {
2567
+ if (_this.core.viewer().element.is(':visible')) {
2568
+ _this.element.addClass('hide');
2569
+ } else {
2570
+ _this.element.removeClass('hide');
2571
+ }
2572
+ return setTimeout(check, 100);
2573
+ };
2574
+ return check();
2575
+ };
2576
+
2577
+ return ViewerButton;
2578
+
2579
+ })(ActionButton);
2580
+
2581
+ HelperButton = (function(_super) {
2582
+
2583
+ __extends(HelperButton, _super);
2584
+
2585
+ function HelperButton(core) {
2586
+ var callback,
2587
+ _this = this;
2588
+ callback = function(e) {
2589
+ return _this.core.helper().toggle();
2590
+ };
2591
+ HelperButton.__super__.constructor.call(this, core, 'helper', 'Help', 'Help', callback, 'Ctrl+H');
2592
+ }
2593
+
2594
+ HelperButton.prototype.validate = function() {
2595
+ if (!this.core.helper()) {
2596
+ this.disable();
2597
+ return false;
2598
+ }
2599
+ return true;
2600
+ };
2601
+
2602
+ HelperButton.prototype.init = function() {
2603
+ var check,
2604
+ _this = this;
2605
+ if (!this.validate()) {
2606
+ return;
2607
+ }
2608
+ check = function() {
2609
+ if (_this.core.helper().element.is(':visible')) {
2610
+ _this.element.addClass('hide');
2611
+ } else {
2612
+ _this.element.removeClass('hide');
2613
+ }
2614
+ return setTimeout(check, 100);
2615
+ };
2616
+ return check();
2617
+ };
2618
+
2619
+ return HelperButton;
2620
+
2621
+ })(ActionButton);
2622
+
2623
+ buttonFactory = function(core, value) {
2624
+ if (value instanceof Array) {
2625
+ return CommandButton.factory(core, value);
2626
+ }
2627
+ if (typeof value === 'string') {
2628
+ switch (value) {
2629
+ case 'Separator':
2630
+ return new Separator(core);
2631
+ case 'Undo':
2632
+ return new UndoButton(core);
2633
+ case 'Redo':
2634
+ return new RedoButton(core);
2635
+ case 'Fullscreen':
2636
+ return new FullscreenButton(core);
2637
+ case 'Viewer':
2638
+ return new ViewerButton(core);
2639
+ case 'Helper':
2640
+ return new HelperButton(core);
2641
+ default:
2642
+ throw new Exception("" + value + " is not known Button type");
2643
+ }
2644
+ }
2645
+ return new value(core);
2646
+ };
2647
+
2648
+ namespace('Jencil.ui.widgets.buttons', function(exports) {
2649
+ exports.Separator = Separator;
2650
+ exports.Button = Button;
2651
+ exports.ActionButton = ActionButton;
2652
+ exports.CommandButton = CommandButton;
2653
+ exports.UndoButton = UndoButton;
2654
+ exports.RedoButton = RedoButton;
2655
+ exports.FullscreenButton = FullscreenButton;
2656
+ exports.ViewerButton = ViewerButton;
2657
+ return exports.HelperButton = HelperButton;
2658
+ });
2659
+
2660
+ Wrapper = (function(_super) {
2661
+
2662
+ __extends(Wrapper, _super);
2663
+
2664
+ function Wrapper(core, width, height) {
2665
+ Wrapper.__super__.constructor.call(this, core);
2666
+ this.element.addClass('jencil wrapper');
2667
+ this.element.width(width);
2668
+ this.element.height(height);
2669
+ this.workspace = new Workspace(this.core);
2670
+ this.workspace.element.appendTo(this.element);
2671
+ }
2672
+
2673
+ Wrapper.prototype.init = function() {
2674
+ var _this = this;
2675
+ if ((this.element.resizable != null) && this.core.options.resizable === true) {
2676
+ this.element.resizable({
2677
+ start: function() {
2678
+ var _ref, _ref1, _ref2, _ref3, _ref4, _ref5;
2679
+ if ((_ref = _this.core.editor()) != null) {
2680
+ if ((_ref1 = _ref.curtain) != null) {
2681
+ _ref1.on();
2682
+ }
2683
+ }
2684
+ if ((_ref2 = _this.core.viewer()) != null) {
2685
+ if ((_ref3 = _ref2.curtain) != null) {
2686
+ _ref3.on();
2687
+ }
2688
+ }
2689
+ return (_ref4 = _this.core.helper()) != null ? (_ref5 = _ref4.curtain) != null ? _ref5.on() : void 0 : void 0;
2690
+ },
2691
+ resize: function() {
2692
+ var _ref, _ref1, _ref2, _ref3, _ref4, _ref5;
2693
+ if ((_ref = _this.core.editor()) != null) {
2694
+ if ((_ref1 = _ref.curtain) != null) {
2695
+ _ref1.refresh();
2696
+ }
2697
+ }
2698
+ if ((_ref2 = _this.core.viewer()) != null) {
2699
+ if ((_ref3 = _ref2.curtain) != null) {
2700
+ _ref3.refresh();
2701
+ }
2702
+ }
2703
+ if ((_ref4 = _this.core.helper()) != null) {
2704
+ if ((_ref5 = _ref4.curtain) != null) {
2705
+ _ref5.refresh();
2706
+ }
2707
+ }
2708
+ return _this.adjust();
2709
+ },
2710
+ stop: function() {
2711
+ var _ref, _ref1, _ref2, _ref3, _ref4, _ref5;
2712
+ if ((_ref = _this.core.editor()) != null) {
2713
+ if ((_ref1 = _ref.curtain) != null) {
2714
+ _ref1.off();
2715
+ }
2716
+ }
2717
+ if ((_ref2 = _this.core.viewer()) != null) {
2718
+ if ((_ref3 = _ref2.curtain) != null) {
2719
+ _ref3.off();
2720
+ }
2721
+ }
2722
+ if ((_ref4 = _this.core.helper()) != null) {
2723
+ if ((_ref5 = _ref4.curtain) != null) {
2724
+ _ref5.off();
2725
+ }
2726
+ }
2727
+ return _this.adjust();
2728
+ }
2729
+ });
2730
+ }
2731
+ return this.workspace.init();
2732
+ };
2733
+
2734
+ Wrapper.prototype.adjust = function() {
2735
+ this.workspace.element.outerWidth(true, this.element.width());
2736
+ this.workspace.element.outerHeight(true, this.element.height());
2737
+ this.workspace.adjust();
2738
+ return this;
2739
+ };
2740
+
2741
+ return Wrapper;
2742
+
2743
+ })(Panel);
2744
+
2745
+ Workspace = (function(_super) {
2746
+
2747
+ __extends(Workspace, _super);
2748
+
2749
+ function Workspace(core) {
2750
+ Workspace.__super__.constructor.call(this, core);
2751
+ this.element.addClass('workspace');
2752
+ this.profile(core.options.profile);
2753
+ }
2754
+
2755
+ Workspace.prototype.profile = function(profile) {
2756
+ var button, _i, _j, _len, _len1, _ref, _ref1, _ref2, _ref3,
2757
+ _this = this;
2758
+ if (profile != null) {
2759
+ if (typeof profile === 'string') {
2760
+ profile = this.core.options.profiles[profile];
2761
+ }
2762
+ profile = jQuery.extend(DefaultProfile, profile);
2763
+ profile.defaultVolume = this.core.options.defaultVolume || profile.defaultVolume;
2764
+ profile.defaultVolume2 = this.core.options.defaultVolume2 || profile.defaultVolume2;
2765
+ this.element.empty();
2766
+ this.mainPanel = new profile.mainPanelClass(this.core, profile);
2767
+ if ((_ref = this.mainPanel.editorPanel) != null) {
2768
+ _ref.val(this.core.element.val());
2769
+ }
2770
+ if ((_ref1 = this.mainPanel.editorPanel) != null) {
2771
+ _ref1.change(function(value) {
2772
+ return _this.core.element.val(value);
2773
+ });
2774
+ }
2775
+ this.toolbar = new Toolbar(this.core);
2776
+ _ref2 = profile.toolbarButtons;
2777
+ for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
2778
+ button = _ref2[_i];
2779
+ button = buttonFactory(this.core, button);
2780
+ this.toolbar.addButton(button);
2781
+ }
2782
+ this.statusbar = new Statusbar(this.core);
2783
+ _ref3 = profile.statusbarButtons;
2784
+ for (_j = 0, _len1 = _ref3.length; _j < _len1; _j++) {
2785
+ button = _ref3[_j];
2786
+ button = buttonFactory(this.core, button);
2787
+ this.statusbar.addButton(button);
2788
+ }
2789
+ this.element.append(this.toolbar.element);
2790
+ this.element.append(this.mainPanel.element);
2791
+ this.element.append(this.statusbar.element);
2792
+ this._profile = profile;
2793
+ return this;
2794
+ }
2795
+ return this._profile;
2796
+ };
2797
+
2798
+ Workspace.prototype.init = function() {
2799
+ this.toolbar.init();
2800
+ this.statusbar.init();
2801
+ return this.mainPanel.init();
2802
+ };
2803
+
2804
+ Workspace.prototype.adjust = function() {
2805
+ var offset1, offset2;
2806
+ this.toolbar.element.outerWidth(true, this.element.width());
2807
+ this.statusbar.element.outerWidth(true, this.element.width());
2808
+ this.mainPanel.element.outerWidth(true, this.element.width());
2809
+ this.mainPanel.element.outerHeight(true, this.element.height());
2810
+ this.mainPanel.adjust();
2811
+ offset1 = this.toolbar.element.outerHeight(true);
2812
+ offset2 = this.statusbar.element.outerHeight(true);
2813
+ this.mainPanel.element.outerHeight(true, this.element.height() - (offset1 + offset2));
2814
+ this.toolbar.adjust();
2815
+ this.statusbar.adjust();
2816
+ this.mainPanel.adjust();
2817
+ return this;
2818
+ };
2819
+
2820
+ Workspace.prototype.update = function(force) {
2821
+ if (this.mainPanel.editorPanel && this.mainPanel.viewerPanel) {
2822
+ return this.mainPanel.viewerPanel.update(this.mainPanel.editorPanel.val(), force);
2823
+ }
2824
+ };
2825
+
2826
+ return Workspace;
2827
+
2828
+ })(Panel);
2829
+
2830
+ Bar = (function(_super) {
2831
+
2832
+ __extends(Bar, _super);
2833
+
2834
+ function Bar(core) {
2835
+ Bar.__super__.constructor.call(this, core);
2836
+ this._buttons = [];
2837
+ }
2838
+
2839
+ Bar.prototype.init = function() {
2840
+ var button, _i, _len, _ref;
2841
+ _ref = this._buttons;
2842
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
2843
+ button = _ref[_i];
2844
+ button.init();
2845
+ }
2846
+ return this;
2847
+ };
2848
+
2849
+ Bar.prototype.addButton = function(button) {
2850
+ this._buttons.push(button);
2851
+ return this.element.append(button.element);
2852
+ };
2853
+
2854
+ return Bar;
2855
+
2856
+ })(Panel);
2857
+
2858
+ Toolbar = (function(_super) {
2859
+
2860
+ __extends(Toolbar, _super);
2861
+
2862
+ function Toolbar(core) {
2863
+ Toolbar.__super__.constructor.call(this, core);
2864
+ this.element.addClass('toolbar');
2865
+ }
2866
+
2867
+ return Toolbar;
2868
+
2869
+ })(Bar);
2870
+
2871
+ Statusbar = (function(_super) {
2872
+
2873
+ __extends(Statusbar, _super);
2874
+
2875
+ function Statusbar(core) {
2876
+ Statusbar.__super__.constructor.call(this, core);
2877
+ this.element.addClass('statusbar');
2878
+ }
2879
+
2880
+ return Statusbar;
2881
+
2882
+ })(Bar);
2883
+
2884
+ MonomainPanel = (function() {
2885
+
2886
+ function MonomainPanel(core, profile) {
2887
+ var editorPanel;
2888
+ editorPanel = new profile.editorClass(core);
2889
+ editorPanel.element.addClass('mainPanel');
2890
+ return editorPanel;
2891
+ }
2892
+
2893
+ return MonomainPanel;
2894
+
2895
+ })();
2896
+
2897
+ DimainPanel = (function(_super) {
2898
+
2899
+ __extends(DimainPanel, _super);
2900
+
2901
+ function DimainPanel(core, profile) {
2902
+ var _this = this;
2903
+ this.editorPanel = new profile.editorClass(core);
2904
+ this.viewerPanel = new profile.viewerClass(core);
2905
+ DimainPanel.__super__.constructor.call(this, core, this.editorPanel, this.viewerPanel, profile.defaultVolume);
2906
+ this.element.addClass('mainPanel');
2907
+ this.editorPanel.change(function(value) {
2908
+ return _this.viewerPanel.update(value);
2909
+ });
2910
+ }
2911
+
2912
+ return DimainPanel;
2913
+
2914
+ })(VerticalPanel);
2915
+
2916
+ TrimainPanel = (function(_super) {
2917
+
2918
+ __extends(TrimainPanel, _super);
2919
+
2920
+ function TrimainPanel(core, profile) {
2921
+ var _this = this;
2922
+ this.editorPanel = new profile.editorClass(core);
2923
+ this.viewerPanel = new profile.viewerClass(core);
2924
+ this.helperPanel = new profile.helperClass(core);
2925
+ this.verticalPanel = new VerticalPanel(core, this.editorPanel, this.viewerPanel, profile.defaultVolume);
2926
+ TrimainPanel.__super__.constructor.call(this, core, this.verticalPanel, this.helperPanel, profile.defaultVolume2);
2927
+ this.element.addClass('mainPanel');
2928
+ this.editorPanel.change(function(value) {
2929
+ return _this.viewerPanel.update(value);
2930
+ });
2931
+ }
2932
+
2933
+ return TrimainPanel;
2934
+
2935
+ })(HorizontalPanel);
2936
+
2937
+ namespace('Jencil.ui.widgets.panels', function(exports) {
2938
+ exports.MonomainPanel = MonomainPanel;
2939
+ exports.DimainPanel = DimainPanel;
2940
+ return exports.TrimainPanel = TrimainPanel;
2941
+ });
2942
+
2943
+ Fullscreen = (function(_super) {
2944
+
2945
+ __extends(Fullscreen, _super);
2946
+
2947
+ function Fullscreen(core) {
2948
+ var _this = this;
2949
+ Fullscreen.__super__.constructor.call(this, core);
2950
+ this.element.addClass('fullscreen');
2951
+ this.element.css({
2952
+ 'position': 'fixed',
2953
+ 'top': '0',
2954
+ 'left': '0',
2955
+ 'width': '100%',
2956
+ 'height': '100%',
2957
+ 'z-index': 100
2958
+ });
2959
+ this.curtain = $('<div>').addClass('curtain');
2960
+ this.curtain.css({
2961
+ 'position': 'absolute',
2962
+ 'top': '0',
2963
+ 'left': '0',
2964
+ 'width': '100%',
2965
+ 'height': '100%',
2966
+ 'background': 'black',
2967
+ 'opacity': '0.6',
2968
+ 'cursor': 'pointer'
2969
+ });
2970
+ this.cell = $('<div>').css({
2971
+ 'position': 'absolute',
2972
+ 'top': '5%',
2973
+ 'left': '5%',
2974
+ 'width': '90%',
2975
+ 'height': '90%'
2976
+ });
2977
+ if ($.browser.msie && $.browser.version < 7) {
2978
+ this.element.css('position', 'absolute');
2979
+ $(window).scroll(function() {
2980
+ return _this.element.css('top', $(document).scrollTop());
2981
+ });
2982
+ }
2983
+ this.curtain.click(function() {
2984
+ return _this.off();
2985
+ });
2986
+ this.element.append(this.curtain);
2987
+ this.element.append(this.cell);
2988
+ this.element.hide();
2989
+ this.resize = function() {
2990
+ return _this.core.wrapper.adjust();
2991
+ };
2992
+ }
2993
+
2994
+ Fullscreen.prototype.on = function() {
2995
+ var ratio,
2996
+ _this = this;
2997
+ ratio = 9.0 / 10;
2998
+ this.cell.append(this.core.wrapper.element);
2999
+ this.core.wrapper.element.outerWidth(true, this.element.width() * ratio);
3000
+ this.core.wrapper.element.outerHeight(true, this.element.height() * ratio);
3001
+ this.core.wrapper.init();
3002
+ this.core.wrapper.adjust();
3003
+ this.core.wrapper.workspace.update(true);
3004
+ this.element.fadeIn('fast', function() {
3005
+ _this.core.wrapper.element.css('width', "100%");
3006
+ _this.core.wrapper.element.css('height', "100%");
3007
+ return _this.core.wrapper.adjust();
3008
+ });
3009
+ return $(window).on('resize', this.resize);
3010
+ };
3011
+
3012
+ Fullscreen.prototype.off = function() {
3013
+ this.core.element.after(this.core.wrapper.element);
3014
+ this.core.wrapper.element.css('width', "");
3015
+ this.core.wrapper.element.css('height', "");
3016
+ this.core.wrapper.init();
3017
+ this.core.wrapper.adjust();
3018
+ this.core.wrapper.workspace.update(true);
3019
+ this.element.fadeOut('fast');
3020
+ return $(window).unbind('resize', this.resize);
3021
+ };
3022
+
3023
+ Fullscreen.prototype.toggle = function(callbackOn, callbackOff) {
3024
+ if (this.element.is(':visible')) {
3025
+ this.off();
3026
+ return typeof callbackOff === "function" ? callbackOff() : void 0;
3027
+ } else {
3028
+ this.on();
3029
+ return typeof callbackOn === "function" ? callbackOn() : void 0;
3030
+ }
3031
+ };
3032
+
3033
+ return Fullscreen;
3034
+
3035
+ })(Panel);
3036
+
3037
+ autoIndentableHtml = (function() {
3038
+ var PATTERNS, post, pre, x;
3039
+ PATTERNS = (function() {
3040
+ var _i, _len, _ref, _results;
3041
+ _ref = ['p', 'li'];
3042
+ _results = [];
3043
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
3044
+ x = _ref[_i];
3045
+ _results.push([x, new RegExp("^[\s\t]*<" + x + ">"), new RegExp("</" + x + ">[\s\t]*$")]);
3046
+ }
3047
+ return _results;
3048
+ })();
3049
+ pre = function(e, line) {
3050
+ var lineCaret, pattern, _i, _len;
3051
+ console.log("@", this);
3052
+ if (e.shiftKey) {
3053
+ return;
3054
+ }
3055
+ for (_i = 0, _len = PATTERNS.length; _i < _len; _i++) {
3056
+ pattern = PATTERNS[_i];
3057
+ if (pattern[1].test(line) || pattern[2].test(line)) {
3058
+ lineCaret = this.selection._getLineCaret();
3059
+ this.selection.caret(lineCaret[1]);
3060
+ return;
3061
+ }
3062
+ }
3063
+ };
3064
+ post = function(e, line, indent, insert) {
3065
+ var pattern, _i, _len;
3066
+ if (e.shiftKey) {
3067
+ return;
3068
+ }
3069
+ for (_i = 0, _len = PATTERNS.length; _i < _len; _i++) {
3070
+ pattern = PATTERNS[_i];
3071
+ if (pattern[2].test(line)) {
3072
+ x = pattern[0];
3073
+ this.selection.insertAfter("<" + x + "></" + x + ">", false);
3074
+ this.selection.caretOffset(-(3 + x.length));
3075
+ return;
3076
+ }
3077
+ }
3078
+ };
3079
+ return function(textarea) {
3080
+ if (!(textarea.autoIndent != null)) {
3081
+ textarea = autoIndentable(textarea);
3082
+ }
3083
+ textarea.autoIndent.pre = function(e, line) {
3084
+ return pre.call(textarea, e, line);
3085
+ };
3086
+ textarea.autoIndent.post = function(e, line, indent, insert) {
3087
+ return post.call(textarea, e, line, indent, insert);
3088
+ };
3089
+ return textarea;
3090
+ };
3091
+ })();
3092
+
3093
+ headerMarkup = (function() {
3094
+ var PATTERN;
3095
+ PATTERN = new RegExp("^<h([1-6])>(.*)</h[1-6]>\n?$");
3096
+ return function(n) {
3097
+ var caret, replacement, text;
3098
+ caret = this.textarea.selection.caret();
3099
+ if (caret[0] === caret[1]) {
3100
+ this.textarea.selection.selectWholeCurrentLine();
3101
+ }
3102
+ text = this.selection();
3103
+ if (PATTERN.test(text)) {
3104
+ if (RegExp.$1 === n.toString()) {
3105
+ replacement = RegExp.$2;
3106
+ } else {
3107
+ replacement = "<h" + n + ">" + RegExp.$2 + "</h" + n + ">";
3108
+ }
3109
+ return this.selection(replacement);
3110
+ } else {
3111
+ return this.enclose("<h" + n + ">", "</h" + n + ">\n");
3112
+ }
3113
+ };
3114
+ })();
3115
+
3116
+ HtmlEditor = (function(_super) {
3117
+
3118
+ __extends(HtmlEditor, _super);
3119
+
3120
+ function HtmlEditor(core) {
3121
+ HtmlEditor.__super__.constructor.call(this, core);
3122
+ this.textarea = autoIndentableHtml(this.textarea);
3123
+ }
3124
+
3125
+ HtmlEditor.prototype.h1 = function() {
3126
+ return headerMarkup.call(this, 1);
3127
+ };
3128
+
3129
+ HtmlEditor.prototype.h2 = function() {
3130
+ return headerMarkup.call(this, 2);
3131
+ };
3132
+
3133
+ HtmlEditor.prototype.h3 = function() {
3134
+ return headerMarkup.call(this, 3);
3135
+ };
3136
+
3137
+ HtmlEditor.prototype.h4 = function() {
3138
+ return headerMarkup.call(this, 4);
3139
+ };
3140
+
3141
+ HtmlEditor.prototype.h5 = function() {
3142
+ return headerMarkup.call(this, 5);
3143
+ };
3144
+
3145
+ HtmlEditor.prototype.h6 = function() {
3146
+ return headerMarkup.call(this, 6);
3147
+ };
3148
+
3149
+ HtmlEditor.prototype.bold = function() {
3150
+ return this.enclose("<b>", "</b>");
3151
+ };
3152
+
3153
+ HtmlEditor.prototype.italic = function() {
3154
+ return this.enclose("<i>", "</i>");
3155
+ };
3156
+
3157
+ HtmlEditor.prototype.underline = function() {
3158
+ return this.enclose("<u>", "</u>");
3159
+ };
3160
+
3161
+ HtmlEditor.prototype.strike = function() {
3162
+ return this.enclose("<s>", "</s>");
3163
+ };
3164
+
3165
+ HtmlEditor.prototype.superscript = function() {
3166
+ return this.enclose("<sup>", "</sup>");
3167
+ };
3168
+
3169
+ HtmlEditor.prototype.subscript = function() {
3170
+ return this.enclose("<sub>", "</sub>");
3171
+ };
3172
+
3173
+ HtmlEditor.prototype.quote = function() {
3174
+ return this.enclose("<q>", "</q>");
3175
+ };
3176
+
3177
+ HtmlEditor.prototype.blockquote = function() {
3178
+ return this.enclose("\n<blockquote>", "</blockquote>\n");
3179
+ };
3180
+
3181
+ HtmlEditor.prototype.code = function() {
3182
+ return this.enclose("<code>", "</code>");
3183
+ };
3184
+
3185
+ HtmlEditor.prototype.pre = function() {
3186
+ return this.enclose("<pre>", "</pre>");
3187
+ };
3188
+
3189
+ HtmlEditor.prototype.anchorLink = function() {
3190
+ var href, text;
3191
+ text = this.selection();
3192
+ if (!text) {
3193
+ text = window.prompt("Please input a link text", "Here");
3194
+ }
3195
+ href = window.prompt("Please input a link url", "http://");
3196
+ if (!(href != null)) {
3197
+ return;
3198
+ }
3199
+ return this.selection("<a href='" + href + "'>" + text + "</a>");
3200
+ };
3201
+
3202
+ HtmlEditor.prototype.image = function() {
3203
+ var alt, src;
3204
+ src = window.prompt("Please input a image url", "http://");
3205
+ alt = window.prompt("(Optional) Please input a alt message", "Image");
3206
+ if (!(src != null)) {
3207
+ return;
3208
+ }
3209
+ return this.selection("<img src='" + src + "' alt='" + alt + "'>");
3210
+ };
3211
+
3212
+ HtmlEditor.prototype.unorderedList = function() {
3213
+ var text, x;
3214
+ text = this.selection();
3215
+ text = (function() {
3216
+ var _i, _len, _ref, _results;
3217
+ _ref = text.split("\n");
3218
+ _results = [];
3219
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
3220
+ x = _ref[_i];
3221
+ _results.push(" <li>" + x + "</li>");
3222
+ }
3223
+ return _results;
3224
+ })();
3225
+ text.unshift("<ul>");
3226
+ text.push("</ul>");
3227
+ return this.selection(text.join("\n"));
3228
+ };
3229
+
3230
+ HtmlEditor.prototype.orderedList = function() {
3231
+ var text, x;
3232
+ text = this.selection();
3233
+ text = (function() {
3234
+ var _i, _len, _ref, _results;
3235
+ _ref = text.split("\n");
3236
+ _results = [];
3237
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
3238
+ x = _ref[_i];
3239
+ _results.push(" <li>" + x + "</li>");
3240
+ }
3241
+ return _results;
3242
+ })();
3243
+ text.unshift("<ol>");
3244
+ text.push("</ol>");
3245
+ return this.selection(text.join("\n"));
3246
+ };
3247
+
3248
+ return HtmlEditor;
3249
+
3250
+ })(Jencil.ui.widgets.editors.TextEditor);
3251
+
3252
+ Jencil.utils.namespace('Jencil.ui.widgets.editors', function(exports) {
3253
+ return exports.HtmlEditor = HtmlEditor;
3254
+ });
3255
+
3256
+ HtmlViewer = Jencil.ui.widgets.viewers.TemplateViewer;
3257
+
3258
+ Jencil.utils.namespace('Jencil.ui.widgets.viewers', function(exports) {
3259
+ return exports.HtmlViewer = HtmlViewer;
3260
+ });
3261
+
3262
+ HtmlHelper = (function(_super) {
3263
+
3264
+ __extends(HtmlHelper, _super);
3265
+
3266
+ function HtmlHelper(core) {
3267
+ var HTML_HELPER_HTML;
3268
+ HtmlHelper.__super__.constructor.call(this, core);
3269
+ HTML_HELPER_HTML = "<p><span class=\"key\">Ctrl+Z</span>" + (Jencil.t("Undo")) + "<p>\n<p><span class=\"key\">Ctrl+Shift+Z</span>" + (Jencil.t("Redo")) + "<p>\n<p><span class=\"key\">Ctrl+B</span>" + (Jencil.t("Make selected text property as <b>Bold</b>")) + "<p>\n<p><span class=\"key\">Ctrl+I</span>" + (Jencil.t("Make selected text property as <i>Italic</i>")) + "<p>\n<p><span class=\"key\">Ctrl+U</span>" + (Jencil.t("Underline selected text like <u>Underline</u>")) + "<p>\n<p><span class=\"key\">Ctrl+F</span>" + (Jencil.t("Toggle fullscreen mode")) + "<p>\n<p><span class=\"key\">Ctrl+Q</span>" + (Jencil.t("Toggle quick view")) + "<p>\n<p><span class=\"key\">Ctrl+H</span>" + (Jencil.t("Toggle help")) + "<p>";
3270
+ this.element.html(HTML_HELPER_HTML);
3271
+ }
3272
+
3273
+ return HtmlHelper;
3274
+
3275
+ })(Jencil.ui.widgets.helpers.BaseHelper);
3276
+
3277
+ namespace('Jencil.ui.widgets.helpers', function(exports) {
3278
+ return exports.HtmlHelper = HtmlHelper;
3279
+ });
3280
+
3281
+ HtmlProfile = {
3282
+ mainPanelClass: Jencil.ui.widgets.panels.TrimainPanel,
3283
+ editorClass: HtmlEditor,
3284
+ viewerClass: HtmlViewer,
3285
+ helperClass: HtmlHelper,
3286
+ defaultVolume: 1,
3287
+ defaultVolume2: 0.7,
3288
+ toolbarButtons: ['Undo', 'Redo', 'Separator', ['h1', 'H1'], ['h2', 'H2'], ['h3', 'H3'], ['h4', 'H4'], ['h5', 'H5'], ['h6', 'H6'], 'Separator', ['bold', 'Bold', 'Ctrl+B'], ['italic', 'Italic', 'Ctrl+I'], ['underline', 'Underline', 'Ctrl+U'], ['strike', 'Strikeout'], ['superscript', 'Superscript'], ['subscript', 'Subscript'], 'Separator', ['anchorLink', 'Anchor link'], ['image', 'Image'], ['unorderedList', 'Unordered list'], ['orderedList', 'Ordered list'], ['quote', 'Quote'], ['blockquote', 'Blockquote'], ['code', 'Code'], ['pre', 'Pre'], 'Separator', 'Fullscreen'],
3289
+ statusbarButtons: ['Viewer', 'Helper']
3290
+ };
3291
+
3292
+ Jencil.utils.namespace('Jencil.profiles', function(exports) {
3293
+ return exports.HtmlProfile = HtmlProfile;
3294
+ });
3295
+
3296
+ }).call(this);