summaryrefslogtreecommitdiff
path: root/js/loadsceditor.js
blob: 08511526561568d5ed02bf0d907eeb8173780c64 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
if (active_page === "thread" || active_page === "index" ||  active_page === "ukko") {

$(document).on("ready", function() {
if (window.Options && Options.get_tab('general')) {
	Options.extend_tab("general", 
	"<fieldset><legend>Editor Dialog </legend>"
	+ ("<label class='sceditorc' id='sceditor'><input type='checkbox' /> Enable SCEditor WYSIWYG Editor</label>")
	+ "</fieldset>");
}

$('.sceditorc').on('change', function(){
	var setting = $(this).attr('id');

	localStorage[setting] = $(this).children('input').is(':checked');
	location.reload();
});

if (!localStorage.sceditor) {
	localStorage.sceditor = 'false';
}

function getSetting(key) {
	return (localStorage[key] == 'true');
}

if (getSetting('sceditor')) $('#sceditor>input').prop('checked', 'checked');

function initsceditor() { 
	if (!getSetting("sceditor")) {return;}
	$('.format-text').toggle();		
		
	$.sceditor.plugins.bbcode.bbcode.set('spoiler', {
		    tags: {
			            'span': {
					                'class': ['spoiler']
								        }
				        },
		    format: '[spoiler]{0}[/spoiler]',
			        html: '<span class="spoiler">{0}</span>'
	});
	$.sceditor.plugins.bbcode.bbcode.set('t', {
		    tags: {
			            'span': {
					                'class': ['heading']
								        }
				        },
		    format: '\t=={0}==\t',
			        html: '<span class="heading">{0}</span>'
	});
	$.sceditor.command.set("spoiler", {
	    exec: function() {
    	    this.insert("[spoiler]", "[/spoiler]");
			},
	    txtExec: ["[spoiler]", "[/spoiler]"],
	    tooltip: "Spoiler (CTRL+S)",
	});
	$.sceditor.command.set("t", {
	    exec: function() {
    	    this.insert("\t==", "==\t");
			},
	    txtExec: ["\t==", "==\t"],
	    tooltip: "Heading (CTRL+T)",
        });
	$('#body').sceditor({
	  plugins: 'bbcode',
	  style: $('#stylesheet').attr("href"), 
	  //style: '/stylesheets/sceditor/jquery.sceditor.default.min.css',
          toolbar: "bold,italic,t,spoiler,code|source",
	  emoticonsEnabled : false,
          autoUpdate : true,
	});
	var backgroundcolor = $('#body').css('background-color');
	$('.sceditor-container').css('background-color',backgroundcolor);
	$('.sceditor-toolbar').css('background-color',backgroundcolor);
	$('#body').sceditor('instance').css('body { background-color: ' + backgroundcolor +'; }');
	
	/*$(document).on('ajax_before_post', function (e, formData) {
		formData.set(body, $("#body").sceditor('instance').val());
	});

	$(document).on('ajax_after_post', function () {
		$("#body").sceditor('instance').val("");
	});*/
}
initsceditor();
});
}