/**
* Simple Machines Forum (SMF)
*
* @package SMF
* @author Simple Machines
* @copyright 2013 Simple Machines and individual contributors
* @license http://www.simplemachines.org/about/smf/license.php BSD
*
* @version 2.1 Alpha 1
*/
(function($) {
var extensionMethods = {
InsertText: function(text, bClear) {
var bIsSource = this.inSourceMode();
// @TODO make it put the quote close to the current selection
if (!bIsSource)
this.toggleSourceMode();
var current_value = bClear ? text + "\n" : this.getSourceEditorValue(false) + "\n" + text + "\n";
this.setSourceEditorValue(current_value);
if (!bIsSource)
this.toggleSourceMode();
},
getText: function(filter) {
var current_value = '';
if(this.inSourceMode())
current_value = this.getSourceEditorValue(false);
else
current_value = this.getWysiwygEditorValue(filter);
return current_value;
},
appendEmoticon: function (code, emoticon) {
if (emoticon == '')
line.append($('
'));
else
line.append($('')
.attr({
src: emoticon,
alt: code,
})
.click(function (e) {
var start = '', end = '';
if (base.opts.emoticonsCompat)
{
start = ' ';
end = ' ';
}
if (base.inSourceMode())
base.sourceEditorInsertText(' ' + $(this).attr('alt') + ' ');
else
base.wysiwygEditorInsertHtml(start + '' + end);
e.preventDefault();
})
);
if (line.children().length > 0)
content.append(line);
$(".sceditor-toolbar").append(content);
},
storeLastState: function (){
this.wasSource = this.inSourceMode();
},
setTextMode: function () {
if (!this.inSourceMode())
this.toggleSourceMode();
},
createPermanentDropDown: function() {
var emoticons = $.extend({}, this.opts.emoticons.dropdown);
var popup_exists = false;
content = $('
', ''); } } ); $.sceditor.command.set( 'move', { tooltip: 'Marquee', txtExec: ["[move]", "[/move]"], exec: function () { this.wysiwygEditorInsertHtml(''); } } ); $.sceditor.command.set( 'email', { txtExec: function(caller, selected) { var display = selected && selected.indexOf('@') > -1 ? null : selected, email = prompt(this._("Enter the e-mail address:"), (display ? '' : selected)); if (email) { var text = prompt(this._("Enter the displayed text:"), display || email) || email; this.insertText("[email=" + email + "]" + text + "[/email]"); } } } ); $.sceditor.command.set( 'link', { txtExec: function(caller, selected) { var display = selected && selected.indexOf('http://') > -1 ? null : selected, url = prompt(this._("Enter URL:"), (display ? 'http://' : selected)); if (url) { var text = prompt(this._("Enter the displayed text:"), display || url) || url; this.insertText("[url=" + url + "]" + text + "[/url]"); } } } ); $.sceditor.command.set( 'bulletlist', { txtExec: ["[list]\n[li]", "[/li]\n[li][/li]\n[/list]"] } ); $.sceditor.command.set( 'orderedlist', { txtExec: ["[list type=decimal]\n[li]", "[/li]\n[li][/li]\n[/list]"] } ); $.sceditor.command.set( 'table', { txtExec: ["[table]\n[tr]\n[td]", "[/td]\n[/tr]\n[/table]"] } ); $.sceditorBBCodePlugin.bbcode.set( 'abbr', { tags: { abbr: { title: null } }, format: function(element, content) { return '[abbr=' + element.attr('title') + ']' + content + '[/abbr]'; }, html: function(element, attrs, content) { if(typeof attrs.defaultattr === "undefined" || attrs.defaultattr.length === 0) return content; return '' + content + ''; } } ); $.sceditorBBCodePlugin.bbcode.set( 'acronym', { tags: { acronym: { title: null } }, format: function(element, content) { return '[abbr=' + element.attr('title') + ']' + content + '[/abbr]'; }, html: function(element, attrs, content) { if(typeof attrs.defaultattr === "undefined" || attrs.defaultattr.length === 0) return content; return '' + content + ''; } } ); $.sceditorBBCodePlugin.bbcode.set( 'bdo', { tags: { bdo: { dir: null } }, format: function(element, content) { return '[bdo=' + element.attr('dir') + ']' + content + '[/bdo]'; }, html: function(element, attrs, content) { if(typeof attrs.defaultattr === "undefined" || attrs.defaultattr.length === 0) return content; if (attrs.defaultattr != 'rtl' && attrs.defaultattr != 'ltr') return '[bdo=' + attrs.defaultattr + ']' + content + '[/bdo]'; return '' + content + ''; } } ); $.sceditorBBCodePlugin.bbcode.set( 'black', { html: '{0}' } ); $.sceditorBBCodePlugin.bbcode.set( 'blue', { html: '{0}' } ); $.sceditorBBCodePlugin.bbcode.set( 'green', { html: '{0}' } ); $.sceditorBBCodePlugin.bbcode.set( 'red', { html: '{0}' } ); $.sceditorBBCodePlugin.bbcode.set( 'white', { html: '{0}' } ); $.sceditorBBCodePlugin.bbcode.set( 'list', { breakStart: true, isInline: false, allowedChildren: ['*', 'li'], html: function(element, attrs, content) { var style = ''; var code = 'ul'; if (attrs.type) style = ' style="list-style-type: ' + attrs.type + '"'; return '<' + code + style + '>' + content + '' + code + '>'; } } ); $.sceditorBBCodePlugin.bbcode.set( 'ul', { tags: { ul: null }, breakStart: true, isInline: false, html: '
{0}\n" } ); $.sceditorBBCodePlugin.bbcode.set( 'move', { tags: { marquee: null }, format: "[move]{0}[/move]", html: '' } ); $.sceditorBBCodePlugin.bbcode.set( 'php', { isInline: false, format: "[php]{0}[/php]", html: '
{0}
'
}
);
$.sceditorBBCodePlugin.bbcode.set(
'code', {
tags: {
code: null
},
isInline: false,
allowedChildren: ['#', '#newline'],
format: function(element, content) {
if ($(element[0]).hasClass('php'))
return '[php]' + content.replace('[', '[') + '[/php]';
var from = '';
if ($(element).children("cite:first").length === 1)
{
from = $(element).children("cite:first").text();
$(element).attr({'from': from.php_htmlspecialchars()});
from = '=' + from;
content = '';
$(element).children("cite:first").remove();
content = this.elementToBbcode($(element));
}
else
{
if (typeof $(element).attr('from') != 'undefined')
{
from = '=' + $(element).attr('from').php_unhtmlspecialchars();
}
}
return '[code' + from + ']' + content.replace('[', '[') + '[/code]';
},
html: function(element, attrs, content) {
var from = '';
if(typeof attrs.defaultattr !== "undefined")
from = '' + attrs.defaultattr + '';
return '' + from + content.replace('[', '[') + '
'
}
}
);
$.sceditorBBCodePlugin.bbcode.set(
'quote', {
tags: {
blockquote: null,
cite: null
},
quoteType: $.sceditor.BBCodeParser.QuoteType.never,
breakBefore: false,
isInline: false,
format: function(element, content) {
var author = '';
var date = '';
var link = '';
// The contains only the graphic for the quote, so we can skip it
if(element[0].tagName.toLowerCase() === 'cite')
return '';
if(element.attr('author'))
author = ' author=' + element.attr('author').php_unhtmlspecialchars();
if(element.attr('date'))
date = ' date=' + element.attr('date');
if(element.attr('link'))
link = ' link=' + element.attr('link');
return '[quote' + author + date + link + ']' + content + '[/quote]';
},
html: function(element, attrs, content) {
var attr_author = '', author = '';
var attr_date = '', sDate = '';
var attr_link = '', link = '';
if(typeof attrs.author !== "undefined" && attrs.author)
{
attr_author = attrs.author;
author = bbc_quote_from + ': ' + attr_author;
}
// Links could be in the form: link=topic=71.msg201#msg201 that would fool javascript, so we need a workaround
// Probably no more necessary
for (var key in attrs)
{
if (key.substr(0, 4) == 'link' && attrs.hasOwnProperty(key))
{
var attr_link = key.length > 4 ? key.substr(5) + '=' + attrs[key] : attrs[key];
link = attr_link.substr(0, 7) == 'http://' ? attr_link : smf_scripturl + '?' + attr_link;
author = author == '' ? '' + bbc_quote_from + ': ' + link + '' : '' + author + '';
}
}
if(typeof attrs.date !== "undefined" && attrs.date)
{
attr_date = attrs.date;
sDate = '' + author + ' ' + sDate + '' + content + ''; return content; } } );