jqueryte 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7690ff33ddef4c3811e8b1d3704d5a8c3a934591
4
+ data.tar.gz: c0a8b1d611535cd71ff31cbaca39c59d781e3e5a
5
+ SHA512:
6
+ metadata.gz: 62ace69a7a568cec513260009e439231c78f80bfa1fd0d81003d5c2d193275ff7eedd6e95d3686a989d719acfbda58710082ab9188b4bfeb357b78f915a0a30d
7
+ data.tar.gz: 1a5e67206c9fc7fe25e089b5c8293213c4d85d53ce10cc5daa2013dc36b29065341a7cb5108466a96fea3853c62e1f495ca570104fa41471456b6c65d4d85e51
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # JQuery Text Editor for Ruby on Rails application
2
+
3
+ ## Introduction
4
+
5
+ This gem jqueryte is a rails engine which makes it easy to use [JQuery Text
6
+ Editor][1] in Ruby on Rails' application.
7
+
8
+ ## Installation
9
+
10
+ `gem install jqueryte`
11
+
12
+ or add it to Gemfile
13
+
14
+ `gem jqueryte`
15
+
16
+ ## Usage
17
+
18
+ ```ruby
19
+ # in rails application's stylesheets, eg. application.css
20
+ #= require jqueryte
21
+
22
+ # in rails application's javascript, eg. application.js
23
+ #= require jqueryte
24
+ ```
25
+ Then it is ready for use. For how to use this editor itself, please refer to
26
+ [JQuery Text Editor Documentation][2].
27
+
28
+ ## Version
29
+ This gem integrates JQuery Text Editor v1.4.0.
30
+
31
+ ## Licence MIT
32
+ Copyright (c) 2016 Pan Gaoyong
33
+
34
+ [1]: http://jqueryte.com 'JQuery Text Editor'
35
+ [2]: http://jqueryte.com/documentation 'JQuery Text Editor Documentation'
data/lib/jqueryte.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'jqueryte/version'
2
+ require 'jqueryte/engine' if defined?(::Rails)
@@ -0,0 +1,7 @@
1
+ module JQueryte
2
+ class Engine < ::Rails::Engine
3
+ initializer 'jqueryte.assets.precompile' do |app|
4
+ app.config.assets.precompile += %w(jquery-te.css jquery-te.js)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module JQueryte
2
+ VERSION = '0.0.1'
3
+ end
data/license ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Pan Gaoyong
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
Binary file
@@ -0,0 +1,1347 @@
1
+ /*!
2
+ *
3
+ * jQuery TE 1.4.0 , http://jqueryte.com/
4
+ * Copyright (C) 2013, Fatih Koca (fattih@fattih.com), (http://jqueryte.com/about)
5
+
6
+ * jQuery TE is provided under the MIT LICENSE.
7
+ *
8
+ */
9
+
10
+ (function($){
11
+ $.fn.jqte = function(options){
12
+
13
+ // default titles of buttons
14
+ var varsTitle = [
15
+ {title:"Text Format"},
16
+ {title:"Font Size"},
17
+ {title:"Color"},
18
+ {title:"Bold",hotkey:"B"},
19
+ {title:"Italic",hotkey:"I"},
20
+ {title:"Underline",hotkey:"U"},
21
+ {title:"Ordered List",hotkey:"."},
22
+ {title:"Unordered List",hotkey:","},
23
+ {title:"Subscript",hotkey:"down arrow"},
24
+ {title:"Superscript",hotkey:"up arrow"},
25
+ {title:"Outdent",hotkey:"left arrow"},
26
+ {title:"Indent",hotkey:"right arrow"},
27
+ {title:"Justify Left"},
28
+ {title:"Justify Center"},
29
+ {title:"Justify Right"},
30
+ {title:"Strike Through",hotkey:"K"},
31
+ {title:"Add Link",hotkey:"L"},
32
+ {title:"Remove Link"},
33
+ {title:"Cleaner Style",hotkey:"Delete"},
34
+ {title:"Horizontal Rule",hotkey:"H"},
35
+ {title:"Source"}
36
+ ];
37
+
38
+ // default text formats
39
+ var formats = [["p","Normal"],["h1","Header 1"],["h2","Header 2"],["h3","Header 3"],["h4","Header 4"],["h5","Header 5"],["h6","Header 6"],["pre","Preformatted"]];
40
+
41
+ // default font sizes
42
+ var fsizes = ["10","12","16","18","20","24","28"];
43
+
44
+ // default rgb values of colors
45
+ var colors = [
46
+ "0,0,0","68,68,68","102,102,102","153,153,153","204,204,204","238,238,238","243,243,243","255,255,255",
47
+ null,
48
+ "255,0,0","255,153,0","255,255,0","0,255,0","0,255,255","0,0,255","153,0,255","255,0,255",
49
+ null,
50
+ "244,204,204","252,229,205","255,242,204","217,234,211","208,224,227","207,226,243","217,210,233","234,209,220",
51
+ "234,153,153","249,203,156","255,229,153","182,215,168","162,196,201","159,197,232","180,167,214","213,166,189",
52
+ "224,102,102","246,178,107","255,217,102","147,196,125","118,165,175","111,168,220","142,124,195","194,123,160",
53
+ "204,0,0","230,145,56","241,194,50","106,168,79","69,129,142","61,133,198","103,78,167","166,77,121",
54
+ "153,0,0","180,95,6","191,144,0","56,118,29","19,79,92","11,83,148","53,28,117","116,27,71",
55
+ "102,0,0","120,63,4","127,96,0","39,78,19","12,52,61","7,55,99","32,18,77","76,17,48"
56
+ ];
57
+
58
+ // default link-type names
59
+ var linktypes = ["Web Address","E-mail Address","Picture URL"];
60
+
61
+ var vars = $.extend({
62
+ // options
63
+ 'status' : true,
64
+ 'css' : "jqte",
65
+ 'title' : true,
66
+ 'titletext' : varsTitle,
67
+ 'button' : "OK",
68
+ 'format' : true,
69
+ 'formats' : formats,
70
+ 'fsize' : true,
71
+ 'fsizes' : fsizes,
72
+ 'funit' : "px",
73
+ 'color' : true,
74
+ 'linktypes' : linktypes,
75
+ 'b' : true,
76
+ 'i' : true,
77
+ 'u' : true,
78
+ 'ol' : true,
79
+ 'ul' : true,
80
+ 'sub' : true,
81
+ 'sup' : true,
82
+ 'outdent' : true,
83
+ 'indent' : true,
84
+ 'left' : true,
85
+ 'center' : true,
86
+ 'right' : true,
87
+ 'strike' : true,
88
+ 'link' : true,
89
+ 'unlink' : true,
90
+ 'remove' : true,
91
+ 'rule' : true,
92
+ 'source' : true,
93
+ 'placeholder' : false,
94
+ 'br' : true,
95
+ 'p' : true,
96
+
97
+ // events
98
+ 'change' : "",
99
+ 'focus' : "",
100
+ 'blur' : ""
101
+ }, options);
102
+
103
+ // methods
104
+ $.fn.jqteVal = function(value){
105
+ $(this).closest("."+vars.css).find("."+vars.css+"_editor").html(value);
106
+ }
107
+
108
+ // browser information is received
109
+ var thisBrowser = navigator.userAgent.toLowerCase();
110
+
111
+ // if browser is ie and it version is 7 or even older, close title property
112
+ if(/msie [1-7]./.test(thisBrowser))
113
+ vars.title = false;
114
+
115
+ var buttons = [];
116
+
117
+ // insertion function for parameters to toolbar
118
+ function addParams(name,command,key,tag,emphasis)
119
+ {
120
+ var thisCssNo = buttons.length+1;
121
+ return buttons.push({name:name, cls:thisCssNo, command:command, key:key, tag:tag, emphasis:emphasis});
122
+ };
123
+
124
+ // add parameters for toolbar buttons
125
+ addParams('format','formats','','',false); // text format button --> no hotkey
126
+ addParams('fsize','fSize','','',false); // font size button --> no hotkey
127
+ addParams('color','colors','','',false); // text color button --> no hotkey
128
+ addParams('b','Bold','B',["b","strong"],true); // bold --> ctrl + b
129
+ addParams('i','Italic','I',["i","em"],true); // italic --> ctrl + i
130
+ addParams('u','Underline','U',["u"],true); // underline --> ctrl + u
131
+ addParams('ol','insertorderedlist','¾',["ol"],true); // ordered list --> ctrl + .(dot)
132
+ addParams('ul','insertunorderedlist','¼',["ul"],true); // unordered list --> ctrl + ,(comma)
133
+ addParams('sub','subscript','(',["sub"],true); // sub script --> ctrl + down arrow
134
+ addParams('sup','superscript','&',["sup"],true); // super script --> ctrl + up arrow
135
+ addParams('outdent','outdent','%',["blockquote"],false); // outdent --> ctrl + left arrow
136
+ addParams('indent','indent','\'',["blockquote"],true); // indent --> ctrl + right arrow
137
+ addParams('left','justifyLeft','','',false); // justify Left --> no hotkey
138
+ addParams('center','justifyCenter','','',false); // justify center --> no hotkey
139
+ addParams('right','justifyRight','','',false); // justify right --> no hotkey
140
+ addParams('strike','strikeThrough','K',["strike"],true); // strike through --> ctrl + K
141
+ addParams('link','linkcreator','L',["a"],true); // insertion link --> ctrl + L
142
+ addParams('unlink','unlink','',["a"],false); // remove link --> ctrl + N
143
+ addParams('remove','removeformat','.','',false); // remove all styles --> ctrl + delete
144
+ addParams('rule','inserthorizontalrule','H',["hr"],false); // insertion horizontal rule --> ctrl + H
145
+ addParams('source','displaysource','','',false); // feature of displaying source
146
+
147
+ return this.each(function(){
148
+ if(!$(this).data("jqte") || $(this).data("jqte")==null || $(this).data("jqte")=="undefined")
149
+ $(this).data("jqte",true);
150
+ else
151
+ $(this).data("jqte",false);
152
+
153
+ // is the status false of the editor
154
+ if(!vars.status || !$(this).data("jqte"))
155
+ {
156
+ // if wanting the false status later
157
+ if($(this).closest("."+vars.css).length>0)
158
+ {
159
+ var editorValue = $(this).closest("."+vars.css).find("."+vars.css+"_editor").html();
160
+
161
+ // add all attributes of element
162
+ var thisElementAttrs = "";
163
+
164
+ $($(this)[0].attributes).each(function()
165
+ {
166
+ if(this.nodeName!="style")
167
+ thisElementAttrs = thisElementAttrs+" "+this.nodeName+'="'+this.nodeValue+'"';
168
+ });
169
+
170
+ var thisElementTag = $(this).is("[data-origin]") && $(this).attr("data-origin")!="" ? $(this).attr("data-origin") : "textarea";
171
+
172
+ // the contents of this element
173
+ var createValue = '>'+editorValue;
174
+
175
+ // if this element is input or option
176
+ if(thisElementTag=="input" || thisElementTag=="option")
177
+ {
178
+ // encode special html characters
179
+ editorValue = editorValue.replace(/"/g,'&#34;').replace(/'/g,'&#39;').replace(/</g,'&lt;').replace(/>/g,'&gt;');
180
+
181
+ // the value of this element
182
+ createValue = 'value="'+editorValue+'">';
183
+ }
184
+
185
+ var thisClone = $(this).clone();
186
+
187
+ $(this).data("jqte",false).closest("."+vars.css).before(thisClone).remove();
188
+ thisClone.replaceWith('<'+ thisElementTag + thisElementAttrs + createValue + '</'+thisElementTag+'>');
189
+ }
190
+ return;
191
+ }
192
+
193
+ // element will converted to the jqte editor
194
+ var thisElement = $(this);
195
+
196
+ // tag name of the element
197
+ var thisElementTag = $(this).prop('tagName').toLowerCase();
198
+
199
+ // tag name of origin
200
+ $(this).attr("data-origin",thisElementTag);
201
+
202
+ // contents of the element
203
+ var thisElementVal = $(this).is("[value]") || thisElementTag == "textarea" ? $(this).val() : $(this).html();
204
+
205
+ // decode special html characters
206
+ thisElementVal = thisElementVal.replace(/&#34;/g,'"').replace(/&#39;/g,"'").replace(/&lt;/g,'<').replace(/&gt;/g,'>').replace(/&amp;/g,'&');
207
+
208
+ // start jqte editor to after the element
209
+ $(this).after('<div class="'+vars.css+'"></div>');
210
+
211
+ // jqte
212
+ var jQTE = $(this).next('.'+vars.css);
213
+
214
+ // insert toolbar in jqte editor
215
+ jQTE.html('<div class="'+vars.css+"_toolbar"+'" role="toolbar" unselectable></div><div class="'+vars.css+'_linkform" style="display:none" role="dialog"></div><div class="'+vars.css+"_editor"+'"></div>');
216
+
217
+ var toolbar = jQTE.find('.'+vars.css+"_toolbar"); // the toolbar variable
218
+ var linkform = jQTE.find('.'+vars.css+"_linkform"); // the link-form-area in the toolbar variable
219
+ var editor = jQTE.find('.'+vars.css+"_editor"); // the text-field of jqte editor
220
+ var emphasize = vars.css+"_tool_depressed"; // highlight style of the toolbar buttons
221
+
222
+ // add to some tools in link form area
223
+ linkform.append('<div class="'+vars.css+'_linktypeselect" unselectable></div><input class="'+vars.css+'_linkinput" type="text/css" value=""><div class="'+vars.css+'_linkbutton" unselectable>'+vars.button+'</div> <div style="height:1px;float:none;clear:both"></div>');
224
+
225
+ var linktypeselect = linkform.find("."+vars.css+"_linktypeselect"); // the tool of link-type-selector
226
+ var linkinput = linkform.find("."+vars.css+"_linkinput"); // the input of insertion link
227
+ var linkbutton = linkform.find("."+vars.css+"_linkbutton"); // the button of insertion link
228
+
229
+ // add to the link-type-selector sub tool parts
230
+ linktypeselect.append('<div class="'+vars.css+'_linktypeview" unselectable></div><div class="'+vars.css+'_linktypes" role="menu" unselectable></div>');
231
+
232
+ var linktypes = linktypeselect.find("."+vars.css+"_linktypes"); // the select box of link types
233
+ var linktypeview = linktypeselect.find("."+vars.css+"_linktypeview"); // the link type preview
234
+ var setdatalink = vars.css+"-setlink"; // the selected text add to mark as "link will be added"
235
+
236
+ // create to the source-area
237
+ editor.after('<div class="'+vars.css+'_source '+vars.css+'_hiddenField"></div>');
238
+
239
+ var sourceField = jQTE.find("."+vars.css+"_source"); // the source-area variable
240
+
241
+ // move the element to the source-area
242
+ thisElement.appendTo(sourceField);
243
+
244
+ // if the element isn't a textarea, convert this to textarea
245
+ if(thisElementTag!="textarea")
246
+ {
247
+ // add all attributes of element to new textarea (type and value except)
248
+ var thisElementAttrs = "";
249
+
250
+ $(thisElement[0].attributes).each(function(){
251
+ if(this.nodeName!="type" && this.nodeName!="value")
252
+ thisElementAttrs = thisElementAttrs+" "+this.nodeName+'="'+this.nodeValue+'"';
253
+ });
254
+
255
+ // convert the element to textarea
256
+ thisElement.replaceWith('<textarea '+thisElementAttrs+'>'+thisElementVal+'</textarea>');
257
+
258
+ // update to variable of thisElement
259
+ thisElement = sourceField.find("textarea");
260
+ }
261
+
262
+ // add feature editable to the text-field ve copy from the element's value to text-field
263
+ editor.attr("contenteditable","true").html(thisElementVal);
264
+
265
+ // insertion the toolbar button
266
+ for(var n = 0; n < buttons.length; n++)
267
+ {
268
+ // if setting of this button is activated (is it true?)
269
+ if(vars[buttons[n].name])
270
+ {
271
+ // if it have a title, add to this button
272
+ var buttonHotkey = buttons[n].key.length>0 ? vars.titletext[n].hotkey!=null && vars.titletext[n].hotkey!="undefined" && vars.titletext[n].hotkey!="" ? ' (Ctrl+'+vars.titletext[n].hotkey+')' : '' : '';
273
+ var buttonTitle = vars.titletext[n].title!=null && vars.titletext[n].title!="undefined" && vars.titletext[n].title!="" ? vars.titletext[n].title+buttonHotkey : '';
274
+
275
+ // add this button to the toolbar
276
+ toolbar.append('<div class="'+vars.css+'_tool '+vars.css+'_tool_'+buttons[n].cls+'" role="button" data-tool="'+n+'" unselectable><a class="'+vars.css+'_tool_icon" unselectable></a></div>');
277
+
278
+ // add the parameters to this button
279
+ toolbar.find('.'+vars.css+'_tool[data-tool='+n+']').data({tag : buttons[n].tag, command : buttons[n].command, emphasis : buttons[n].emphasis, title : buttonTitle});
280
+
281
+ // format-selector field
282
+ if(buttons[n].name=="format" && $.isArray(vars.formats))
283
+ {
284
+ // selected text format
285
+ var toolLabel = vars.formats[0][1].length>0 && vars.formats[0][1]!="undefined" ? vars.formats[0][1] : "";
286
+
287
+ toolbar.find("."+vars.css+'_tool_'+buttons[n].cls).find("."+vars.css+"_tool_icon").replaceWith('<a class="'+vars.css+'_tool_label" unselectable><span class="'+vars.css+'_tool_text" unselectable>'+toolLabel+'</span><span class="'+vars.css+'_tool_icon" unselectable></span></a>');
288
+
289
+ toolbar.find("."+vars.css+'_tool_'+buttons[n].cls)
290
+ .append('<div class="'+vars.css+'_formats" unselectable></div>');
291
+
292
+ // add font-sizes to font-size-selector
293
+ for(var f = 0; f < vars.formats.length; f++)
294
+ {
295
+ toolbar.find("."+vars.css+"_formats").append('<a '+vars.css+'-formatval="'+ vars.formats[f][0] +'" class="'+vars.css+'_format'+' '+vars.css+'_format_'+f+'" role="menuitem" unselectable>'+ vars.formats[f][1] +'</a>');
296
+ }
297
+
298
+ toolbar.find("."+vars.css+"_formats").data("status",false);
299
+ }
300
+
301
+ // font-size-selector field
302
+ else if(buttons[n].name=="fsize" && $.isArray(vars.fsizes))
303
+ {
304
+ toolbar.find("."+vars.css+'_tool_'+buttons[n].cls)
305
+ .append('<div class="'+vars.css+'_fontsizes" unselectable></div>');
306
+
307
+ // add font-sizes to font-size-selector
308
+ for(var f = 0; f < vars.fsizes.length; f++)
309
+ {
310
+ toolbar.find("."+vars.css+"_fontsizes").append('<a '+vars.css+'-styleval="'+ vars.fsizes[f] +'" class="'+vars.css+'_fontsize'+'" style="font-size:'+ vars.fsizes[f] + vars.funit+'" role="menuitem" unselectable>Abcdefgh...</a>');
311
+ }
312
+ }
313
+
314
+ // color-selector field
315
+ else if(buttons[n].name=="color" && $.isArray(colors))
316
+ {
317
+ toolbar.find("."+vars.css+'_tool_'+buttons[n].cls)
318
+ .append('<div class="'+vars.css+'_cpalette" unselectable></div>');
319
+
320
+ // create color palette to color-selector field
321
+ for(var c = 0; c < colors.length; c++)
322
+ {
323
+ if(colors[c]!=null)
324
+ toolbar.find("."+vars.css+"_cpalette").append('<a '+vars.css+'-styleval="'+ colors[c] +'" class="'+vars.css+'_color'+'" style="background-color: rgb('+ colors[c] +')" role="gridcell" unselectable></a>');
325
+ else
326
+ toolbar.find("."+vars.css+"_cpalette").append('<div class="'+vars.css+"_colorSeperator"+'"></div>');
327
+ }
328
+ }
329
+ }
330
+ }
331
+
332
+ // the default value of the link-type
333
+ linktypes.data("linktype","0");
334
+
335
+ // add link types to link-type-selector
336
+ for(var n = 0; n < 3; n++)
337
+ {
338
+ linktypes.append('<a '+vars.css+'-linktype="'+n+'" unselectable>'+vars.linktypes[n]+'</a>');
339
+
340
+ linktypeview.html('<div class="'+vars.css+'_linktypearrow" unselectable></div><div class="'+vars.css+'_linktypetext">'+linktypes.find('a:eq('+linktypes.data("linktype")+')').text()+'</div>');
341
+ }
342
+
343
+ // add the prefix of css according to browser
344
+ var prefixCss = "";
345
+
346
+ if(/msie/.test(thisBrowser)) // ie
347
+ prefixCss = '-ms-';
348
+ else if(/chrome/.test(thisBrowser) || /safari/.test(thisBrowser) || /yandex/.test(thisBrowser)) // webkit group (safari, chrome, yandex)
349
+ prefixCss = '-webkit-';
350
+ else if(/mozilla/.test(thisBrowser)) // firefox
351
+ prefixCss = '-moz-';
352
+ else if(/opera/.test(thisBrowser)) // opera
353
+ prefixCss = '-o-';
354
+ else if(/konqueror/.test(thisBrowser)) // konqueror
355
+ prefixCss = '-khtml-';
356
+ else
357
+ prefixCss = '';
358
+
359
+ // the feature of placeholder
360
+ if(vars.placeholder && vars.placeholder!="")
361
+ {
362
+ jQTE.prepend('<div class="'+vars.css+'_placeholder" unselectable><div class="'+vars.css+'_placeholder_text">'+vars.placeholder+'</div></div>');
363
+
364
+ var placeHolder = jQTE.find("."+vars.css+"_placeholder");
365
+
366
+ placeHolder.click(function(){
367
+ editor.focus();
368
+ });
369
+ }
370
+
371
+ // make unselectable to unselectable attribute ones
372
+ jQTE.find("[unselectable]")
373
+ .css(prefixCss+"user-select","none")
374
+ .addClass("unselectable")
375
+ .attr("unselectable","on")
376
+ .on("selectstart mousedown",false);
377
+
378
+ // each button of the toolbar
379
+ var toolbutton = toolbar.find("."+vars.css+"_tool");
380
+
381
+ // format menu
382
+ var formatbar = toolbar.find("."+vars.css+"_formats");
383
+
384
+ // font-size filed
385
+ var fsizebar = toolbar.find("."+vars.css+"_fontsizes");
386
+
387
+ // color palette
388
+ var cpalette = toolbar.find("."+vars.css+"_cpalette");
389
+
390
+ // get the selected text as plain format
391
+ function selectionGet()
392
+ {
393
+ // for webkit, mozilla, opera
394
+ if (window.getSelection)
395
+ return window.getSelection();
396
+ // for ie
397
+ else if (document.selection && document.selection.createRange && document.selection.type != "None")
398
+ return document.selection.createRange();
399
+ }
400
+
401
+ // the function of changing to the selected text with "execCommand" method
402
+ function selectionSet(addCommand,thirdParam)
403
+ {
404
+ var range,
405
+ sel = selectionGet();
406
+
407
+ // for webkit, mozilla, opera
408
+ if (window.getSelection)
409
+ {
410
+ if (sel.anchorNode && sel.getRangeAt)
411
+ range = sel.getRangeAt(0);
412
+
413
+ if(range)
414
+ {
415
+ sel.removeAllRanges();
416
+ sel.addRange(range);
417
+ }
418
+
419
+ if(!thisBrowser.match(/msie/))
420
+ document.execCommand('StyleWithCSS', false, false);
421
+
422
+ document.execCommand(addCommand, false, thirdParam);
423
+ }
424
+
425
+ // for ie
426
+ else if (document.selection && document.selection.createRange && document.selection.type != "None")
427
+ {
428
+ range = document.selection.createRange();
429
+ range.execCommand(addCommand, false, thirdParam);
430
+ }
431
+
432
+ // change styles to around tags
433
+ affectStyleAround(false,false);
434
+ }
435
+
436
+ // the function of changing to the selected text with tags and tags's attributes
437
+ function replaceSelection(tTag,tAttr,tVal) {
438
+
439
+ // first, prevent to conflict of different jqte editors
440
+ if(editor.not(":focus"))
441
+ editor.focus();
442
+
443
+ // for webkit, mozilla, opera
444
+ if (window.getSelection)
445
+ {
446
+ var selObj = selectionGet(), selRange, newElement, documentFragment;
447
+
448
+ if (selObj.anchorNode && selObj.getRangeAt)
449
+ {
450
+ selRange = selObj.getRangeAt(0);
451
+
452
+ // create to new element
453
+ newElement = document.createElement(tTag);
454
+
455
+ // add the attribute to the new element
456
+ $(newElement).attr(tAttr,tVal);
457
+
458
+ // extract to the selected text
459
+ documentFragment = selRange.extractContents();
460
+
461
+ // add the contents to the new element
462
+ newElement.appendChild(documentFragment);
463
+
464
+ selRange.insertNode(newElement);
465
+ selObj.removeAllRanges();
466
+
467
+ // if the attribute is "style", change styles to around tags
468
+ if(tAttr=="style")
469
+ affectStyleAround($(newElement),tVal);
470
+ // for other attributes
471
+ else
472
+ affectStyleAround($(newElement),false);
473
+ }
474
+ }
475
+ // for ie
476
+ else if (document.selection && document.selection.createRange && document.selection.type != "None")
477
+ {
478
+ var range = document.selection.createRange();
479
+ var selectedText = range.htmlText;
480
+
481
+ var newText = '<'+tTag+' '+tAttr+'="'+tVal+'">'+selectedText+'</'+tTag+'>';
482
+
483
+ document.selection.createRange().pasteHTML(newText);
484
+ }
485
+ }
486
+
487
+ // the function of getting to the parent tag
488
+ var getSelectedNode = function() {
489
+ var node,selection;
490
+ if(window.getSelection) {
491
+ selection = getSelection();
492
+ node = selection.anchorNode;
493
+ }
494
+ if(!node && document.selection && document.selection.createRange && document.selection.type != "None")
495
+ {
496
+ selection = document.selection;
497
+ var range = selection.getRangeAt ? selection.getRangeAt(0) : selection.createRange();
498
+ node = range.commonAncestorContainer ? range.commonAncestorContainer :
499
+ range.parentElement ? range.parentElement() : range.item(0);
500
+ }
501
+ if(node) {
502
+ return (node.nodeName == "#text" ? $(node.parentNode) : $(node));
503
+ }
504
+ else
505
+ return false;
506
+ };
507
+
508
+ // the function of replacement styles to the around tags (parent and child)
509
+ function affectStyleAround(element,style)
510
+ {
511
+ var selectedTag = getSelectedNode(); // the selected node
512
+
513
+ selectedTag = selectedTag ? selectedTag : element;
514
+
515
+ // (for replacement with execCommand) affect to child tags with parent tag's styles
516
+ if(selectedTag && style==false)
517
+ {
518
+ // apply to the selected node with parent tag's styles
519
+ if(selectedTag.parent().is("[style]"))
520
+ selectedTag.attr("style",selectedTag.parent().attr("style"));
521
+
522
+ // apply to child tags with parent tag's styles
523
+ if(selectedTag.is("[style]"))
524
+ selectedTag.find("*").attr("style",selectedTag.attr("style"));
525
+ }
526
+ // (for replacement with html changing method)
527
+ else if(element && style && element.is("[style]"))
528
+ {
529
+ var styleKey = style.split(";"); // split the styles
530
+
531
+ styleKey = styleKey[0].split(":") // get the key of first style feature
532
+
533
+ // apply to child tags with parent tag's styles
534
+ if(element.is("[style*="+styleKey[0]+"]"))
535
+ element.find("*").css(styleKey[0],styleKey[1]);
536
+
537
+ // select to the selected node again
538
+ selectText(element);
539
+ }
540
+ }
541
+
542
+ // the function of making selected to a element
543
+ function selectText(element)
544
+ {
545
+ if(element)
546
+ {
547
+ var element = element[0];
548
+
549
+ if (document.body.createTextRange)
550
+ {
551
+ var range = document.body.createTextRange();
552
+ range.moveToElementText(element);
553
+ range.select();
554
+ }
555
+ else if (window.getSelection)
556
+ {
557
+ var selection = window.getSelection();
558
+ var range = document.createRange();
559
+
560
+ if(element != "undefined" && element != null)
561
+ {
562
+ range.selectNodeContents(element);
563
+
564
+ selection.removeAllRanges();
565
+ selection.addRange(range);
566
+
567
+ if($(element).is(":empty"))
568
+ {
569
+ $(element).append("&nbsp;");
570
+ selectText($(element));
571
+ }
572
+ }
573
+ }
574
+ }
575
+ }
576
+
577
+ // the function of converting text to link
578
+ function selected2link()
579
+ {
580
+ if(!toolbar.data("sourceOpened"))
581
+ {
582
+ var selectedTag = getSelectedNode(); // the selected node
583
+ var thisHrefLink = "http://"; // default the input value of the link-form-field
584
+
585
+ // display the link-form-field
586
+ linkAreaSwitch(true);
587
+
588
+ if(selectedTag)
589
+ {
590
+
591
+ var thisTagName = selectedTag.prop('tagName').toLowerCase();
592
+
593
+ // if tag name of the selected node is "a" and the selected node have "href" attribute
594
+ if(thisTagName == "a" && selectedTag.is('[href]'))
595
+ {
596
+ thisHrefLink = selectedTag.attr('href');
597
+
598
+ selectedTag.attr(setdatalink,"");
599
+ }
600
+ // if it don't have "a" tag name
601
+ else
602
+ replaceSelection("a",setdatalink,"");
603
+
604
+ }
605
+ else
606
+ linkinput.val(thisHrefLink).focus();
607
+
608
+ // the method of displaying-hiding to link-types
609
+ linktypeselect.click(function(e)
610
+ {
611
+ if($(e.target).hasClass(vars.css+"_linktypetext") || $(e.target).hasClass(vars.css+"_linktypearrow"))
612
+ linktypeSwitch(true);
613
+ });
614
+
615
+ // the method of selecting to link-types
616
+ linktypes.find("a").click(function()
617
+ {
618
+ var thisLinkType = $(this).attr(vars.css+"-linktype");
619
+
620
+ linktypes.data("linktype",thisLinkType)
621
+
622
+ linktypeview.find("."+vars.css+"_linktypetext").html(linktypes.find('a:eq('+linktypes.data("linktype")+')').text());
623
+
624
+ linkInputSet(thisHrefLink);
625
+
626
+ linktypeSwitch();
627
+ });
628
+
629
+ linkInputSet(thisHrefLink);
630
+
631
+ // the method of link-input
632
+ linkinput
633
+ // auto focus
634
+ .focus()
635
+ // update to value
636
+ .val(thisHrefLink)
637
+ // the event of key to enter in link-input
638
+ .bind("keypress keyup",function(e)
639
+ {
640
+ if(e.keyCode==13)
641
+ {
642
+ linkRecord(jQTE.find("["+setdatalink+"]"));
643
+ return false;
644
+ }
645
+ });
646
+
647
+ // the event of click link-button
648
+ linkbutton.click(function()
649
+ {
650
+ linkRecord(jQTE.find("["+setdatalink+"]"));
651
+ });
652
+ }
653
+ else
654
+ // hide the link-form-field
655
+ linkAreaSwitch(false);
656
+ }
657
+
658
+ function linkRecord(thisSelection)
659
+ {
660
+ // focus to link-input
661
+ linkinput.focus();
662
+
663
+ // select to the selected node
664
+ selectText(thisSelection);
665
+
666
+ // remove pre-link attribute (mark as "link will be added") of the selected node
667
+ thisSelection.removeAttr(setdatalink);
668
+
669
+ // if not selected to link-type of picture
670
+ if(linktypes.data("linktype")!="2")
671
+ selectionSet("createlink",linkinput.val()); // insert link url of link-input to the selected node
672
+ // if selected to link-type of picture
673
+ else
674
+ {
675
+ selectionSet("insertImage",linkinput.val()); // insert image url of link-input to the selected node
676
+
677
+ // the method of all pictures in the editor
678
+ editor.find("img").each(function(){
679
+ var emptyPrevLinks = $(this).prev("a");
680
+ var emptyNextLinks = $(this).next("a");
681
+
682
+ // if "a" tags of the front and rear of the picture is empty, remove
683
+ if(emptyPrevLinks.length>0 && emptyPrevLinks.html()=="")
684
+ emptyPrevLinks.remove();
685
+ else if(emptyNextLinks.length>0 && emptyNextLinks.html()=="")
686
+ emptyNextLinks.remove();
687
+ });
688
+ }
689
+
690
+ // hide the link-form-field
691
+ linkAreaSwitch();
692
+
693
+ // export contents of the text to the sources
694
+ editor.trigger("change");
695
+ }
696
+
697
+ // the function of switching link-form-field
698
+ function linkAreaSwitch(status)
699
+ {
700
+ // remove all pre-link attribute (mark as "link will be added")
701
+ clearSetElement("["+setdatalink+"]:not([href])");
702
+ jQTE.find("["+setdatalink+"][href]").removeAttr(setdatalink);
703
+
704
+ if(status)
705
+ {
706
+ toolbar.data("linkOpened",true);
707
+ linkform.show();
708
+ }
709
+ else
710
+ {
711
+ toolbar.data("linkOpened",false);
712
+ linkform.hide();
713
+ }
714
+
715
+ linktypeSwitch();
716
+ }
717
+
718
+ // the function of switching link-type-selector
719
+ function linktypeSwitch(status)
720
+ {
721
+ if(status)
722
+ linktypes.show();
723
+ else
724
+ linktypes.hide();
725
+ }
726
+
727
+ // the function of updating the link-input according to the link-type
728
+ function linkInputSet(thisHrefLink)
729
+ {
730
+ var currentType = linktypes.data("linktype");
731
+
732
+ // if selected type of e-mail
733
+ if(currentType=="1" && (linkinput.val()=="http://" || linkinput.is("[value^=http://]") || !linkinput.is("[value^=mailto]")))
734
+ linkinput.val("mailto:");
735
+ else if(currentType!="1" && !linkinput.is("[value^=http://]"))
736
+ linkinput.val("http://");
737
+ else
738
+ linkinput.val(thisHrefLink);
739
+ }
740
+
741
+ // the function of adding style to selected text
742
+ function selected2style(styleCommand)
743
+ {
744
+ if(!toolbar.data("sourceOpened"))
745
+ {
746
+
747
+ // if selected to changing the font-size value
748
+ if(styleCommand=="fSize")
749
+ styleField = fsizebar;
750
+
751
+ // if selected to changing the text-color value
752
+ else if(styleCommand=="colors")
753
+ styleField = cpalette;
754
+
755
+ // display the style-field
756
+ styleFieldSwitch(styleField,true);
757
+
758
+ // the event of click to style button
759
+ styleField.find("a").unbind("click").click(function()
760
+ {
761
+ var styleValue = $(this).attr(vars.css + "-styleval"); // the property of style value to be added
762
+
763
+ // if selected to changing the font-size value
764
+ if(styleCommand=="fSize")
765
+ {
766
+ styleType = "font-size";
767
+ styleValue = styleValue + vars.funit; // combine the value with size unit
768
+ }
769
+ // if selected to changing the text-color value
770
+ else if(styleCommand=="colors")
771
+ {
772
+ styleType = "color";
773
+ styleValue = "rgb("+styleValue + ")"; // combine color value with rgb
774
+ }
775
+
776
+ var prevStyles = refuseStyle(styleType); // affect styles to child tags (and extract to the new style attributes)
777
+
778
+ // change to selected text
779
+ replaceSelection("span","style",styleType+":"+styleValue+";"+prevStyles);
780
+
781
+ // hide all style-fields
782
+ styleFieldSwitch("",false);
783
+
784
+ // remove title bubbles
785
+ $('.'+vars.css+'_title').remove();
786
+
787
+ // export contents of the text to the sources
788
+ editor.trigger("change");
789
+ });
790
+
791
+ }
792
+ else
793
+ // hide the style-field
794
+ styleFieldSwitch(styleField,false);
795
+
796
+ // hide the link-form-field
797
+ linkAreaSwitch(false);
798
+ }
799
+
800
+ // the function of switching the style-field
801
+ function styleFieldSwitch(styleField,status)
802
+ {
803
+ var mainData="", // the style data of the actual wanted
804
+ allData = [{"d":"fsizeOpened","f":fsizebar},{"d":"cpallOpened","f":cpalette}]; // all style datas
805
+
806
+ // if the style data of the actual wanted isn't empty
807
+ if(styleField!="")
808
+ {
809
+ // return to all datas and find the main data
810
+ for(var si=0; si < allData.length; si++)
811
+ {
812
+ if(styleField==allData[si]["f"])
813
+ mainData = allData[si];
814
+ }
815
+ }
816
+ // display the style-field
817
+ if(status)
818
+ {
819
+ toolbar.data(mainData["d"],true); // stil seçme alanının açıldığını belirten parametre yaz
820
+ mainData["f"].slideDown(100); // stil seçme alanını aç
821
+
822
+ // return to all datas and close the fields of external datas
823
+ for(var si=0; si < allData.length; si++)
824
+ {
825
+ if(mainData["d"]!=allData[si]["d"])
826
+ {
827
+ toolbar.data(allData[si]["d"],false);
828
+ allData[si]["f"].slideUp(100);
829
+ }
830
+ }
831
+ }
832
+ // hide all style-fields
833
+ else
834
+ {
835
+ // return to all datas and close all style fields
836
+ for(var si=0; si < allData.length; si++)
837
+ {
838
+ toolbar.data(allData[si]["d"],false);
839
+ allData[si]["f"].slideUp(100);
840
+ }
841
+ }
842
+ }
843
+
844
+ // the function of removing all pre-link attribute (mark as "link will be added")
845
+ function clearSetElement(elem)
846
+ {
847
+ jQTE.find(elem).each(function(){
848
+ $(this).before($(this).html()).remove();
849
+ });
850
+ }
851
+
852
+ // the function of refusing some styles
853
+ function refuseStyle(refStyle)
854
+ {
855
+ var selectedTag = getSelectedNode(); // the selected node
856
+
857
+ // if the selected node have attribute of "style" and it have unwanted style
858
+ if(selectedTag && selectedTag.is("[style]") && selectedTag.css(refStyle)!="")
859
+ {
860
+ var refValue = selectedTag.css(refStyle); // first get key of unwanted style
861
+
862
+ selectedTag.css(refStyle,""); // clear unwanted style
863
+
864
+ var cleanStyle = selectedTag.attr("style"); // cleaned style
865
+
866
+ selectedTag.css(refStyle,refValue); // add unwanted style to the selected node again
867
+
868
+ return cleanStyle; // print cleaned style
869
+ }
870
+ else
871
+ return "";
872
+ }
873
+
874
+ // the function of adding style to selected text
875
+ function selected2format()
876
+ {
877
+ formatFieldSwitch(true);
878
+
879
+ formatbar.find("a").click(function()
880
+ {
881
+ $("*",this).click(function(e)
882
+ {
883
+ e.preventDefault();
884
+ return false;
885
+ });
886
+
887
+ formatLabelView($(this).text());
888
+
889
+ var formatValue = $(this).attr(vars.css + "-formatval"); // the type of format value
890
+
891
+ // convert to selected format
892
+ selectionSet("formatBlock",'<'+formatValue+'>');
893
+
894
+ formatFieldSwitch(false);
895
+ });
896
+ }
897
+
898
+ // the function of switching the style-field
899
+ function formatFieldSwitch(status)
900
+ {
901
+ var thisStatus = status ? true : false;
902
+
903
+ thisStatus = status && formatbar.data("status") ? true : false;
904
+
905
+ if(thisStatus || !status)
906
+ formatbar.data("status",false).slideUp(200);
907
+ else
908
+ formatbar.data("status",true).slideDown(200);
909
+ }
910
+
911
+ // change format label
912
+ function formatLabelView(str)
913
+ {
914
+ var formatLabel = formatbar.closest("."+vars.css+"_tool").find("."+vars.css+"_tool_label").find("."+vars.css+"_tool_text");
915
+
916
+ if(str.length > 10)
917
+ str = str.substr(0,7) + "...";
918
+
919
+ // change format label of button
920
+ formatLabel.html(str);
921
+ }
922
+
923
+ // the function of insertion a specific form to texts
924
+ function extractToText(strings)
925
+ {
926
+ var $htmlContent, $htmlPattern, $htmlReplace;
927
+
928
+ // first remove to unnecessary gaps
929
+ $htmlContent = strings.replace(/\n/gim,'').replace(/\r/gim,'').replace(/\t/gim,'').replace(/&nbsp;/gim,' ');
930
+
931
+ $htmlPattern = [
932
+ /\<span(|\s+.*?)><span(|\s+.*?)>(.*?)<\/span><\/span>/gim, // trim nested spans
933
+ /<(\w*[^p])\s*[^\/>]*>\s*<\/\1>/gim, // remove empty or white-spaces tags (ignore paragraphs (<p>) and breaks (<br>))
934
+ /\<div(|\s+.*?)>(.*?)\<\/div>/gim, // convert div to p
935
+ /\<strong(|\s+.*?)>(.*?)\<\/strong>/gim, // convert strong to b
936
+ /\<em(|\s+.*?)>(.*?)\<\/em>/gim // convert em to i
937
+ ];
938
+
939
+ $htmlReplace = [
940
+ '<span$2>$3</span>',
941
+ '',
942
+ '<p$1>$2</p>',
943
+ '<b$1>$2</b>',
944
+ '<i$1>$2</i>'
945
+ ];
946
+
947
+ // repeat the cleaning process 5 times
948
+ for(c=0; c<5; c++)
949
+ {
950
+ // create loop as the number of pattern
951
+ for(var i = 0; i < $htmlPattern.length; i++)
952
+ {
953
+ $htmlContent = $htmlContent.replace($htmlPattern[i], $htmlReplace[i]);
954
+ }
955
+ }
956
+
957
+ // if paragraph is false (<p>), convert <p> to <br>
958
+ if(!vars.p)
959
+ $htmlContent = $htmlContent.replace(/\<p(|\s+.*?)>(.*?)\<\/p>/ig, '<br/>$2');
960
+
961
+ // if break is false (<br>), convert <br> to <p>
962
+ if(!vars.br)
963
+ {
964
+ $htmlPattern = [
965
+ /\<br>(.*?)/ig,
966
+ /\<br\/>(.*?)/ig
967
+ ];
968
+
969
+ $htmlReplace = [
970
+ '<p>$1</p>',
971
+ '<p>$1</p>'
972
+ ];
973
+
974
+ // create loop as the number of pattern (for breaks)
975
+ for (var i = 0; i < $htmlPattern.length; i++) {
976
+ $htmlContent = $htmlContent.replace($htmlPattern[i], $htmlReplace[i]);
977
+ }
978
+ }
979
+
980
+ // if paragraph and break is false (<p> && <br>), convert <p> to <div>
981
+ if(!vars.p && !vars.br)
982
+ $htmlContent = $htmlContent.replace(/\<p>(.*?)\<\/p>/ig, '<div>$1</div>');
983
+
984
+ return $htmlContent;
985
+ }
986
+
987
+ // the function of exporting contents of the text field to the source field (to be the standard in all browsers)
988
+ function postToSource()
989
+ {
990
+ // clear unnecessary tags when editor view empty
991
+ var sourceStrings = editor.text()=="" && editor.html().length<12 ? "" : editor.html();
992
+
993
+ thisElement.val(extractToText(sourceStrings));
994
+ }
995
+
996
+ // the function of exporting contents of the source field to the text field (to be the standard in all browsers)
997
+ function postToEditor()
998
+ {
999
+ editor.html(extractToText(thisElement.val()));
1000
+ }
1001
+
1002
+ // the function of getting parent (or super parent) tag name of the selected node
1003
+ function detectElement(tags){
1004
+
1005
+ var resultdetect=false, $node = getSelectedNode(), parentsTag;
1006
+
1007
+ if($node)
1008
+ {
1009
+ $.each(tags, function(i, val){
1010
+ parentsTag = $node.prop('tagName').toLowerCase();
1011
+
1012
+ if (parentsTag == val)
1013
+ resultdetect = true;
1014
+ else
1015
+ {
1016
+ $node.parents().each(function(){
1017
+ parentsTag = $(this).prop('tagName').toLowerCase();
1018
+ if (parentsTag == val)
1019
+ resultdetect = true;
1020
+ });
1021
+ }
1022
+ });
1023
+
1024
+ return resultdetect;
1025
+ }
1026
+ else
1027
+ return false;
1028
+ };
1029
+
1030
+ // the function of highlighting the toolbar buttons according to the cursor position in jqte editor
1031
+ function buttonEmphasize(e)
1032
+ {
1033
+ for(var n = 0; n < buttons.length; n++)
1034
+ {
1035
+ if(vars[buttons[n].name] && buttons[n].emphasis && buttons[n].tag!='')
1036
+ detectElement(buttons[n].tag) ? toolbar.find('.'+vars.css+'_tool_'+buttons[n].cls).addClass(emphasize) : $('.'+vars.css+'_tool_'+buttons[n].cls).removeClass(emphasize);
1037
+ }
1038
+ // showing text format
1039
+ if(vars.format && $.isArray(vars.formats))
1040
+ {
1041
+ var isFoundFormat = false;
1042
+
1043
+ for(var f = 0; f < vars.formats.length; f++)
1044
+ {
1045
+ var thisFormat = [];
1046
+ thisFormat[0] = vars.formats[f][0];
1047
+
1048
+ if(vars.formats[f][0].length>0 && detectElement(thisFormat))
1049
+ {
1050
+ formatLabelView(vars.formats[f][1]);
1051
+
1052
+ isFoundFormat = true;
1053
+ break;
1054
+ }
1055
+ }
1056
+
1057
+ if(!isFoundFormat)
1058
+ formatLabelView(vars.formats[0][1]);
1059
+ }
1060
+
1061
+ // hide all style-fields
1062
+ styleFieldSwitch("",false);
1063
+ formatFieldSwitch(false);
1064
+ }
1065
+
1066
+ // the event of click to the toolbar buttons
1067
+ toolbutton
1068
+ .unbind("click")
1069
+ .click(function(e){
1070
+ // if source button is clicked
1071
+ if($(this).data('command')=='displaysource' && !toolbar.data("sourceOpened"))
1072
+ {
1073
+ // hide all the toolbar buttons (except the source button)
1074
+ toolbar.find("."+vars.css+"_tool").addClass(vars.css+"_hiddenField");
1075
+ $(this).removeClass(vars.css+"_hiddenField");
1076
+
1077
+ // update to data of source displaying
1078
+ toolbar.data("sourceOpened",true);
1079
+
1080
+ // equalize height of the text field with height of the source field
1081
+ thisElement.css("height",editor.outerHeight());
1082
+
1083
+ sourceField.removeClass(vars.css+"_hiddenField");
1084
+ editor.addClass(vars.css+"_hiddenField");
1085
+ thisElement.focus();
1086
+
1087
+ // hide the link-form-field
1088
+ linkAreaSwitch(false);
1089
+
1090
+ // hide all style-fields
1091
+ styleFieldSwitch("",false);
1092
+
1093
+ // hide format field
1094
+ formatFieldSwitch();
1095
+
1096
+ // hide placeholder
1097
+ if(vars.placeholder && vars.placeholder!="")
1098
+ placeHolder.hide();
1099
+ }
1100
+ // if other buttons is clicked
1101
+ else
1102
+ {
1103
+ // if source field is closed
1104
+ if(!toolbar.data("sourceOpened"))
1105
+ {
1106
+ // if insert-link-button is clicked
1107
+ if($(this).data('command')=='linkcreator')
1108
+ {
1109
+ if(!toolbar.data("linkOpened"))
1110
+ selected2link();
1111
+ else
1112
+ {
1113
+ // hide the link-form-field
1114
+ linkAreaSwitch(false);
1115
+
1116
+ // hide format field
1117
+ formatFieldSwitch(false);
1118
+ }
1119
+ }
1120
+
1121
+ // if the format button is clicked
1122
+ else if($(this).data('command')=='formats')
1123
+ {
1124
+ if($(this).data('command')=='formats' && !$(e.target).hasClass(vars.css+"_format"))
1125
+ selected2format();
1126
+
1127
+ // hide all style-fields
1128
+ styleFieldSwitch("",false);
1129
+
1130
+ if(editor.not(":focus"))
1131
+ editor.focus();
1132
+ }
1133
+
1134
+ // if the style buttons are clicked
1135
+ else if($(this).data('command')=='fSize' || $(this).data('command')=='colors')
1136
+ {
1137
+ if(
1138
+ ($(this).data('command')=='fSize' && !$(e.target).hasClass(vars.css+"_fontsize")) || // the font-size button
1139
+ ($(this).data('command')=='colors' && !$(e.target).hasClass(vars.css+"_color")) // the color button
1140
+ )
1141
+ selected2style($(this).data('command'));
1142
+
1143
+ // hide format field
1144
+ formatFieldSwitch(false);
1145
+
1146
+ if(editor.not(":focus"))
1147
+ editor.focus();
1148
+ }
1149
+
1150
+ // if other buttons is clicked
1151
+ else
1152
+ {
1153
+ // first, prevent to conflict of different jqte editors
1154
+ if(editor.not(":focus"))
1155
+ editor.focus();
1156
+
1157
+ // apply command of clicked button to the selected text
1158
+ selectionSet($(this).data('command'),null);
1159
+
1160
+ // hide all menu-fields
1161
+ styleFieldSwitch("",false);
1162
+ formatFieldSwitch(false);
1163
+ linktypeSwitch();
1164
+
1165
+ // to highlight the toolbar buttons according to the cursor position in jqte editor
1166
+ $(this).data('emphasis')==true && !$(this).hasClass(emphasize) ? $(this).addClass(emphasize) : $(this).removeClass(emphasize);
1167
+
1168
+ sourceField.addClass(vars.css+"_hiddenField");
1169
+ editor.removeClass(vars.css+"_hiddenField");
1170
+ }
1171
+
1172
+ }
1173
+ // hide the source field and display the text field
1174
+ else
1175
+ {
1176
+ // update to data of source hiding
1177
+ toolbar.data("sourceOpened",false);
1178
+
1179
+ // display all the toolbar buttons
1180
+ toolbar.find("."+vars.css+"_tool").removeClass(vars.css+"_hiddenField");
1181
+
1182
+ sourceField.addClass(vars.css+"_hiddenField");
1183
+ editor.removeClass(vars.css+"_hiddenField");
1184
+ }
1185
+
1186
+ if(vars.placeholder && vars.placeholder!="")
1187
+ editor.html()!="" ? placeHolder.hide() : placeHolder.show();
1188
+ }
1189
+
1190
+ // export contents of the text to the sources
1191
+ editor.trigger("change");
1192
+ })
1193
+ // the event of showing to the title bubble when mouse over of the toolbar buttons
1194
+ .hover(function(e){
1195
+ if(vars.title && $(this).data("title")!="" && ( $(e.target).hasClass(vars.css+"_tool") || $(e.target).hasClass(vars.css+"_tool_icon") ))
1196
+ {
1197
+ $('.'+vars.css+'_title').remove();
1198
+
1199
+ // create the title bubble
1200
+ jQTE.append('<div class="'+vars.css+'_title"><div class="'+vars.css+'_titleArrow"><div class="'+vars.css+'_titleArrowIcon"></div></div><div class="'+vars.css+'_titleText">'+$(this).data("title")+'</div></div>');
1201
+
1202
+ var thisTitle = $('.'+vars.css+'_title:first');
1203
+ var thisArrow = thisTitle.find('.'+vars.css+'_titleArrowIcon');
1204
+ var thisPosition = $(this).position();
1205
+ var thisAlignX = thisPosition.left + $(this).outerWidth() - (thisTitle.outerWidth()/2) - ($(this).outerWidth()/2);
1206
+ var thisAlignY = (thisPosition.top + $(this).outerHeight() + 5);
1207
+
1208
+ // show the title bubble and set to its position
1209
+ thisTitle.delay(400).css({'top':thisAlignY, 'left':thisAlignX}).fadeIn(200);
1210
+ }
1211
+ },function(){
1212
+ $('.'+vars.css+'_title').remove();
1213
+ });
1214
+
1215
+ // prevent multiple calling postToSource()
1216
+ var editorChangeTimer = null;
1217
+
1218
+ // the methods of the text fields
1219
+ editor
1220
+
1221
+ // trigger change method of the text field when the text field modified
1222
+ .bind("keypress keyup keydown drop cut copy paste DOMCharacterDataModified DOMSubtreeModified",function()
1223
+ {
1224
+ // export contents of the text to the sources
1225
+ if(!toolbar.data("sourceOpened"))
1226
+ $(this).trigger("change");
1227
+
1228
+ // hide the link-type-field
1229
+ linktypeSwitch();
1230
+
1231
+ // if the change method is added run the change method
1232
+ if($.isFunction(vars.change))
1233
+ vars.change();
1234
+
1235
+ // the feature of placeholder
1236
+ if(vars.placeholder && vars.placeholder!="")
1237
+ $(this).text()!="" ? placeHolder.hide() : placeHolder.show();
1238
+ })
1239
+ .bind("change",function()
1240
+ {
1241
+ if(!toolbar.data("sourceOpened"))
1242
+ {
1243
+ clearTimeout(editorChangeTimer);
1244
+ editorChangeTimer = setTimeout(postToSource,10);
1245
+ }
1246
+ })
1247
+
1248
+ // run to keyboard shortcuts
1249
+ .keydown(function(e)
1250
+ {
1251
+ // if ctrl key is clicked
1252
+ if(e.ctrlKey)
1253
+ {
1254
+ // check all toolbar buttons
1255
+ for(var n = 0; n < buttons.length; n++)
1256
+ {
1257
+ // if this settings of this button is activated (is it true)
1258
+ // if the keyed button with ctrl is same of hotkey of this button
1259
+ if(vars[buttons[n].name] && e.keyCode == buttons[n].key.charCodeAt(0))
1260
+ {
1261
+ if(buttons[n].command!='' && buttons[n].command!='linkcreator')
1262
+ selectionSet(buttons[n].command,null);
1263
+
1264
+ else if(buttons[n].command=='linkcreator')
1265
+ selected2link();
1266
+
1267
+ return false;
1268
+ }
1269
+ }
1270
+ }
1271
+ })
1272
+
1273
+ // method of triggering to the highlight button
1274
+ .bind("mouseup keyup",buttonEmphasize)
1275
+
1276
+ // the event of focus to the text field
1277
+ .focus(function()
1278
+ {
1279
+ // if the focus method is added run the focus method
1280
+ if($.isFunction(vars.focus))
1281
+ vars.focus();
1282
+
1283
+ // add onfocus class
1284
+ jQTE.addClass(vars.css+"_focused");
1285
+
1286
+ // prevent focus problem on opera
1287
+ if(/opera/.test(thisBrowser))
1288
+ {
1289
+ var range = document.createRange();
1290
+ range.selectNodeContents(editor[0]);
1291
+ range.collapse(false);
1292
+ var selection = window.getSelection();
1293
+ selection.removeAllRanges();
1294
+ selection.addRange(range);
1295
+ }
1296
+ })
1297
+
1298
+ // the event of focus out from the text field
1299
+ .focusout(function()
1300
+ {
1301
+ // remove to highlights of all toolbar buttons
1302
+ toolbutton.removeClass(emphasize);
1303
+
1304
+ // hide all menu-fields
1305
+ styleFieldSwitch("",false);
1306
+ formatFieldSwitch(false);
1307
+ linktypeSwitch();
1308
+
1309
+ // if the blur method is added run the blur method
1310
+ if($.isFunction(vars.blur))
1311
+ vars.blur();
1312
+
1313
+ // remove onfocus class
1314
+ jQTE.removeClass(vars.css+"_focused");
1315
+
1316
+ // show default text format
1317
+ if($.isArray(vars.formats))
1318
+ formatLabelView(vars.formats[0][1]);
1319
+ });
1320
+
1321
+ // the event of key in the source field
1322
+ thisElement
1323
+ .bind("keydown keyup",function()
1324
+ {
1325
+ // export contents of the source to the text field
1326
+ setTimeout(postToEditor,0);
1327
+
1328
+ // auto extension for the source field
1329
+ $(this).height($(this)[0].scrollHeight);
1330
+
1331
+ // if the source field is empty, shorten to the source field
1332
+ if($(this).val()=="")
1333
+ $(this).height(0);
1334
+ })
1335
+ .focus(function()
1336
+ {
1337
+ // add onfocus class
1338
+ jQTE.addClass(vars.css+"_focused");
1339
+ })
1340
+ .focusout(function()
1341
+ {
1342
+ // remove onfocus class
1343
+ jQTE.removeClass(vars.css+"_focused");
1344
+ });
1345
+ });
1346
+ };
1347
+ })(jQuery);