rails-uikit 2.8.0

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.
Files changed (48) hide show
  1. data/lib/rails/uikit/engine.rb +6 -0
  2. data/lib/rails/uikit/version.rb +5 -0
  3. data/lib/rails/uikit.rb +8 -0
  4. data/public/fonts/FontAwesome.otf +0 -0
  5. data/public/fonts/fontawesome-webfont.eot +0 -0
  6. data/public/fonts/fontawesome-webfont.ttf +0 -0
  7. data/public/fonts/fontawesome-webfont.woff +0 -0
  8. data/vendor/assets/javascripts/addons/autocomplete.js +306 -0
  9. data/vendor/assets/javascripts/addons/autocomplete.min.js +3 -0
  10. data/vendor/assets/javascripts/addons/datepicker.js +365 -0
  11. data/vendor/assets/javascripts/addons/datepicker.min.js +3 -0
  12. data/vendor/assets/javascripts/addons/form-password.js +62 -0
  13. data/vendor/assets/javascripts/addons/form-password.min.js +3 -0
  14. data/vendor/assets/javascripts/addons/form-select.js +62 -0
  15. data/vendor/assets/javascripts/addons/form-select.min.js +3 -0
  16. data/vendor/assets/javascripts/addons/htmleditor.js +594 -0
  17. data/vendor/assets/javascripts/addons/htmleditor.min.js +3 -0
  18. data/vendor/assets/javascripts/addons/nestable.js +574 -0
  19. data/vendor/assets/javascripts/addons/nestable.min.js +3 -0
  20. data/vendor/assets/javascripts/addons/notify.js +177 -0
  21. data/vendor/assets/javascripts/addons/notify.min.js +3 -0
  22. data/vendor/assets/javascripts/addons/pagination.js +146 -0
  23. data/vendor/assets/javascripts/addons/pagination.min.js +3 -0
  24. data/vendor/assets/javascripts/addons/search.js +90 -0
  25. data/vendor/assets/javascripts/addons/search.min.js +3 -0
  26. data/vendor/assets/javascripts/addons/sortable.js +494 -0
  27. data/vendor/assets/javascripts/addons/sortable.min.js +3 -0
  28. data/vendor/assets/javascripts/addons/sticky.js +130 -0
  29. data/vendor/assets/javascripts/addons/sticky.min.js +3 -0
  30. data/vendor/assets/javascripts/addons/timepicker.js +163 -0
  31. data/vendor/assets/javascripts/addons/timepicker.min.js +3 -0
  32. data/vendor/assets/javascripts/addons/upload.js +239 -0
  33. data/vendor/assets/javascripts/addons/upload.min.js +3 -0
  34. data/vendor/assets/javascripts/uikit.js +2573 -0
  35. data/vendor/assets/javascripts/uikit.min.js +4 -0
  36. data/vendor/assets/stylesheets/addons/uikit.addons.css +1124 -0
  37. data/vendor/assets/stylesheets/addons/uikit.addons.min.css +3 -0
  38. data/vendor/assets/stylesheets/addons/uikit.almost-flat.addons.css +1205 -0
  39. data/vendor/assets/stylesheets/addons/uikit.almost-flat.addons.min.css +3 -0
  40. data/vendor/assets/stylesheets/addons/uikit.gradient.addons.css +1226 -0
  41. data/vendor/assets/stylesheets/addons/uikit.gradient.addons.min.css +3 -0
  42. data/vendor/assets/stylesheets/uikit.almost-flat.css +7022 -0
  43. data/vendor/assets/stylesheets/uikit.almost-flat.min.css +3 -0
  44. data/vendor/assets/stylesheets/uikit.css +6732 -0
  45. data/vendor/assets/stylesheets/uikit.gradient.css +7090 -0
  46. data/vendor/assets/stylesheets/uikit.gradient.min.css +3 -0
  47. data/vendor/assets/stylesheets/uikit.min.css +3 -0
  48. metadata +125 -0
@@ -0,0 +1,594 @@
1
+ /*! UIkit 2.8.0 | http://www.getuikit.com | (c) 2014 YOOtheme | MIT License */
2
+
3
+ (function(addon) {
4
+
5
+ var component;
6
+
7
+ if (jQuery && jQuery.UIkit) {
8
+ component = addon(jQuery, jQuery.UIkit);
9
+ }
10
+
11
+ if (typeof define == "function" && define.amd) {
12
+ define("uikit-htmleditor", ["uikit"], function(){
13
+ return component || addon(jQuery, jQuery.UIkit);
14
+ });
15
+ }
16
+
17
+ })(function($, UI) {
18
+
19
+ var editors = [];
20
+
21
+ UI.component('htmleditor', {
22
+
23
+ defaults: {
24
+ mode : 'split',
25
+ markdown : false,
26
+ autocomplete : true,
27
+ height : 500,
28
+ maxsplitsize : 1000,
29
+ markedOptions: { gfm: true, tables: true, breaks: true, pedantic: true, sanitize: false, smartLists: true, smartypants: false, langPrefix: 'lang-'},
30
+ codemirror : { mode: 'htmlmixed', tabMode: 'indent', tabsize: 4, lineWrapping: true, dragDrop: false, autoCloseTags: true, matchTags: true, autoCloseBrackets: true, matchBrackets: true, indentUnit: 4, hintOptions: {completionSingle:false} },
31
+ toolbar : [ 'bold', 'italic', 'strike', 'link', 'image', 'blockquote', 'listUl', 'listOl' ],
32
+ lblPreview : 'Preview',
33
+ lblCodeview : 'HTML',
34
+ lblMarkedview: 'Markdown'
35
+ },
36
+
37
+ init: function() {
38
+
39
+ var $this = this, tpl = UI.components.htmleditor.template;
40
+
41
+ this.CodeMirror = this.options.CodeMirror || CodeMirror;
42
+ this.buttons = {};
43
+
44
+ tpl = tpl.replace(/\{:lblPreview\}/g, this.options.lblPreview);
45
+ tpl = tpl.replace(/\{:lblCodeview\}/g, this.options.lblCodeview);
46
+
47
+ this.htmleditor = $(tpl);
48
+ this.content = this.htmleditor.find('.uk-htmleditor-content');
49
+ this.toolbar = this.htmleditor.find('.uk-htmleditor-toolbar');
50
+ this.preview = this.htmleditor.find('.uk-htmleditor-preview').children().eq(0);
51
+ this.code = this.htmleditor.find('.uk-htmleditor-code');
52
+
53
+ this.element.before(this.htmleditor).appendTo(this.code);
54
+ this.editor = this.CodeMirror.fromTextArea(this.element[0], this.options.codemirror);
55
+ this.editor.htmleditor = this;
56
+ this.editor.on('change', UI.Utils.debounce(function() { $this.render(); }, 150));
57
+ this.editor.on('change', function() { $this.editor.save(); });
58
+ this.code.find('.CodeMirror').css('height', this.options.height);
59
+
60
+ $(window).on('resize', UI.Utils.debounce(function() { $this.fit(); }, 200));
61
+
62
+ var previewContainer = $this.preview.parent(),
63
+ codeContent = this.code.find('.CodeMirror-sizer'),
64
+ codeScroll = this.code.find('.CodeMirror-scroll').on('scroll', UI.Utils.debounce(function() {
65
+
66
+ if ($this.htmleditor.attr('data-mode') == 'tab') return;
67
+
68
+ // calc position
69
+ var codeHeight = codeContent.height() - codeScroll.height(),
70
+ previewHeight = previewContainer[0].scrollHeight - previewContainer.height(),
71
+ ratio = previewHeight / codeHeight,
72
+ previewPostition = codeScroll.scrollTop() * ratio;
73
+
74
+ // apply new scroll
75
+ previewContainer.scrollTop(previewPostition);
76
+
77
+ }, 10));
78
+
79
+ this.htmleditor.on('click', '.uk-htmleditor-button-code, .uk-htmleditor-button-preview', function(e) {
80
+
81
+ e.preventDefault();
82
+
83
+ if ($this.htmleditor.attr('data-mode') == 'tab') {
84
+
85
+ $this.htmleditor.find('.uk-htmleditor-button-code, .uk-htmleditor-button-preview').removeClass('uk-active').filter(this).addClass('uk-active');
86
+
87
+ $this.activetab = $(this).hasClass('uk-htmleditor-button-code') ? 'code' : 'preview';
88
+ $this.htmleditor.attr('data-active-tab', $this.activetab);
89
+ $this.editor.refresh();
90
+ }
91
+ });
92
+
93
+ // toolbar actions
94
+ this.htmleditor.on('click', 'a[data-htmleditor-button]', function() {
95
+
96
+ if (!$this.code.is(':visible')) return;
97
+
98
+ $this.trigger('action.' + $(this).data('htmleditor-button'), [$this.editor]);
99
+ });
100
+
101
+ this.preview.parent().css('height', this.code.height());
102
+
103
+ // autocomplete
104
+ if (this.options.autocomplete && this.CodeMirror.showHint && this.CodeMirror.hint && this.CodeMirror.hint.html) {
105
+
106
+ this.editor.on('inputRead', UI.Utils.debounce(function() {
107
+ var doc = $this.editor.getDoc(), POS = doc.getCursor(), mode = $this.CodeMirror.innerMode($this.editor.getMode(), $this.editor.getTokenAt(POS).state).mode.name;
108
+
109
+ if (mode == 'xml') { //html depends on xml
110
+
111
+ var cur = $this.editor.getCursor(), token = $this.editor.getTokenAt(cur);
112
+
113
+ if (token.string.charAt(0) == '<' || token.type == 'attribute') {
114
+ $this.CodeMirror.showHint($this.editor, $this.CodeMirror.hint.html, { completeSingle: false });
115
+ }
116
+ }
117
+ }, 100));
118
+ }
119
+
120
+ this.debouncedRedraw = UI.Utils.debounce(function () { $this.redraw(); }, 5);
121
+
122
+ this.on('init', function() {
123
+ $this.redraw();
124
+ });
125
+
126
+ editors.push(this);
127
+ },
128
+
129
+ addButton: function(name, button) {
130
+ this.buttons[name] = button;
131
+ },
132
+
133
+ addButtons: function(buttons) {
134
+ $.extend(this.buttons, buttons);
135
+ },
136
+
137
+ replaceInPreview: function(regexp, callback) {
138
+
139
+ var editor = this.editor, results = [], value = editor.getValue(), offset = -1;
140
+
141
+ this.currentvalue = this.currentvalue.replace(regexp, function() {
142
+
143
+ offset = value.indexOf(arguments[0], ++offset);
144
+
145
+ var match = {
146
+ matches: arguments,
147
+ from : translateOffset(offset),
148
+ to : translateOffset(offset + arguments[0].length),
149
+ replace: function(value) {
150
+ editor.replaceRange(value, match.from, match.to);
151
+ },
152
+ inRange: function(cursor) {
153
+
154
+ if (cursor.line === match.from.line && cursor.line === match.to.line) {
155
+ return cursor.ch >= match.from.ch && cursor.ch < match.to.ch;
156
+ }
157
+
158
+ return (cursor.line === match.from.line && cursor.ch >= match.from.ch)
159
+ || (cursor.line > match.from.line && cursor.line < match.to.line)
160
+ || (cursor.line === match.to.line && cursor.ch < match.to.ch);
161
+ }
162
+ };
163
+
164
+ var result = callback(match);
165
+
166
+ if (result == false) {
167
+ return arguments[0];
168
+ }
169
+
170
+ results.push(match);
171
+ return result;
172
+ });
173
+
174
+ function translateOffset(offset) {
175
+ var result = editor.getValue().substring(0, offset).split('\n');
176
+ return { line: result.length - 1, ch: result[result.length - 1].length }
177
+ }
178
+
179
+ return results;
180
+ },
181
+
182
+ _buildtoolbar: function() {
183
+
184
+ if (!(this.options.toolbar && this.options.toolbar.length)) return;
185
+
186
+ var $this = this, bar = [];
187
+
188
+ this.toolbar.empty();
189
+
190
+ this.options.toolbar.forEach(function(button) {
191
+ if (!$this.buttons[button]) return;
192
+
193
+ var title = $this.buttons[button].title ? $this.buttons[button].title : button;
194
+
195
+ bar.push('<li><a data-htmleditor-button="'+button+'" title="'+title+'" data-uk-tooltip>'+$this.buttons[button].label+'</a></li>');
196
+ });
197
+
198
+ this.toolbar.html(bar.join('\n'));
199
+ },
200
+
201
+ fit: function() {
202
+
203
+ var mode = this.options.mode;
204
+
205
+ if (mode == 'split' && this.htmleditor.width() < this.options.maxsplitsize) {
206
+ mode = 'tab';
207
+ }
208
+
209
+ if (mode == 'tab') {
210
+ if (!this.activetab) {
211
+ this.activetab = 'code';
212
+ this.htmleditor.attr('data-active-tab', this.activetab);
213
+ }
214
+
215
+ this.htmleditor.find('.uk-htmleditor-button-code, .uk-htmleditor-button-preview').removeClass('uk-active')
216
+ .filter(this.activetab == 'code' ? '.uk-htmleditor-button-code' : '.uk-htmleditor-button-preview')
217
+ .addClass('uk-active');
218
+ }
219
+
220
+ this.editor.refresh();
221
+ this.preview.parent().css('height', this.code.height());
222
+
223
+ this.htmleditor.attr('data-mode', mode);
224
+ },
225
+
226
+ redraw: function() {
227
+ this._buildtoolbar();
228
+ this.render();
229
+ this.fit();
230
+ },
231
+
232
+ getMode: function() {
233
+ return this.editor.getOption('mode');
234
+ },
235
+
236
+ getCursorMode: function() {
237
+ var param = { mode: 'html'};
238
+ this.trigger('cursorMode', [param]);
239
+ return param.mode;
240
+ },
241
+
242
+ render: function() {
243
+
244
+ this.currentvalue = this.editor.getValue();
245
+
246
+ // empty code
247
+ if (!this.currentvalue) {
248
+
249
+ this.element.val('');
250
+ this.preview.html('');
251
+
252
+ return;
253
+ }
254
+
255
+ this.trigger('render', [this]);
256
+ this.trigger('renderLate', [this]);
257
+
258
+ this.preview.html(this.currentvalue);
259
+ },
260
+
261
+ addShortcut: function(name, callback) {
262
+ var map = {};
263
+ if (!$.isArray(name)) {
264
+ name = [name];
265
+ }
266
+
267
+ name.forEach(function(key) {
268
+ map[key] = callback;
269
+ });
270
+
271
+ this.editor.addKeyMap(map);
272
+
273
+ return map;
274
+ },
275
+
276
+ addShortcutAction: function(action, shortcuts) {
277
+ var editor = this;
278
+ this.addShortcut(shortcuts, function() {
279
+ editor.element.trigger('action.' + action, [editor.editor]);
280
+ });
281
+ },
282
+
283
+ replaceSelection: function(replace) {
284
+
285
+ var text = this.editor.getSelection();
286
+
287
+ if (!text.length) {
288
+
289
+ var cur = this.editor.getCursor(),
290
+ curLine = this.editor.getLine(cur.line),
291
+ start = cur.ch,
292
+ end = start;
293
+
294
+ while (end < curLine.length && /[\w$]+/.test(curLine.charAt(end))) ++end;
295
+ while (start && /[\w$]+/.test(curLine.charAt(start - 1))) --start;
296
+
297
+ var curWord = start != end && curLine.slice(start, end);
298
+
299
+ if (curWord) {
300
+ this.editor.setSelection({ line: cur.line, ch: start}, { line: cur.line, ch: end });
301
+ text = curWord;
302
+ }
303
+ }
304
+
305
+ var html = replace.replace('$1', text);
306
+
307
+ this.editor.replaceSelection(html, 'end');
308
+ this.editor.focus();
309
+ },
310
+
311
+ replaceLine: function(replace) {
312
+ var pos = this.editor.getDoc().getCursor(),
313
+ text = this.editor.getLine(pos.line),
314
+ html = replace.replace('$1', text);
315
+
316
+ this.editor.replaceRange(html , { line: pos.line, ch: 0 }, { line: pos.line, ch: text.length });
317
+ this.editor.setCursor({ line: pos.line, ch: html.length });
318
+ this.editor.focus();
319
+ },
320
+
321
+ save: function() {
322
+ this.editor.save();
323
+ }
324
+ });
325
+
326
+
327
+ UI.components.htmleditor.template = [
328
+ '<div class="uk-htmleditor uk-clearfix" data-mode="split">',
329
+ '<div class="uk-htmleditor-navbar">',
330
+ '<ul class="uk-htmleditor-navbar-nav uk-htmleditor-toolbar"></ul>',
331
+ '<div class="uk-htmleditor-navbar-flip">',
332
+ '<ul class="uk-htmleditor-navbar-nav">',
333
+ '<li class="uk-htmleditor-button-code"><a>{:lblCodeview}</a></li>',
334
+ '<li class="uk-htmleditor-button-preview"><a>{:lblPreview}</a></li>',
335
+ '<li><a data-htmleditor-button="fullscreen"><i class="uk-icon-expand"></i></a></li>',
336
+ '</ul>',
337
+ '</div>',
338
+ '</div>',
339
+ '<div class="uk-htmleditor-content">',
340
+ '<div class="uk-htmleditor-code"></div>',
341
+ '<div class="uk-htmleditor-preview"><div></div></div>',
342
+ '</div>',
343
+ '</div>'
344
+ ].join('');
345
+
346
+
347
+ UI.plugin('htmleditor', 'base', {
348
+
349
+ init: function(editor) {
350
+
351
+ editor.addButtons({
352
+
353
+ fullscreen: {
354
+ title : 'Fullscreen',
355
+ label : '<i class="uk-icon-expand"></i>'
356
+ },
357
+ bold : {
358
+ title : 'Bold',
359
+ label : '<i class="uk-icon-bold"></i>'
360
+ },
361
+ italic : {
362
+ title : 'Italic',
363
+ label : '<i class="uk-icon-italic"></i>'
364
+ },
365
+ strike : {
366
+ title : 'Strikethrough',
367
+ label : '<i class="uk-icon-strikethrough"></i>'
368
+ },
369
+ blockquote : {
370
+ title : 'Blockquote',
371
+ label : '<i class="uk-icon-quote-right"></i>'
372
+ },
373
+ link : {
374
+ title : 'Link',
375
+ label : '<i class="uk-icon-link"></i>'
376
+ },
377
+ image : {
378
+ title : 'Image',
379
+ label : '<i class="uk-icon-picture-o"></i>'
380
+ },
381
+ listUl : {
382
+ title : 'Unordered List',
383
+ label : '<i class="uk-icon-list-ul"></i>'
384
+ },
385
+ listOl : {
386
+ title : 'Ordered List',
387
+ label : '<i class="uk-icon-list-ol"></i>'
388
+ }
389
+
390
+ });
391
+
392
+ addAction('bold', '<strong>$1</strong>');
393
+ addAction('italic', '<em>$1</em>');
394
+ addAction('strike', '<del>$1</del>');
395
+ addAction('blockquote', '<blockquote><p>$1</p></blockquote>', 'replaceLine');
396
+ addAction('link', '<a href="http://">$1</a>');
397
+ addAction('image', '<img src="http://" alt="$1">');
398
+
399
+ var listfn = function() {
400
+ if (editor.getCursorMode() == 'html') {
401
+
402
+ var cm = editor.editor,
403
+ pos = cm.getDoc().getCursor(true),
404
+ posend = cm.getDoc().getCursor(false);
405
+
406
+ for (var i=pos.line; i<(posend.line+1);i++) {
407
+ cm.replaceRange('<li>'+cm.getLine(i)+'</li>', { line: i, ch: 0 }, { line: i, ch: cm.getLine(i).length });
408
+ }
409
+
410
+ cm.setCursor({ line: posend.line, ch: cm.getLine(posend.line).length });
411
+ cm.focus();
412
+ }
413
+ }
414
+
415
+ editor.on('action.listUl', function() {
416
+ listfn();
417
+ });
418
+
419
+ editor.on('action.listOl', function() {
420
+ listfn();
421
+ });
422
+
423
+ editor.htmleditor.on('click', 'a[data-htmleditor-button="fullscreen"]', function() {
424
+ editor.htmleditor.toggleClass('uk-htmleditor-fullscreen');
425
+
426
+ var wrap = editor.editor.getWrapperElement();
427
+
428
+ if (editor.htmleditor.hasClass('uk-htmleditor-fullscreen')) {
429
+
430
+ editor.editor.state.fullScreenRestore = {scrollTop: window.pageYOffset, scrollLeft: window.pageXOffset, width: wrap.style.width, height: wrap.style.height};
431
+ wrap.style.width = '';
432
+ wrap.style.height = editor.content.height()+'px';
433
+ document.documentElement.style.overflow = 'hidden';
434
+
435
+ } else {
436
+
437
+ document.documentElement.style.overflow = '';
438
+ var info = editor.editor.state.fullScreenRestore;
439
+ wrap.style.width = info.width; wrap.style.height = info.height;
440
+ window.scrollTo(info.scrollLeft, info.scrollTop);
441
+ }
442
+
443
+ setTimeout(function() {
444
+ editor.fit();
445
+ }, 10);
446
+ });
447
+
448
+ editor.addShortcut(['Ctrl-S', 'Cmd-S'], function() { editor.element.trigger('htmleditor-save', [editor]); });
449
+ editor.addShortcutAction('bold', ['Ctrl-B', 'Cmd-B']);
450
+
451
+ function addAction(name, replace, mode) {
452
+ editor.on('action.'+name, function() {
453
+ if (editor.getCursorMode() == 'html') {
454
+ editor[mode == 'replaceLine' ? 'replaceLine' : 'replaceSelection'](replace);
455
+ }
456
+ });
457
+ }
458
+ }
459
+ });
460
+
461
+ UI.plugin('htmleditor', 'markdown', {
462
+
463
+ init: function(editor) {
464
+
465
+ var parser = editor.options.marked || marked;
466
+
467
+ if (!parser) return;
468
+
469
+ parser.setOptions(editor.options.markedOptions);
470
+
471
+ if (editor.options.markdown) {
472
+ enableMarkdown()
473
+ }
474
+
475
+ addAction('bold', '**$1**');
476
+ addAction('italic', '*$1*');
477
+ addAction('strike', '~~$1~~');
478
+ addAction('blockquote', '> $1', 'replaceLine');
479
+ addAction('link', '[$1](http://)');
480
+ addAction('image', '![$1](http://)');
481
+
482
+ editor.on('action.listUl', function() {
483
+
484
+ if (editor.getCursorMode() == 'markdown') {
485
+
486
+ var cm = editor.editor,
487
+ pos = cm.getDoc().getCursor(true),
488
+ posend = cm.getDoc().getCursor(false);
489
+
490
+ for (var i=pos.line; i<(posend.line+1);i++) {
491
+ cm.replaceRange('* '+cm.getLine(i), { line: i, ch: 0 }, { line: i, ch: cm.getLine(i).length });
492
+ }
493
+
494
+ cm.setCursor({ line: posend.line, ch: cm.getLine(posend.line).length });
495
+ cm.focus();
496
+ }
497
+ });
498
+
499
+ editor.on('action.listOl', function() {
500
+
501
+ if (editor.getCursorMode() == 'markdown') {
502
+
503
+ var cm = editor.editor,
504
+ pos = cm.getDoc().getCursor(true),
505
+ posend = cm.getDoc().getCursor(false),
506
+ prefix = 1;
507
+
508
+ if (pos.line > 0) {
509
+ var prevline = cm.getLine(pos.line-1), matches;
510
+
511
+ if(matches = prevline.match(/^(\d+)\./)) {
512
+ prefix = Number(matches[1])+1;
513
+ }
514
+ }
515
+
516
+ for (var i=pos.line; i<(posend.line+1);i++) {
517
+ cm.replaceRange(prefix+'. '+cm.getLine(i), { line: i, ch: 0 }, { line: i, ch: cm.getLine(i).length });
518
+ prefix++;
519
+ }
520
+
521
+ cm.setCursor({ line: posend.line, ch: cm.getLine(posend.line).length });
522
+ cm.focus();
523
+ }
524
+ });
525
+
526
+ editor.on('renderLate', function() {
527
+ if (editor.editor.options.mode == 'gfm') {
528
+ editor.currentvalue = parser(editor.currentvalue);
529
+ }
530
+ });
531
+
532
+ editor.on('cursorMode', function(e, param) {
533
+ if (editor.editor.options.mode == 'gfm') {
534
+ var pos = editor.editor.getDoc().getCursor();
535
+ if (!editor.editor.getTokenAt(pos).state.base.htmlState) {
536
+ param.mode = 'markdown';
537
+ }
538
+ }
539
+ });
540
+
541
+ $.extend(editor, {
542
+
543
+ enableMarkdown: function() {
544
+ enableMarkdown()
545
+ this.render();
546
+ },
547
+ disableMarkdown: function() {
548
+ this.editor.setOption('mode', 'htmlmixed');
549
+ this.htmleditor.find('.uk-htmleditor-button-code a').html(this.options.lblCodeview);
550
+ this.render();
551
+ }
552
+
553
+ });
554
+
555
+ // switch markdown mode on event
556
+ editor.on({
557
+ enableMarkdown : function() { editor.enableMarkdown(); },
558
+ disableMarkdown : function() { editor.disableMarkdown(); }
559
+ });
560
+
561
+ function enableMarkdown() {
562
+ editor.editor.setOption('mode', 'gfm');
563
+ editor.htmleditor.find('.uk-htmleditor-button-code a').html(editor.options.lblMarkedview);
564
+ }
565
+
566
+ function addAction(name, replace, mode) {
567
+ editor.on('action.'+name, function() {
568
+ if (editor.getCursorMode() == 'markdown') {
569
+ editor[mode == 'replaceLine' ? 'replaceLine' : 'replaceSelection'](replace);
570
+ }
571
+ });
572
+ }
573
+ }
574
+ });
575
+
576
+ // init code
577
+ $(function() {
578
+ $('textarea[data-uk-htmleditor]').each(function() {
579
+ var editor = $(this), obj;
580
+
581
+ if (!editor.data('htmleditor')) {
582
+ obj = UI.htmleditor(editor, UI.Utils.options(editor.attr('data-uk-htmleditor')));
583
+ }
584
+ });
585
+ });
586
+
587
+ $(document).on("uk-check-display", function(e) {
588
+ editors.forEach(function(item) {
589
+ if(item.htmleditor.is(":visible")) item.fit();
590
+ });
591
+ });
592
+
593
+ return UI.htmleditor;
594
+ });
@@ -0,0 +1,3 @@
1
+ /*! UIkit 2.8.0 | http://www.getuikit.com | (c) 2014 YOOtheme | MIT License */
2
+
3
+ !function(a){var b;jQuery&&jQuery.UIkit&&(b=a(jQuery,jQuery.UIkit)),"function"==typeof define&&define.amd&&define("uikit-htmleditor",["uikit"],function(){return b||a(jQuery,jQuery.UIkit)})}(function(a,b){var c=[];return b.component("htmleditor",{defaults:{mode:"split",markdown:!1,autocomplete:!0,height:500,maxsplitsize:1e3,markedOptions:{gfm:!0,tables:!0,breaks:!0,pedantic:!0,sanitize:!1,smartLists:!0,smartypants:!1,langPrefix:"lang-"},codemirror:{mode:"htmlmixed",tabMode:"indent",tabsize:4,lineWrapping:!0,dragDrop:!1,autoCloseTags:!0,matchTags:!0,autoCloseBrackets:!0,matchBrackets:!0,indentUnit:4,hintOptions:{completionSingle:!1}},toolbar:["bold","italic","strike","link","image","blockquote","listUl","listOl"],lblPreview:"Preview",lblCodeview:"HTML",lblMarkedview:"Markdown"},init:function(){var d=this,e=b.components.htmleditor.template;this.CodeMirror=this.options.CodeMirror||CodeMirror,this.buttons={},e=e.replace(/\{:lblPreview\}/g,this.options.lblPreview),e=e.replace(/\{:lblCodeview\}/g,this.options.lblCodeview),this.htmleditor=a(e),this.content=this.htmleditor.find(".uk-htmleditor-content"),this.toolbar=this.htmleditor.find(".uk-htmleditor-toolbar"),this.preview=this.htmleditor.find(".uk-htmleditor-preview").children().eq(0),this.code=this.htmleditor.find(".uk-htmleditor-code"),this.element.before(this.htmleditor).appendTo(this.code),this.editor=this.CodeMirror.fromTextArea(this.element[0],this.options.codemirror),this.editor.htmleditor=this,this.editor.on("change",b.Utils.debounce(function(){d.render()},150)),this.editor.on("change",function(){d.editor.save()}),this.code.find(".CodeMirror").css("height",this.options.height),a(window).on("resize",b.Utils.debounce(function(){d.fit()},200));var f=d.preview.parent(),g=this.code.find(".CodeMirror-sizer"),h=this.code.find(".CodeMirror-scroll").on("scroll",b.Utils.debounce(function(){if("tab"!=d.htmleditor.attr("data-mode")){var a=g.height()-h.height(),b=f[0].scrollHeight-f.height(),c=b/a,e=h.scrollTop()*c;f.scrollTop(e)}},10));this.htmleditor.on("click",".uk-htmleditor-button-code, .uk-htmleditor-button-preview",function(b){b.preventDefault(),"tab"==d.htmleditor.attr("data-mode")&&(d.htmleditor.find(".uk-htmleditor-button-code, .uk-htmleditor-button-preview").removeClass("uk-active").filter(this).addClass("uk-active"),d.activetab=a(this).hasClass("uk-htmleditor-button-code")?"code":"preview",d.htmleditor.attr("data-active-tab",d.activetab),d.editor.refresh())}),this.htmleditor.on("click","a[data-htmleditor-button]",function(){d.code.is(":visible")&&d.trigger("action."+a(this).data("htmleditor-button"),[d.editor])}),this.preview.parent().css("height",this.code.height()),this.options.autocomplete&&this.CodeMirror.showHint&&this.CodeMirror.hint&&this.CodeMirror.hint.html&&this.editor.on("inputRead",b.Utils.debounce(function(){var a=d.editor.getDoc(),b=a.getCursor(),c=d.CodeMirror.innerMode(d.editor.getMode(),d.editor.getTokenAt(b).state).mode.name;if("xml"==c){var e=d.editor.getCursor(),f=d.editor.getTokenAt(e);("<"==f.string.charAt(0)||"attribute"==f.type)&&d.CodeMirror.showHint(d.editor,d.CodeMirror.hint.html,{completeSingle:!1})}},100)),this.debouncedRedraw=b.Utils.debounce(function(){d.redraw()},5),this.on("init",function(){d.redraw()}),c.push(this)},addButton:function(a,b){this.buttons[a]=b},addButtons:function(b){a.extend(this.buttons,b)},replaceInPreview:function(a,b){function c(a){var b=d.getValue().substring(0,a).split("\n");return{line:b.length-1,ch:b[b.length-1].length}}var d=this.editor,e=[],f=d.getValue(),g=-1;return this.currentvalue=this.currentvalue.replace(a,function(){g=f.indexOf(arguments[0],++g);var a={matches:arguments,from:c(g),to:c(g+arguments[0].length),replace:function(b){d.replaceRange(b,a.from,a.to)},inRange:function(b){return b.line===a.from.line&&b.line===a.to.line?b.ch>=a.from.ch&&b.ch<a.to.ch:b.line===a.from.line&&b.ch>=a.from.ch||b.line>a.from.line&&b.line<a.to.line||b.line===a.to.line&&b.ch<a.to.ch}},h=b(a);return 0==h?arguments[0]:(e.push(a),h)}),e},_buildtoolbar:function(){if(this.options.toolbar&&this.options.toolbar.length){var a=this,b=[];this.toolbar.empty(),this.options.toolbar.forEach(function(c){if(a.buttons[c]){var d=a.buttons[c].title?a.buttons[c].title:c;b.push('<li><a data-htmleditor-button="'+c+'" title="'+d+'" data-uk-tooltip>'+a.buttons[c].label+"</a></li>")}}),this.toolbar.html(b.join("\n"))}},fit:function(){var a=this.options.mode;"split"==a&&this.htmleditor.width()<this.options.maxsplitsize&&(a="tab"),"tab"==a&&(this.activetab||(this.activetab="code",this.htmleditor.attr("data-active-tab",this.activetab)),this.htmleditor.find(".uk-htmleditor-button-code, .uk-htmleditor-button-preview").removeClass("uk-active").filter("code"==this.activetab?".uk-htmleditor-button-code":".uk-htmleditor-button-preview").addClass("uk-active")),this.editor.refresh(),this.preview.parent().css("height",this.code.height()),this.htmleditor.attr("data-mode",a)},redraw:function(){this._buildtoolbar(),this.render(),this.fit()},getMode:function(){return this.editor.getOption("mode")},getCursorMode:function(){var a={mode:"html"};return this.trigger("cursorMode",[a]),a.mode},render:function(){return this.currentvalue=this.editor.getValue(),this.currentvalue?(this.trigger("render",[this]),this.trigger("renderLate",[this]),void this.preview.html(this.currentvalue)):(this.element.val(""),void this.preview.html(""))},addShortcut:function(b,c){var d={};return a.isArray(b)||(b=[b]),b.forEach(function(a){d[a]=c}),this.editor.addKeyMap(d),d},addShortcutAction:function(a,b){var c=this;this.addShortcut(b,function(){c.element.trigger("action."+a,[c.editor])})},replaceSelection:function(a){var b=this.editor.getSelection();if(!b.length){for(var c=this.editor.getCursor(),d=this.editor.getLine(c.line),e=c.ch,f=e;f<d.length&&/[\w$]+/.test(d.charAt(f));)++f;for(;e&&/[\w$]+/.test(d.charAt(e-1));)--e;var g=e!=f&&d.slice(e,f);g&&(this.editor.setSelection({line:c.line,ch:e},{line:c.line,ch:f}),b=g)}var h=a.replace("$1",b);this.editor.replaceSelection(h,"end"),this.editor.focus()},replaceLine:function(a){var b=this.editor.getDoc().getCursor(),c=this.editor.getLine(b.line),d=a.replace("$1",c);this.editor.replaceRange(d,{line:b.line,ch:0},{line:b.line,ch:c.length}),this.editor.setCursor({line:b.line,ch:d.length}),this.editor.focus()},save:function(){this.editor.save()}}),b.components.htmleditor.template=['<div class="uk-htmleditor uk-clearfix" data-mode="split">','<div class="uk-htmleditor-navbar">','<ul class="uk-htmleditor-navbar-nav uk-htmleditor-toolbar"></ul>','<div class="uk-htmleditor-navbar-flip">','<ul class="uk-htmleditor-navbar-nav">','<li class="uk-htmleditor-button-code"><a>{:lblCodeview}</a></li>','<li class="uk-htmleditor-button-preview"><a>{:lblPreview}</a></li>','<li><a data-htmleditor-button="fullscreen"><i class="uk-icon-expand"></i></a></li>',"</ul>","</div>","</div>",'<div class="uk-htmleditor-content">','<div class="uk-htmleditor-code"></div>','<div class="uk-htmleditor-preview"><div></div></div>',"</div>","</div>"].join(""),b.plugin("htmleditor","base",{init:function(a){function b(b,c,d){a.on("action."+b,function(){"html"==a.getCursorMode()&&a["replaceLine"==d?"replaceLine":"replaceSelection"](c)})}a.addButtons({fullscreen:{title:"Fullscreen",label:'<i class="uk-icon-expand"></i>'},bold:{title:"Bold",label:'<i class="uk-icon-bold"></i>'},italic:{title:"Italic",label:'<i class="uk-icon-italic"></i>'},strike:{title:"Strikethrough",label:'<i class="uk-icon-strikethrough"></i>'},blockquote:{title:"Blockquote",label:'<i class="uk-icon-quote-right"></i>'},link:{title:"Link",label:'<i class="uk-icon-link"></i>'},image:{title:"Image",label:'<i class="uk-icon-picture-o"></i>'},listUl:{title:"Unordered List",label:'<i class="uk-icon-list-ul"></i>'},listOl:{title:"Ordered List",label:'<i class="uk-icon-list-ol"></i>'}}),b("bold","<strong>$1</strong>"),b("italic","<em>$1</em>"),b("strike","<del>$1</del>"),b("blockquote","<blockquote><p>$1</p></blockquote>","replaceLine"),b("link",'<a href="http://">$1</a>'),b("image",'<img src="http://" alt="$1">');var c=function(){if("html"==a.getCursorMode()){for(var b=a.editor,c=b.getDoc().getCursor(!0),d=b.getDoc().getCursor(!1),e=c.line;e<d.line+1;e++)b.replaceRange("<li>"+b.getLine(e)+"</li>",{line:e,ch:0},{line:e,ch:b.getLine(e).length});b.setCursor({line:d.line,ch:b.getLine(d.line).length}),b.focus()}};a.on("action.listUl",function(){c()}),a.on("action.listOl",function(){c()}),a.htmleditor.on("click",'a[data-htmleditor-button="fullscreen"]',function(){a.htmleditor.toggleClass("uk-htmleditor-fullscreen");var b=a.editor.getWrapperElement();if(a.htmleditor.hasClass("uk-htmleditor-fullscreen"))a.editor.state.fullScreenRestore={scrollTop:window.pageYOffset,scrollLeft:window.pageXOffset,width:b.style.width,height:b.style.height},b.style.width="",b.style.height=a.content.height()+"px",document.documentElement.style.overflow="hidden";else{document.documentElement.style.overflow="";var c=a.editor.state.fullScreenRestore;b.style.width=c.width,b.style.height=c.height,window.scrollTo(c.scrollLeft,c.scrollTop)}setTimeout(function(){a.fit()},10)}),a.addShortcut(["Ctrl-S","Cmd-S"],function(){a.element.trigger("htmleditor-save",[a])}),a.addShortcutAction("bold",["Ctrl-B","Cmd-B"])}}),b.plugin("htmleditor","markdown",{init:function(b){function c(){b.editor.setOption("mode","gfm"),b.htmleditor.find(".uk-htmleditor-button-code a").html(b.options.lblMarkedview)}function d(a,c,d){b.on("action."+a,function(){"markdown"==b.getCursorMode()&&b["replaceLine"==d?"replaceLine":"replaceSelection"](c)})}var e=b.options.marked||marked;e&&(e.setOptions(b.options.markedOptions),b.options.markdown&&c(),d("bold","**$1**"),d("italic","*$1*"),d("strike","~~$1~~"),d("blockquote","> $1","replaceLine"),d("link","[$1](http://)"),d("image","![$1](http://)"),b.on("action.listUl",function(){if("markdown"==b.getCursorMode()){for(var a=b.editor,c=a.getDoc().getCursor(!0),d=a.getDoc().getCursor(!1),e=c.line;e<d.line+1;e++)a.replaceRange("* "+a.getLine(e),{line:e,ch:0},{line:e,ch:a.getLine(e).length});a.setCursor({line:d.line,ch:a.getLine(d.line).length}),a.focus()}}),b.on("action.listOl",function(){if("markdown"==b.getCursorMode()){var a=b.editor,c=a.getDoc().getCursor(!0),d=a.getDoc().getCursor(!1),e=1;if(c.line>0){var f,g=a.getLine(c.line-1);(f=g.match(/^(\d+)\./))&&(e=Number(f[1])+1)}for(var h=c.line;h<d.line+1;h++)a.replaceRange(e+". "+a.getLine(h),{line:h,ch:0},{line:h,ch:a.getLine(h).length}),e++;a.setCursor({line:d.line,ch:a.getLine(d.line).length}),a.focus()}}),b.on("renderLate",function(){"gfm"==b.editor.options.mode&&(b.currentvalue=e(b.currentvalue))}),b.on("cursorMode",function(a,c){if("gfm"==b.editor.options.mode){var d=b.editor.getDoc().getCursor();b.editor.getTokenAt(d).state.base.htmlState||(c.mode="markdown")}}),a.extend(b,{enableMarkdown:function(){c(),this.render()},disableMarkdown:function(){this.editor.setOption("mode","htmlmixed"),this.htmleditor.find(".uk-htmleditor-button-code a").html(this.options.lblCodeview),this.render()}}),b.on({enableMarkdown:function(){b.enableMarkdown()},disableMarkdown:function(){b.disableMarkdown()}}))}}),a(function(){a("textarea[data-uk-htmleditor]").each(function(){var c,d=a(this);d.data("htmleditor")||(c=b.htmleditor(d,b.Utils.options(d.attr("data-uk-htmleditor"))))})}),a(document).on("uk-check-display",function(){c.forEach(function(a){a.htmleditor.is(":visible")&&a.fit()})}),b.htmleditor});