uikit-sass-rails 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/CHANGELOG.md +5 -0
- data/LICENSE.md +155 -0
- data/README.md +78 -0
- data/lib/uikit-sass-rails.rb +1 -0
- data/lib/uikit/sass/rails.rb +2 -0
- data/lib/uikit/sass/rails/engine.rb +12 -0
- data/lib/uikit/sass/rails/version.rb +7 -0
- data/uikit-sass-rails.gemspec +24 -0
- data/vendor/assets/fonts/fontawesome-webfont.eot +0 -0
- data/vendor/assets/fonts/fontawesome-webfont.svg +504 -0
- data/vendor/assets/fonts/fontawesome-webfont.ttf +0 -0
- data/vendor/assets/fonts/fontawesome-webfont.woff +0 -0
- data/vendor/assets/javascripts/uikit.js +14 -0
- data/vendor/assets/javascripts/uikit/addons/autocomplete.js +306 -0
- data/vendor/assets/javascripts/uikit/addons/datepicker.js +365 -0
- data/vendor/assets/javascripts/uikit/addons/form-password.js +62 -0
- data/vendor/assets/javascripts/uikit/addons/form-select.js +62 -0
- data/vendor/assets/javascripts/uikit/addons/htmleditor.js +594 -0
- data/vendor/assets/javascripts/uikit/addons/nestable.js +574 -0
- data/vendor/assets/javascripts/uikit/addons/notify.js +177 -0
- data/vendor/assets/javascripts/uikit/addons/pagination.js +146 -0
- data/vendor/assets/javascripts/uikit/addons/search.js +90 -0
- data/vendor/assets/javascripts/uikit/addons/sortable.js +494 -0
- data/vendor/assets/javascripts/uikit/addons/sticky.js +130 -0
- data/vendor/assets/javascripts/uikit/addons/timepicker.js +163 -0
- data/vendor/assets/javascripts/uikit/addons/upload.js +239 -0
- data/vendor/assets/javascripts/uikit/uikit.js +2573 -0
- data/vendor/assets/stylesheets/extra/font-awesome.scss +16 -0
- data/vendor/assets/stylesheets/uikit.scss +5 -0
- data/vendor/assets/stylesheets/uikit/addons/uikit.addons.scss +1326 -0
- data/vendor/assets/stylesheets/uikit/addons/uikit.almost-flat.addons.scss +1423 -0
- data/vendor/assets/stylesheets/uikit/addons/uikit.gradient.addons.scss +1445 -0
- data/vendor/assets/stylesheets/uikit/almost-flat.scss +5 -0
- data/vendor/assets/stylesheets/uikit/gradient.scss +5 -0
- data/vendor/assets/stylesheets/uikit/uikit.almost-flat.scss +8207 -0
- data/vendor/assets/stylesheets/uikit/uikit.gradient.scss +8264 -0
- data/vendor/assets/stylesheets/uikit/uikit.scss +7874 -0
- metadata +100 -0
@@ -0,0 +1,62 @@
|
|
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-form-password", ["uikit"], function(){
|
13
|
+
return component || addon(jQuery, jQuery.UIkit);
|
14
|
+
});
|
15
|
+
}
|
16
|
+
|
17
|
+
})(function($, UI){
|
18
|
+
|
19
|
+
UI.component('formPassword', {
|
20
|
+
|
21
|
+
defaults: {
|
22
|
+
"lblShow": "Show",
|
23
|
+
"lblHide": "Hide"
|
24
|
+
},
|
25
|
+
|
26
|
+
init: function() {
|
27
|
+
|
28
|
+
var $this = this;
|
29
|
+
|
30
|
+
this.on("click", function(e) {
|
31
|
+
|
32
|
+
e.preventDefault();
|
33
|
+
|
34
|
+
if($this.input.length) {
|
35
|
+
var type = $this.input.attr("type");
|
36
|
+
$this.input.attr("type", type=="text" ? "password":"text");
|
37
|
+
$this.element.text($this.options[type=="text" ? "lblShow":"lblHide"]);
|
38
|
+
}
|
39
|
+
});
|
40
|
+
|
41
|
+
this.input = this.element.next("input").length ? this.element.next("input") : this.element.prev("input");
|
42
|
+
this.element.text(this.options[this.input.is("[type='password']") ? "lblShow":"lblHide"]);
|
43
|
+
|
44
|
+
this.element.data("formPassword", this);
|
45
|
+
}
|
46
|
+
});
|
47
|
+
|
48
|
+
// init code
|
49
|
+
$(document).on("click.formpassword.uikit", "[data-uk-form-password]", function(e) {
|
50
|
+
|
51
|
+
var ele = $(this);
|
52
|
+
if (!ele.data("formPassword")) {
|
53
|
+
|
54
|
+
e.preventDefault();
|
55
|
+
|
56
|
+
var obj = UI.formPassword(ele, UI.Utils.options(ele.attr("data-uk-form-password")));
|
57
|
+
ele.trigger("click");
|
58
|
+
}
|
59
|
+
});
|
60
|
+
|
61
|
+
return UI.formPassword;
|
62
|
+
});
|
@@ -0,0 +1,62 @@
|
|
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-form-select", ["uikit"], function(){
|
13
|
+
return component || addon(jQuery, jQuery.UIkit);
|
14
|
+
});
|
15
|
+
}
|
16
|
+
|
17
|
+
})(function($, UI){
|
18
|
+
|
19
|
+
UI.component('formSelect', {
|
20
|
+
defaults: {
|
21
|
+
'target': '>span:first'
|
22
|
+
},
|
23
|
+
|
24
|
+
init: function() {
|
25
|
+
var $this = this;
|
26
|
+
|
27
|
+
this.target = this.find(this.options.target);
|
28
|
+
this.select = this.find('select');
|
29
|
+
|
30
|
+
// init + on change event
|
31
|
+
this.select.on("change", (function(){
|
32
|
+
|
33
|
+
var select = $this.select[0], fn = function(){
|
34
|
+
|
35
|
+
try {
|
36
|
+
$this.target.text(select.options[select.selectedIndex].text);
|
37
|
+
} catch(e) {}
|
38
|
+
|
39
|
+
return fn;
|
40
|
+
};
|
41
|
+
|
42
|
+
return fn();
|
43
|
+
})());
|
44
|
+
|
45
|
+
this.element.data("formSelect", this);
|
46
|
+
}
|
47
|
+
});
|
48
|
+
|
49
|
+
// init code
|
50
|
+
$(document).on("uk-domready", function(e) {
|
51
|
+
|
52
|
+
$("[data-uk-form-select]").each(function(){
|
53
|
+
var ele = $(this);
|
54
|
+
|
55
|
+
if (!ele.data("formSelect")) {
|
56
|
+
var obj = UI.formSelect(ele, UI.Utils.options(ele.attr("data-uk-form-select")));
|
57
|
+
}
|
58
|
+
});
|
59
|
+
});
|
60
|
+
|
61
|
+
return UI.formSelect;
|
62
|
+
});
|
@@ -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
|
+
});
|