summaryrefslogtreecommitdiff
path: root/js/sceditor/development/plugins/format.js
diff options
context:
space:
mode:
authorBenjamin Southall <applemansigloo@gmail.com>2017-09-03 23:15:56 +0900
committerBenjamin Southall <applemansigloo@gmail.com>2017-09-03 23:15:56 +0900
commit9e2f9f49ec9803adfa0249161c8d2188ee0d40ca (patch)
treeee04586a6ce84ebd0929fa5f3fac69394868e306 /js/sceditor/development/plugins/format.js
parentf68e130bfe8690b174cc915e9f18335ef296e2d3 (diff)
Add sceditor WYSIWIG post editor support
Diffstat (limited to 'js/sceditor/development/plugins/format.js')
-rw-r--r--js/sceditor/development/plugins/format.js127
1 files changed, 127 insertions, 0 deletions
diff --git a/js/sceditor/development/plugins/format.js b/js/sceditor/development/plugins/format.js
new file mode 100644
index 00000000..15129957
--- /dev/null
+++ b/js/sceditor/development/plugins/format.js
@@ -0,0 +1,127 @@
+/**
+ * SCEditor Paragraph Formatting Plugin
+ * http://www.sceditor.com/
+ *
+ * Copyright (C) 2011-2013, Sam Clarke (samclarke.com)
+ *
+ * SCEditor is licensed under the MIT license:
+ * http://www.opensource.org/licenses/mit-license.php
+ *
+ * @fileoverview SCEditor Paragraph Formatting Plugin
+ * @author Sam Clarke
+ * @requires jQuery
+ */
+(function ($) {
+ 'use strict';
+
+ $.sceditor.plugins.format = function () {
+ var base = this;
+
+ /**
+ * Default tags
+ * @type {Object}
+ * @private
+ */
+ var tags = {
+ p: 'Paragraph',
+ h1: 'Heading 1',
+ h2: 'Heading 2',
+ h3: 'Heading 3',
+ h4: 'Heading 4',
+ h5: 'Heading 5',
+ h6: 'Heading 6',
+ address: 'Address',
+ pre: 'Preformatted Text'
+ };
+
+ /**
+ * Private functions
+ * @private
+ */
+ var insertTag,
+ formatCmd;
+
+
+ base.init = function () {
+ var opts = this.opts,
+ pOpts = opts.paragraphformat;
+
+ // Don't enable if the BBCode plugin is enabled.
+ if (opts.plugins && opts.plugins.indexOf('bbcode') > -1) {
+ return;
+ }
+
+ if (pOpts) {
+ if (pOpts.tags) {
+ tags = pOpts.tags;
+ }
+
+ if (pOpts.excludeTags) {
+ $.each(pOpts.excludeTags, function (idx, val) {
+ delete tags[val];
+ });
+ }
+ }
+
+ if (!this.commands.format) {
+ this.commands.format = {
+ exec: formatCmd,
+ txtExec: formatCmd,
+ tooltip: 'Format Paragraph'
+ };
+ }
+
+ if (opts.toolbar === $.sceditor.defaultOptions.toolbar) {
+ opts.toolbar = opts.toolbar.replace(',color,',
+ ',color,format,');
+ }
+ };
+
+ /**
+ * Inserts the specified tag into the editor
+ *
+ * @param {sceditor} editor
+ * @param {string} tag
+ * @private
+ */
+ insertTag = function (editor, tag) {
+ if (editor.sourceMode()) {
+ editor.insert('<' + tag + '>', '</' + tag + '>');
+ } else {
+ editor.execCommand('formatblock', '<' + tag + '>');
+ }
+
+ };
+
+ /**
+ * Function for the exec and txtExec properties
+ *
+ * @param {node} caller
+ * @private
+ */
+ formatCmd = function (caller) {
+ var editor = this,
+ $content = $('<div />');
+
+ $.each(tags, function (tag, val) {
+ $(
+ '<a class="sceditor-option" href="#">' +
+ (val.name || val) + '</a>'
+ ).click(function () {
+ editor.closeDropDown(true);
+
+ if (val.exec) {
+ val.exec(editor);
+ } else {
+ insertTag(editor, tag);
+ }
+
+ return false;
+ })
+ .appendTo($content);
+ });
+
+ editor.createDropDown(caller, 'format', $content);
+ };
+ };
+})(jQuery);