mark_it_up 0.0.2
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.
- data/MIT-LICENSE +20 -0
- data/README.rdoc +278 -0
- data/Rakefile +18 -0
- data/VERSION +1 -0
- data/lib/generators/miu_controller_generator.rb +27 -0
- data/lib/generators/templates/app/controllers/mark_it_up_controller.rb +7 -0
- data/lib/generators/templates/app/views/mark_it_up/preview.html.erb +16 -0
- data/lib/mark_it_up/view_helpers.rb +51 -0
- data/lib/mark_it_up.rb +136 -0
- data/lib/public/mark_it_up/icons/bold.png +0 -0
- data/lib/public/mark_it_up/icons/book_arrow.png +0 -0
- data/lib/public/mark_it_up/icons/button.png +0 -0
- data/lib/public/mark_it_up/icons/clean.png +0 -0
- data/lib/public/mark_it_up/icons/code.png +0 -0
- data/lib/public/mark_it_up/icons/h1.png +0 -0
- data/lib/public/mark_it_up/icons/h2.png +0 -0
- data/lib/public/mark_it_up/icons/h3.png +0 -0
- data/lib/public/mark_it_up/icons/h4.png +0 -0
- data/lib/public/mark_it_up/icons/h5.png +0 -0
- data/lib/public/mark_it_up/icons/h6.png +0 -0
- data/lib/public/mark_it_up/icons/image.png +0 -0
- data/lib/public/mark_it_up/icons/italic.png +0 -0
- data/lib/public/mark_it_up/icons/link.png +0 -0
- data/lib/public/mark_it_up/icons/list-bullet.png +0 -0
- data/lib/public/mark_it_up/icons/list-item.png +0 -0
- data/lib/public/mark_it_up/icons/list-numeric.png +0 -0
- data/lib/public/mark_it_up/icons/paragraph.png +0 -0
- data/lib/public/mark_it_up/icons/picture.png +0 -0
- data/lib/public/mark_it_up/icons/preview.png +0 -0
- data/lib/public/mark_it_up/icons/stroke.png +0 -0
- data/lib/public/mark_it_up/jquery.markitup.js +559 -0
- data/lib/public/mark_it_up/jquery.markitup.pack.js +9 -0
- data/lib/public/mark_it_up/skins/markitup/images/bg-container.png +0 -0
- data/lib/public/mark_it_up/skins/markitup/images/bg-editor-bbcode.png +0 -0
- data/lib/public/mark_it_up/skins/markitup/images/bg-editor-dotclear.png +0 -0
- data/lib/public/mark_it_up/skins/markitup/images/bg-editor-html.png +0 -0
- data/lib/public/mark_it_up/skins/markitup/images/bg-editor-json.png +0 -0
- data/lib/public/mark_it_up/skins/markitup/images/bg-editor-markdown.png +0 -0
- data/lib/public/mark_it_up/skins/markitup/images/bg-editor-textile.png +0 -0
- data/lib/public/mark_it_up/skins/markitup/images/bg-editor-wiki.png +0 -0
- data/lib/public/mark_it_up/skins/markitup/images/bg-editor-xml.png +0 -0
- data/lib/public/mark_it_up/skins/markitup/images/bg-editor.png +0 -0
- data/lib/public/mark_it_up/skins/markitup/images/handle.png +0 -0
- data/lib/public/mark_it_up/skins/markitup/images/menu.png +0 -0
- data/lib/public/mark_it_up/skins/markitup/images/submenu.png +0 -0
- data/lib/public/mark_it_up/skins/markitup/style.css +148 -0
- data/lib/public/mark_it_up/skins/simple/images/handle.png +0 -0
- data/lib/public/mark_it_up/skins/simple/images/menu.png +0 -0
- data/lib/public/mark_it_up/skins/simple/images/submenu.png +0 -0
- data/lib/public/mark_it_up/skins/simple/style.css +118 -0
- data/mark_it_up.gemspec +87 -0
- metadata +117 -0
@@ -0,0 +1,559 @@
|
|
1
|
+
// ----------------------------------------------------------------------------
|
2
|
+
// markItUp! Universal MarkUp Engine, JQuery plugin
|
3
|
+
// v 1.1.7
|
4
|
+
// Dual licensed under the MIT and GPL licenses.
|
5
|
+
// ----------------------------------------------------------------------------
|
6
|
+
// Copyright (C) 2007-2010 Jay Salvat
|
7
|
+
// http://markitup.jaysalvat.com/
|
8
|
+
// ----------------------------------------------------------------------------
|
9
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
10
|
+
// of this software and associated documentation files (the "Software"), to deal
|
11
|
+
// in the Software without restriction, including without limitation the rights
|
12
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
13
|
+
// copies of the Software, and to permit persons to whom the Software is
|
14
|
+
// furnished to do so, subject to the following conditions:
|
15
|
+
//
|
16
|
+
// The above copyright notice and this permission notice shall be included in
|
17
|
+
// all copies or substantial portions of the Software.
|
18
|
+
//
|
19
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
20
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
21
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
22
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
23
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
24
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
25
|
+
// THE SOFTWARE.
|
26
|
+
// ----------------------------------------------------------------------------
|
27
|
+
(function($) {
|
28
|
+
$.fn.markItUp = function(settings, extraSettings) {
|
29
|
+
var options, ctrlKey, shiftKey, altKey;
|
30
|
+
ctrlKey = shiftKey = altKey = false;
|
31
|
+
|
32
|
+
options = { id: '',
|
33
|
+
nameSpace: '',
|
34
|
+
root: '',
|
35
|
+
previewInWindow: '', // 'width=800, height=600, resizable=yes, scrollbars=yes'
|
36
|
+
previewAutoRefresh: true,
|
37
|
+
previewPosition: 'after',
|
38
|
+
previewTemplatePath: '~/templates/preview.html',
|
39
|
+
previewParserPath: '',
|
40
|
+
previewParserVar: 'data',
|
41
|
+
resizeHandle: true,
|
42
|
+
beforeInsert: '',
|
43
|
+
afterInsert: '',
|
44
|
+
onEnter: {},
|
45
|
+
onShiftEnter: {},
|
46
|
+
onCtrlEnter: {},
|
47
|
+
onTab: {},
|
48
|
+
markupSet: [ { /* set */ } ]
|
49
|
+
};
|
50
|
+
$.extend(options, settings, extraSettings);
|
51
|
+
|
52
|
+
// compute markItUp! path
|
53
|
+
if (!options.root) {
|
54
|
+
$('script').each(function(a, tag) {
|
55
|
+
miuScript = $(tag).get(0).src.match(/(.*)jquery\.markitup(\.pack)?\.js$/);
|
56
|
+
if (miuScript !== null) {
|
57
|
+
options.root = miuScript[1];
|
58
|
+
}
|
59
|
+
});
|
60
|
+
}
|
61
|
+
|
62
|
+
return this.each(function() {
|
63
|
+
var $$, textarea, levels, scrollPosition, caretPosition, caretOffset,
|
64
|
+
clicked, hash, header, footer, previewWindow, template, iFrame, abort;
|
65
|
+
$$ = $(this);
|
66
|
+
textarea = this;
|
67
|
+
levels = [];
|
68
|
+
abort = false;
|
69
|
+
scrollPosition = caretPosition = 0;
|
70
|
+
caretOffset = -1;
|
71
|
+
|
72
|
+
options.previewParserPath = localize(options.previewParserPath);
|
73
|
+
options.previewTemplatePath = localize(options.previewTemplatePath);
|
74
|
+
|
75
|
+
// apply the computed path to ~/
|
76
|
+
function localize(data, inText) {
|
77
|
+
if (inText) {
|
78
|
+
return data.replace(/("|')~\//g, "$1"+options.root);
|
79
|
+
}
|
80
|
+
return data.replace(/^~\//, options.root);
|
81
|
+
}
|
82
|
+
|
83
|
+
// init and build editor
|
84
|
+
function init() {
|
85
|
+
id = ''; nameSpace = '';
|
86
|
+
if (options.id) {
|
87
|
+
id = 'id="'+options.id+'"';
|
88
|
+
} else if ($$.attr("id")) {
|
89
|
+
id = 'id="markItUp'+($$.attr("id").substr(0, 1).toUpperCase())+($$.attr("id").substr(1))+'"';
|
90
|
+
|
91
|
+
}
|
92
|
+
if (options.nameSpace) {
|
93
|
+
nameSpace = 'class="'+options.nameSpace+'"';
|
94
|
+
}
|
95
|
+
$$.wrap('<div '+nameSpace+'></div>');
|
96
|
+
$$.wrap('<div '+id+' class="markItUp"></div>');
|
97
|
+
$$.wrap('<div class="markItUpContainer"></div>');
|
98
|
+
$$.addClass("markItUpEditor");
|
99
|
+
|
100
|
+
// add the header before the textarea
|
101
|
+
header = $('<div class="markItUpHeader"></div>').insertBefore($$);
|
102
|
+
$(dropMenus(options.markupSet)).appendTo(header);
|
103
|
+
|
104
|
+
// add the footer after the textarea
|
105
|
+
footer = $('<div class="markItUpFooter"></div>').insertAfter($$);
|
106
|
+
|
107
|
+
// add the resize handle after textarea
|
108
|
+
if (options.resizeHandle === true && $.browser.safari !== true) {
|
109
|
+
resizeHandle = $('<div class="markItUpResizeHandle"></div>')
|
110
|
+
.insertAfter($$)
|
111
|
+
.bind("mousedown", function(e) {
|
112
|
+
var h = $$.height(), y = e.clientY, mouseMove, mouseUp;
|
113
|
+
mouseMove = function(e) {
|
114
|
+
$$.css("height", Math.max(20, e.clientY+h-y)+"px");
|
115
|
+
return false;
|
116
|
+
};
|
117
|
+
mouseUp = function(e) {
|
118
|
+
$("html").unbind("mousemove", mouseMove).unbind("mouseup", mouseUp);
|
119
|
+
return false;
|
120
|
+
};
|
121
|
+
$("html").bind("mousemove", mouseMove).bind("mouseup", mouseUp);
|
122
|
+
});
|
123
|
+
footer.append(resizeHandle);
|
124
|
+
}
|
125
|
+
|
126
|
+
// listen key events
|
127
|
+
$$.keydown(keyPressed).keyup(keyPressed);
|
128
|
+
|
129
|
+
// bind an event to catch external calls
|
130
|
+
$$.bind("insertion", function(e, settings) {
|
131
|
+
if (settings.target !== false) {
|
132
|
+
get();
|
133
|
+
}
|
134
|
+
if (textarea === $.markItUp.focused) {
|
135
|
+
markup(settings);
|
136
|
+
}
|
137
|
+
});
|
138
|
+
|
139
|
+
// remember the last focus
|
140
|
+
$$.focus(function() {
|
141
|
+
$.markItUp.focused = this;
|
142
|
+
});
|
143
|
+
}
|
144
|
+
|
145
|
+
// recursively build header with dropMenus from markupset
|
146
|
+
function dropMenus(markupSet) {
|
147
|
+
var ul = $('<ul></ul>'), i = 0;
|
148
|
+
$('li:hover > ul', ul).css('display', 'block');
|
149
|
+
$.each(markupSet, function() {
|
150
|
+
var button = this, t = '', title, li, j;
|
151
|
+
title = (button.key) ? (button.name||'')+' [Ctrl+'+button.key+']' : (button.name||'');
|
152
|
+
key = (button.key) ? 'accesskey="'+button.key+'"' : '';
|
153
|
+
if (button.separator) {
|
154
|
+
li = $('<li class="markItUpSeparator">'+(button.separator||'')+'</li>').appendTo(ul);
|
155
|
+
} else {
|
156
|
+
i++;
|
157
|
+
for (j = levels.length -1; j >= 0; j--) {
|
158
|
+
t += levels[j]+"-";
|
159
|
+
}
|
160
|
+
li = $('<li class="markItUpButton markItUpButton'+t+(i)+' '+(button.className||'')+'"><a href="" '+key+' title="'+title+'">'+(button.name||'')+'</a></li>')
|
161
|
+
.bind("contextmenu", function() { // prevent contextmenu on mac and allow ctrl+click
|
162
|
+
return false;
|
163
|
+
}).click(function() {
|
164
|
+
return false;
|
165
|
+
}).mousedown(function() {
|
166
|
+
if (button.call) {
|
167
|
+
eval(button.call)();
|
168
|
+
}
|
169
|
+
setTimeout(function() { markup(button) },1);
|
170
|
+
return false;
|
171
|
+
}).hover(function() {
|
172
|
+
$('> ul', this).show();
|
173
|
+
$(document).one('click', function() { // close dropmenu if click outside
|
174
|
+
$('ul ul', header).hide();
|
175
|
+
}
|
176
|
+
);
|
177
|
+
}, function() {
|
178
|
+
$('> ul', this).hide();
|
179
|
+
}
|
180
|
+
).appendTo(ul);
|
181
|
+
if (button.dropMenu) {
|
182
|
+
levels.push(i);
|
183
|
+
$(li).addClass('markItUpDropMenu').append(dropMenus(button.dropMenu));
|
184
|
+
}
|
185
|
+
}
|
186
|
+
});
|
187
|
+
levels.pop();
|
188
|
+
return ul;
|
189
|
+
}
|
190
|
+
|
191
|
+
// markItUp! markups
|
192
|
+
function magicMarkups(string) {
|
193
|
+
if (string) {
|
194
|
+
string = string.toString();
|
195
|
+
string = string.replace(/\(\!\(([\s\S]*?)\)\!\)/g,
|
196
|
+
function(x, a) {
|
197
|
+
var b = a.split('|!|');
|
198
|
+
if (altKey === true) {
|
199
|
+
return (b[1] !== undefined) ? b[1] : b[0];
|
200
|
+
} else {
|
201
|
+
return (b[1] === undefined) ? "" : b[0];
|
202
|
+
}
|
203
|
+
}
|
204
|
+
);
|
205
|
+
// [![prompt]!], [![prompt:!:value]!]
|
206
|
+
string = string.replace(/\[\!\[([\s\S]*?)\]\!\]/g,
|
207
|
+
function(x, a) {
|
208
|
+
var b = a.split(':!:');
|
209
|
+
if (abort === true) {
|
210
|
+
return false;
|
211
|
+
}
|
212
|
+
value = prompt(b[0], (b[1]) ? b[1] : '');
|
213
|
+
if (value === null) {
|
214
|
+
abort = true;
|
215
|
+
}
|
216
|
+
return value;
|
217
|
+
}
|
218
|
+
);
|
219
|
+
return string;
|
220
|
+
}
|
221
|
+
return "";
|
222
|
+
}
|
223
|
+
|
224
|
+
// prepare action
|
225
|
+
function prepare(action) {
|
226
|
+
if ($.isFunction(action)) {
|
227
|
+
action = action(hash);
|
228
|
+
}
|
229
|
+
return magicMarkups(action);
|
230
|
+
}
|
231
|
+
|
232
|
+
// build block to insert
|
233
|
+
function build(string) {
|
234
|
+
openWith = prepare(clicked.openWith);
|
235
|
+
placeHolder = prepare(clicked.placeHolder);
|
236
|
+
replaceWith = prepare(clicked.replaceWith);
|
237
|
+
closeWith = prepare(clicked.closeWith);
|
238
|
+
if (replaceWith !== "") {
|
239
|
+
block = openWith + replaceWith + closeWith;
|
240
|
+
} else if (selection === '' && placeHolder !== '') {
|
241
|
+
block = openWith + placeHolder + closeWith;
|
242
|
+
} else {
|
243
|
+
block = openWith + (string||selection) + closeWith;
|
244
|
+
}
|
245
|
+
return { block:block,
|
246
|
+
openWith:openWith,
|
247
|
+
replaceWith:replaceWith,
|
248
|
+
placeHolder:placeHolder,
|
249
|
+
closeWith:closeWith
|
250
|
+
};
|
251
|
+
}
|
252
|
+
|
253
|
+
// define markup to insert
|
254
|
+
function markup(button) {
|
255
|
+
var len, j, n, i;
|
256
|
+
hash = clicked = button;
|
257
|
+
get();
|
258
|
+
|
259
|
+
$.extend(hash, { line:"",
|
260
|
+
root:options.root,
|
261
|
+
textarea:textarea,
|
262
|
+
selection:(selection||''),
|
263
|
+
caretPosition:caretPosition,
|
264
|
+
ctrlKey:ctrlKey,
|
265
|
+
shiftKey:shiftKey,
|
266
|
+
altKey:altKey
|
267
|
+
}
|
268
|
+
);
|
269
|
+
// callbacks before insertion
|
270
|
+
prepare(options.beforeInsert);
|
271
|
+
prepare(clicked.beforeInsert);
|
272
|
+
if (ctrlKey === true && shiftKey === true) {
|
273
|
+
prepare(clicked.beforeMultiInsert);
|
274
|
+
}
|
275
|
+
$.extend(hash, { line:1 });
|
276
|
+
|
277
|
+
if (ctrlKey === true && shiftKey === true) {
|
278
|
+
lines = selection.split(/\r?\n/);
|
279
|
+
for (j = 0, n = lines.length, i = 0; i < n; i++) {
|
280
|
+
if ($.trim(lines[i]) !== '') {
|
281
|
+
$.extend(hash, { line:++j, selection:lines[i] } );
|
282
|
+
lines[i] = build(lines[i]).block;
|
283
|
+
} else {
|
284
|
+
lines[i] = "";
|
285
|
+
}
|
286
|
+
}
|
287
|
+
string = { block:lines.join('\n')};
|
288
|
+
start = caretPosition;
|
289
|
+
len = string.block.length + (($.browser.opera) ? n : 0);
|
290
|
+
} else if (ctrlKey === true) {
|
291
|
+
string = build(selection);
|
292
|
+
start = caretPosition + string.openWith.length;
|
293
|
+
len = string.block.length - string.openWith.length - string.closeWith.length;
|
294
|
+
len -= fixIeBug(string.block);
|
295
|
+
} else if (shiftKey === true) {
|
296
|
+
string = build(selection);
|
297
|
+
start = caretPosition;
|
298
|
+
len = string.block.length;
|
299
|
+
len -= fixIeBug(string.block);
|
300
|
+
} else {
|
301
|
+
string = build(selection);
|
302
|
+
start = caretPosition + string.block.length ;
|
303
|
+
len = 0;
|
304
|
+
start -= fixIeBug(string.block);
|
305
|
+
}
|
306
|
+
if ((selection === '' && string.replaceWith === '')) {
|
307
|
+
caretOffset += fixOperaBug(string.block);
|
308
|
+
|
309
|
+
start = caretPosition + string.openWith.length;
|
310
|
+
len = string.block.length - string.openWith.length - string.closeWith.length;
|
311
|
+
|
312
|
+
caretOffset = $$.val().substring(caretPosition, $$.val().length).length;
|
313
|
+
caretOffset -= fixOperaBug($$.val().substring(0, caretPosition));
|
314
|
+
}
|
315
|
+
$.extend(hash, { caretPosition:caretPosition, scrollPosition:scrollPosition } );
|
316
|
+
|
317
|
+
if (string.block !== selection && abort === false) {
|
318
|
+
insert(string.block);
|
319
|
+
set(start, len);
|
320
|
+
} else {
|
321
|
+
caretOffset = -1;
|
322
|
+
}
|
323
|
+
get();
|
324
|
+
|
325
|
+
$.extend(hash, { line:'', selection:selection });
|
326
|
+
|
327
|
+
// callbacks after insertion
|
328
|
+
if (ctrlKey === true && shiftKey === true) {
|
329
|
+
prepare(clicked.afterMultiInsert);
|
330
|
+
}
|
331
|
+
prepare(clicked.afterInsert);
|
332
|
+
prepare(options.afterInsert);
|
333
|
+
|
334
|
+
// refresh preview if opened
|
335
|
+
if (previewWindow && options.previewAutoRefresh) {
|
336
|
+
refreshPreview();
|
337
|
+
}
|
338
|
+
|
339
|
+
// reinit keyevent
|
340
|
+
shiftKey = altKey = ctrlKey = abort = false;
|
341
|
+
}
|
342
|
+
|
343
|
+
// Substract linefeed in Opera
|
344
|
+
function fixOperaBug(string) {
|
345
|
+
if ($.browser.opera) {
|
346
|
+
return string.length - string.replace(/\n*/g, '').length;
|
347
|
+
}
|
348
|
+
return 0;
|
349
|
+
}
|
350
|
+
// Substract linefeed in IE
|
351
|
+
function fixIeBug(string) {
|
352
|
+
if ($.browser.msie) {
|
353
|
+
return string.length - string.replace(/\r*/g, '').length;
|
354
|
+
}
|
355
|
+
return 0;
|
356
|
+
}
|
357
|
+
|
358
|
+
// add markup
|
359
|
+
function insert(block) {
|
360
|
+
if (document.selection) {
|
361
|
+
var newSelection = document.selection.createRange();
|
362
|
+
newSelection.text = block;
|
363
|
+
} else {
|
364
|
+
$$.val($$.val().substring(0, caretPosition) + block + $$.val().substring(caretPosition + selection.length, $$.val().length));
|
365
|
+
}
|
366
|
+
}
|
367
|
+
|
368
|
+
// set a selection
|
369
|
+
function set(start, len) {
|
370
|
+
if (textarea.createTextRange){
|
371
|
+
// quick fix to make it work on Opera 9.5
|
372
|
+
if ($.browser.opera && $.browser.version >= 9.5 && len == 0) {
|
373
|
+
return false;
|
374
|
+
}
|
375
|
+
range = textarea.createTextRange();
|
376
|
+
range.collapse(true);
|
377
|
+
range.moveStart('character', start);
|
378
|
+
range.moveEnd('character', len);
|
379
|
+
range.select();
|
380
|
+
} else if (textarea.setSelectionRange ){
|
381
|
+
textarea.setSelectionRange(start, start + len);
|
382
|
+
}
|
383
|
+
textarea.scrollTop = scrollPosition;
|
384
|
+
textarea.focus();
|
385
|
+
}
|
386
|
+
|
387
|
+
// get the selection
|
388
|
+
function get() {
|
389
|
+
textarea.focus();
|
390
|
+
|
391
|
+
scrollPosition = textarea.scrollTop;
|
392
|
+
if (document.selection) {
|
393
|
+
selection = document.selection.createRange().text;
|
394
|
+
if ($.browser.msie) { // ie
|
395
|
+
var range = document.selection.createRange(), rangeCopy = range.duplicate();
|
396
|
+
rangeCopy.moveToElementText(textarea);
|
397
|
+
caretPosition = -1;
|
398
|
+
while(rangeCopy.inRange(range)) { // fix most of the ie bugs with linefeeds...
|
399
|
+
rangeCopy.moveStart('character');
|
400
|
+
caretPosition ++;
|
401
|
+
}
|
402
|
+
} else { // opera
|
403
|
+
caretPosition = textarea.selectionStart;
|
404
|
+
}
|
405
|
+
} else { // gecko & webkit
|
406
|
+
caretPosition = textarea.selectionStart;
|
407
|
+
selection = $$.val().substring(caretPosition, textarea.selectionEnd);
|
408
|
+
}
|
409
|
+
return selection;
|
410
|
+
}
|
411
|
+
|
412
|
+
// open preview window
|
413
|
+
function preview() {
|
414
|
+
if (!previewWindow || previewWindow.closed) {
|
415
|
+
if (options.previewInWindow) {
|
416
|
+
previewWindow = window.open('', 'preview', options.previewInWindow);
|
417
|
+
} else {
|
418
|
+
iFrame = $('<iframe class="markItUpPreviewFrame"></iframe>');
|
419
|
+
if (options.previewPosition == 'after') {
|
420
|
+
iFrame.insertAfter(footer);
|
421
|
+
} else {
|
422
|
+
iFrame.insertBefore(header);
|
423
|
+
}
|
424
|
+
previewWindow = iFrame[iFrame.length - 1].contentWindow || frame[iFrame.length - 1];
|
425
|
+
}
|
426
|
+
} else if (altKey === true) {
|
427
|
+
// Thx Stephen M. Redd for the IE8 fix
|
428
|
+
if (iFrame) {
|
429
|
+
iFrame.remove();
|
430
|
+
} else {
|
431
|
+
previewWindow.close();
|
432
|
+
}
|
433
|
+
previewWindow = iFrame = false;
|
434
|
+
}
|
435
|
+
if (!options.previewAutoRefresh) {
|
436
|
+
refreshPreview();
|
437
|
+
}
|
438
|
+
}
|
439
|
+
|
440
|
+
// refresh Preview window
|
441
|
+
function refreshPreview() {
|
442
|
+
renderPreview();
|
443
|
+
}
|
444
|
+
|
445
|
+
function renderPreview() {
|
446
|
+
var phtml;
|
447
|
+
if (options.previewParserPath !== '') {
|
448
|
+
$.ajax( {
|
449
|
+
type: 'POST',
|
450
|
+
url: options.previewParserPath,
|
451
|
+
data: options.previewParserVar+'='+encodeURIComponent($$.val()),
|
452
|
+
success: function(data) {
|
453
|
+
writeInPreview( localize(data, 1) );
|
454
|
+
}
|
455
|
+
} );
|
456
|
+
} else {
|
457
|
+
if (!template) {
|
458
|
+
$.ajax( {
|
459
|
+
url: options.previewTemplatePath,
|
460
|
+
success: function(data) {
|
461
|
+
writeInPreview( localize(data, 1).replace(/<!-- content -->/g, $$.val()) );
|
462
|
+
}
|
463
|
+
} );
|
464
|
+
}
|
465
|
+
}
|
466
|
+
return false;
|
467
|
+
}
|
468
|
+
|
469
|
+
function writeInPreview(data) {
|
470
|
+
if (previewWindow.document) {
|
471
|
+
try {
|
472
|
+
sp = previewWindow.document.documentElement.scrollTop
|
473
|
+
} catch(e) {
|
474
|
+
sp = 0;
|
475
|
+
}
|
476
|
+
previewWindow.document.open();
|
477
|
+
previewWindow.document.write(data);
|
478
|
+
previewWindow.document.close();
|
479
|
+
previewWindow.document.documentElement.scrollTop = sp;
|
480
|
+
}
|
481
|
+
if (options.previewInWindow) {
|
482
|
+
previewWindow.focus();
|
483
|
+
}
|
484
|
+
}
|
485
|
+
|
486
|
+
// set keys pressed
|
487
|
+
function keyPressed(e) {
|
488
|
+
shiftKey = e.shiftKey;
|
489
|
+
altKey = e.altKey;
|
490
|
+
ctrlKey = (!(e.altKey && e.ctrlKey)) ? e.ctrlKey : false;
|
491
|
+
|
492
|
+
if (e.type === 'keydown') {
|
493
|
+
if (ctrlKey === true) {
|
494
|
+
li = $("a[accesskey="+String.fromCharCode(e.keyCode)+"]", header).parent('li');
|
495
|
+
if (li.length !== 0) {
|
496
|
+
ctrlKey = false;
|
497
|
+
setTimeout(function() {
|
498
|
+
li.triggerHandler('mousedown');
|
499
|
+
},1);
|
500
|
+
return false;
|
501
|
+
}
|
502
|
+
}
|
503
|
+
if (e.keyCode === 13 || e.keyCode === 10) { // Enter key
|
504
|
+
if (ctrlKey === true) { // Enter + Ctrl
|
505
|
+
ctrlKey = false;
|
506
|
+
markup(options.onCtrlEnter);
|
507
|
+
return options.onCtrlEnter.keepDefault;
|
508
|
+
} else if (shiftKey === true) { // Enter + Shift
|
509
|
+
shiftKey = false;
|
510
|
+
markup(options.onShiftEnter);
|
511
|
+
return options.onShiftEnter.keepDefault;
|
512
|
+
} else { // only Enter
|
513
|
+
markup(options.onEnter);
|
514
|
+
return options.onEnter.keepDefault;
|
515
|
+
}
|
516
|
+
}
|
517
|
+
if (e.keyCode === 9) { // Tab key
|
518
|
+
if (shiftKey == true || ctrlKey == true || altKey == true) { // Thx Dr Floob.
|
519
|
+
return false;
|
520
|
+
}
|
521
|
+
if (caretOffset !== -1) {
|
522
|
+
get();
|
523
|
+
caretOffset = $$.val().length - caretOffset;
|
524
|
+
set(caretOffset, 0);
|
525
|
+
caretOffset = -1;
|
526
|
+
return false;
|
527
|
+
} else {
|
528
|
+
markup(options.onTab);
|
529
|
+
return options.onTab.keepDefault;
|
530
|
+
}
|
531
|
+
}
|
532
|
+
}
|
533
|
+
}
|
534
|
+
|
535
|
+
init();
|
536
|
+
});
|
537
|
+
};
|
538
|
+
|
539
|
+
$.fn.markItUpRemove = function() {
|
540
|
+
return this.each(function() {
|
541
|
+
var $$ = $(this).unbind().removeClass('markItUpEditor');
|
542
|
+
$$.parent('div').parent('div.markItUp').parent('div').replaceWith($$);
|
543
|
+
}
|
544
|
+
);
|
545
|
+
};
|
546
|
+
|
547
|
+
$.markItUp = function(settings) {
|
548
|
+
var options = { target:false };
|
549
|
+
$.extend(options, settings);
|
550
|
+
if (options.target) {
|
551
|
+
return $(options.target).each(function() {
|
552
|
+
$(this).focus();
|
553
|
+
$(this).trigger('insertion', [options]);
|
554
|
+
});
|
555
|
+
} else {
|
556
|
+
$('textarea').trigger('insertion', [options]);
|
557
|
+
}
|
558
|
+
};
|
559
|
+
})(jQuery);
|
@@ -0,0 +1,9 @@
|
|
1
|
+
// ----------------------------------------------------------------------------
|
2
|
+
// markItUp! Universal MarkUp Engine, JQuery plugin
|
3
|
+
// v 1.1.7
|
4
|
+
// Dual licensed under the MIT and GPL licenses.
|
5
|
+
// ----------------------------------------------------------------------------
|
6
|
+
// Copyright (C) 2007-2010 Jay Salvat
|
7
|
+
// http://markitup.jaysalvat.com/
|
8
|
+
// ----------------------------------------------------------------------------
|
9
|
+
eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('(3($){$.23.T=3(f,g){B k,v,A,F;v=A=F=l;k={D:\'\',12:\'\',U:\'\',1j:\'\',1y:7,24:\'25\',1k:\'~/2R/1z.1A\',1b:\'\',26:\'27\',1l:7,1B:\'\',1C:\'\',1D:{},1E:{},1F:{},1G:{},28:[{}]};$.V(k,f,g);2(!k.U){$(\'2S\').1c(3(a,b){1H=$(b).14(0).2T.2U(/(.*)2V\\.2W(\\.2X)?\\.2Y$/);2(1H!==29){k.U=1H[1]}})}4 G.1c(3(){B d,u,15,16,p,H,L,P,17,1m,w,2a,M,18;d=$(G);u=G;15=[];18=l;16=p=0;H=-1;k.1b=1d(k.1b);k.1k=1d(k.1k);3 1d(a,b){2(b){4 a.W(/("|\')~\\//g,"$1"+k.U)}4 a.W(/^~\\//,k.U)}3 2b(){D=\'\';12=\'\';2(k.D){D=\'D="\'+k.D+\'"\'}8 2(d.1I("D")){D=\'D="T\'+(d.1I("D").2c(0,1).2Z())+(d.1I("D").2c(1))+\'"\'}2(k.12){12=\'N="\'+k.12+\'"\'}d.1J(\'<z \'+12+\'></z>\');d.1J(\'<z \'+D+\' N="T"></z>\');d.1J(\'<z N="30"></z>\');d.2d("2e");17=$(\'<z N="31"></z>\').2f(d);$(1K(k.28)).1L(17);1m=$(\'<z N="32"></z>\').1M(d);2(k.1l===7&&$.X.33!==7){1l=$(\'<z N="34"></z>\').1M(d).1e("1N",3(e){B h=d.2g(),y=e.2h,1n,1o;1n=3(e){d.2i("2g",35.36(20,e.2h+h-y)+"37");4 l};1o=3(e){$("1A").1O("2j",1n).1O("2k",1o);4 l};$("1A").1e("2j",1n).1e("2k",1o)});1m.2l(1l)}d.2m(1P).38(1P);d.1e("1Q",3(e,a){2(a.1p!==l){14()}2(u===$.T.2n){Y(a)}});d.1f(3(){$.T.2n=G})}3 1K(b){B c=$(\'<Z></Z>\'),i=0;$(\'C:2o > Z\',c).2i(\'39\',\'q\');$.1c(b,3(){B a=G,t=\'\',1q,C,j;1q=(a.19)?(a.1R||\'\')+\' [3a+\'+a.19+\']\':(a.1R||\'\');19=(a.19)?\'2p="\'+a.19+\'"\':\'\';2(a.2q){C=$(\'<C N="3b">\'+(a.2q||\'\')+\'</C>\').1L(c)}8{i++;2r(j=15.6-1;j>=0;j--){t+=15[j]+"-"}C=$(\'<C N="2s 2s\'+t+(i)+\' \'+(a.3c||\'\')+\'"><a 3d="" \'+19+\' 1q="\'+1q+\'">\'+(a.1R||\'\')+\'</a></C>\').1e("3e",3(){4 l}).2t(3(){4 l}).1N(3(){2(a.2u){3f(a.2u)()}2v(3(){Y(a)},1);4 l}).2o(3(){$(\'> Z\',G).3g();$(E).3h(\'2t\',3(){$(\'Z Z\',17).2w()})},3(){$(\'> Z\',G).2w()}).1L(c);2(a.2x){15.3i(i);$(C).2d(\'3j\').2l(1K(a.2x))}}});15.3k();4 c}3 2y(c){2(c){c=c.3l();c=c.W(/\\(\\!\\(([\\s\\S]*?)\\)\\!\\)/g,3(x,a){B b=a.1S(\'|!|\');2(F===7){4(b[1]!==2z)?b[1]:b[0]}8{4(b[1]===2z)?"":b[0]}});c=c.W(/\\[\\!\\[([\\s\\S]*?)\\]\\!\\]/g,3(x,a){B b=a.1S(\':!:\');2(18===7){4 l}1T=3m(b[0],(b[1])?b[1]:\'\');2(1T===29){18=7}4 1T});4 c}4""}3 I(a){2($.3n(a)){a=a(P)}4 2y(a)}3 1g(a){J=I(L.J);1a=I(L.1a);Q=I(L.Q);O=I(L.O);2(Q!==""){q=J+Q+O}8 2(m===\'\'&&1a!==\'\'){q=J+1a+O}8{q=J+(a||m)+O}4{q:q,J:J,Q:Q,1a:1a,O:O}}3 Y(a){B b,j,n,i;P=L=a;14();$.V(P,{1r:"",U:k.U,u:u,m:(m||\'\'),p:p,v:v,A:A,F:F});I(k.1B);I(L.1B);2(v===7&&A===7){I(L.3o)}$.V(P,{1r:1});2(v===7&&A===7){R=m.1S(/\\r?\\n/);2r(j=0,n=R.6,i=0;i<n;i++){2($.3p(R[i])!==\'\'){$.V(P,{1r:++j,m:R[i]});R[i]=1g(R[i]).q}8{R[i]=""}}o={q:R.3q(\'\\n\')};11=p;b=o.q.6+(($.X.1U)?n:0)}8 2(v===7){o=1g(m);11=p+o.J.6;b=o.q.6-o.J.6-o.O.6;b-=1s(o.q)}8 2(A===7){o=1g(m);11=p;b=o.q.6;b-=1s(o.q)}8{o=1g(m);11=p+o.q.6;b=0;11-=1s(o.q)}2((m===\'\'&&o.Q===\'\')){H+=1V(o.q);11=p+o.J.6;b=o.q.6-o.J.6-o.O.6;H=d.K().1h(p,d.K().6).6;H-=1V(d.K().1h(0,p))}$.V(P,{p:p,16:16});2(o.q!==m&&18===l){2A(o.q);1W(11,b)}8{H=-1}14();$.V(P,{1r:\'\',m:m});2(v===7&&A===7){I(L.3r)}I(L.1C);I(k.1C);2(w&&k.1y){1X()}A=F=v=18=l}3 1V(a){2($.X.1U){4 a.6-a.W(/\\n*/g,\'\').6}4 0}3 1s(a){2($.X.2B){4 a.6-a.W(/\\r*/g,\'\').6}4 0}3 2A(a){2(E.m){B b=E.m.1Y();b.2C=a}8{d.K(d.K().1h(0,p)+a+d.K().1h(p+m.6,d.K().6))}}3 1W(a,b){2(u.2D){2($.X.1U&&$.X.3s>=9.5&&b==0){4 l}1i=u.2D();1i.3t(7);1i.2E(\'1Z\',a);1i.3u(\'1Z\',b);1i.3v()}8 2(u.2F){u.2F(a,a+b)}u.1t=16;u.1f()}3 14(){u.1f();16=u.1t;2(E.m){m=E.m.1Y().2C;2($.X.2B){B a=E.m.1Y(),1u=a.3w();1u.3x(u);p=-1;3y(1u.3z(a)){1u.2E(\'1Z\');p++}}8{p=u.2G}}8{p=u.2G;m=d.K().1h(p,u.3A)}4 m}3 1z(){2(!w||w.3B){2(k.1j){w=3C.2H(\'\',\'1z\',k.1j)}8{M=$(\'<2I N="3D"></2I>\');2(k.24==\'25\'){M.1M(1m)}8{M.2f(17)}w=M[M.6-1].3E||3F[M.6-1]}}8 2(F===7){2(M){M.3G()}8{w.2J()}w=M=l}2(!k.1y){1X()}}3 1X(){2K()}3 2K(){B b;2(k.1b!==\'\'){$.2L({2M:\'3H\',2N:k.1b,27:k.26+\'=\'+3I(d.K()),2O:3(a){21(1d(a,1))}})}8{2(!2a){$.2L({2N:k.1k,2O:3(a){21(1d(a,1).W(/<!-- 3J -->/g,d.K()))}})}}4 l}3 21(a){2(w.E){3K{22=w.E.2P.1t}3L(e){22=0}w.E.2H();w.E.3M(a);w.E.2J();w.E.2P.1t=22}2(k.1j){w.1f()}}3 1P(e){A=e.A;F=e.F;v=(!(e.F&&e.v))?e.v:l;2(e.2M===\'2m\'){2(v===7){C=$("a[2p="+3N.3O(e.1v)+"]",17).1w(\'C\');2(C.6!==0){v=l;2v(3(){C.3P(\'1N\')},1);4 l}}2(e.1v===13||e.1v===10){2(v===7){v=l;Y(k.1F);4 k.1F.1x}8 2(A===7){A=l;Y(k.1E);4 k.1E.1x}8{Y(k.1D);4 k.1D.1x}}2(e.1v===9){2(A==7||v==7||F==7){4 l}2(H!==-1){14();H=d.K().6-H;1W(H,0);H=-1;4 l}8{Y(k.1G);4 k.1G.1x}}}}2b()})};$.23.3Q=3(){4 G.1c(3(){B a=$(G).1O().3R(\'2e\');a.1w(\'z\').1w(\'z.T\').1w(\'z\').Q(a)})};$.T=3(a){B b={1p:l};$.V(b,a);2(b.1p){4 $(b.1p).1c(3(){$(G).1f();$(G).2Q(\'1Q\',[b])})}8{$(\'u\').2Q(\'1Q\',[b])}}})(3S);',62,241,'||if|function|return||length|true|else|||||||||||||false|selection||string|caretPosition|block||||textarea|ctrlKey|previewWindow|||div|shiftKey|var|li|id|document|altKey|this|caretOffset|prepare|openWith|val|clicked|iFrame|class|closeWith|hash|replaceWith|lines||markItUp|root|extend|replace|browser|markup|ul||start|nameSpace||get|levels|scrollPosition|header|abort|key|placeHolder|previewParserPath|each|localize|bind|focus|build|substring|range|previewInWindow|previewTemplatePath|resizeHandle|footer|mouseMove|mouseUp|target|title|line|fixIeBug|scrollTop|rangeCopy|keyCode|parent|keepDefault|previewAutoRefresh|preview|html|beforeInsert|afterInsert|onEnter|onShiftEnter|onCtrlEnter|onTab|miuScript|attr|wrap|dropMenus|appendTo|insertAfter|mousedown|unbind|keyPressed|insertion|name|split|value|opera|fixOperaBug|set|refreshPreview|createRange|character||writeInPreview|sp|fn|previewPosition|after|previewParserVar|data|markupSet|null|template|init|substr|addClass|markItUpEditor|insertBefore|height|clientY|css|mousemove|mouseup|append|keydown|focused|hover|accesskey|separator|for|markItUpButton|click|call|setTimeout|hide|dropMenu|magicMarkups|undefined|insert|msie|text|createTextRange|moveStart|setSelectionRange|selectionStart|open|iframe|close|renderPreview|ajax|type|url|success|documentElement|trigger|templates|script|src|match|jquery|markitup|pack|js|toUpperCase|markItUpContainer|markItUpHeader|markItUpFooter|safari|markItUpResizeHandle|Math|max|px|keyup|display|Ctrl|markItUpSeparator|className|href|contextmenu|eval|show|one|push|markItUpDropMenu|pop|toString|prompt|isFunction|beforeMultiInsert|trim|join|afterMultiInsert|version|collapse|moveEnd|select|duplicate|moveToElementText|while|inRange|selectionEnd|closed|window|markItUpPreviewFrame|contentWindow|frame|remove|POST|encodeURIComponent|content|try|catch|write|String|fromCharCode|triggerHandler|markItUpRemove|removeClass|jQuery'.split('|'),0,{}))
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|