1
|
|
|
|
2
|
|
|
var isEditingEnabled; |
3
|
|
|
var widgets = {}; |
4
|
|
|
|
5
|
|
|
function toggleEditor(btn) { |
6
|
|
|
if (!isEditingEnabled) { |
7
|
|
|
$.each($('.fastEdit'), function () { |
8
|
|
|
if ($(this).closest('a').length > 0) { |
9
|
|
|
var a = $(this).closest('a'); |
10
|
|
|
a.replaceWith("<div class = 'historyA " + a.attr('class') + "' style = '" + a.attr('style') + "' href = '" + a.attr('href') + "'>" + a.html() + "</div>"); |
11
|
|
|
} |
12
|
|
|
}); |
13
|
|
|
$.each($('.fastEdit'), function () { |
14
|
|
|
$(this).attr('contenteditable', true); |
15
|
|
|
$(this).css('position', 'relative'); |
16
|
|
|
html = $(this).html(); |
|
|
|
|
17
|
|
|
var regex = /<!--start:(.*)-->([\s\S]*?)<!--end:\1-->/ig; |
18
|
|
|
while (match = regex.exec(html)) { |
|
|
|
|
19
|
|
|
if (match) { |
20
|
|
|
widgets[match[1]] = match[0]; |
21
|
|
|
} |
22
|
|
|
} |
23
|
|
|
$(this).html(html.replace(/<!--start:(.*)-->([\s\S]*?)<!--end:\1-->/ig, '$1')); |
24
|
|
|
|
25
|
|
|
$(this).ckeditor({ |
26
|
|
|
//removePlugins: 'stylescombo', |
27
|
|
|
//startupFocus: true, |
28
|
|
|
customConfig: '/static/moduleAsset/libs/libs/ckeditor/inline_config.js' |
29
|
|
|
}); |
30
|
|
|
|
31
|
|
|
}); |
32
|
|
|
isEditingEnabled = true; |
33
|
|
|
$(btn).text('Отключить редактирование'); |
34
|
|
|
} else { |
35
|
|
|
$.each($('.fastEdit'), function () { |
36
|
|
|
$(this).ckeditor().editor.destroy(); |
37
|
|
|
$(this).removeAttr('contenteditable'); |
38
|
|
|
$(this).css('position', 'static'); |
39
|
|
|
//$(this).attr('class', 'fastEdit'); |
40
|
|
|
for (key in widgets) { |
|
|
|
|
41
|
|
|
$(this).html($(this).html().replace(new RegExp(key, "gm"), widgets[key])); |
42
|
|
|
} |
43
|
|
|
}); |
44
|
|
|
isEditingEnabled = false; |
45
|
|
|
$.each($('.fastEdit'), function () { |
46
|
|
|
if ($(this).closest('.historyA').length > 0) { |
47
|
|
|
var a = $(this).closest('.historyA'); |
48
|
|
|
a.removeClass('historyA'); |
49
|
|
|
a.replaceWith("<a class = '" + a.attr('class') + "' style = '" + a.attr('style') + "' href = '" + a.attr('href') + "'>" + a.html() + "</a>"); |
50
|
|
|
} |
51
|
|
|
}); |
52
|
|
|
$(btn).text('Включить редактирование'); |
53
|
|
|
} |
54
|
|
|
return; |
55
|
|
|
} |
56
|
|
|
$(function () { |
57
|
|
|
$('body').append("<div class ='btn-group' style = 'position:fixed;right:0;top:0;z-index:100000;' ><button onclick='toggleEditor(this);return false;' class ='btn btn-default btn-xs' >Включить редактирование</button></div>"); |
58
|
|
|
}) |
59
|
|
|
|