return {
init: function() {
- // tooltips are handled on our own
- this.button.buildButtonTooltip = function () {};
-
- var mpClickCallback = this.button.clickCallback;
- this.button.clickCallback = (function(e, callback, btnName, args) {
- // prevent the browser from breaking the editor focus
- if (typeof e.preventDefault === 'function') {
- e.preventDefault();
- }
-
- //noinspection JSUnresolvedFunction
- mpClickCallback.call(this, e, callback, btnName, args);
- }).bind(this);
-
// add custom buttons
var button, buttonName, i, length;
//noinspection JSUnresolvedVariable
this.button.addCallback(button, this.WoltLabButton._handleCustomButton);
}
+ var toolbar = this.core.toolbar()[0];
+
// set button icons and labels
var buttonData, icon, iconIsImage;
for (i = 0, length = this.opts.buttons.length; i < length; i++) {
}
icon = buttonData.icon;
- iconIsImage = false;
- if (!icon.match(/^fa-/) && icon.match(/\.(gif|jpe?g|png|svg)$/)) {
- iconIsImage = true;
- }
+ iconIsImage = (!icon.match(/^fa-/) && icon.match(/\.(gif|jpe?g|png|svg)$/));
// set icon
//noinspection CssUnknownTarget
// set title
//noinspection JSUnresolvedVariable
- elAttr(button[0], 'title', buttonData.title);
+ button[0].title = buttonData.title;
button[0].classList.add('jsTooltip');
// update dropdown label for list
}
}
- var toolbar = this.core.toolbar()[0];
- elBySelAll('.re-button-tooltip', toolbar.parentNode, elRemove);
-
// enforce button order as provided with `opts.buttons`
var listItem, toolbarButtons = {}, toolbarOrder = [];
while (toolbar.childElementCount) {
}).bind(this));
// prevent drag & drop of toolbar buttons
- this.$toolbar[0].addEventListener('dragstart', function (event) {
+ toolbar.addEventListener('dragstart', function (event) {
event.preventDefault();
});
-(function($)
-{
- $.Redactor.prototype.source = function()
- {
+(function ($) {
+ $.Redactor.prototype.source = function () {
return {
- init: function()
- {
+ init: function () {
var button = this.button.addFirst('html', 'HTML');
this.button.addCallback(button, this.source.toggle);
-
+
var style = {
'width': '100%',
'margin': '0',
'line-height': '22px',
'font-family': 'Menlo, Monaco, Consolas, "Courier New", monospace'
};
-
+
this.source.$textarea = $('<textarea />');
this.source.$textarea.css(style).hide();
-
- if (this.opts.type === 'textarea')
- {
+
+ if (this.opts.type === 'textarea') {
this.core.box().append(this.source.$textarea);
}
- else
- {
+ else {
this.core.box().after(this.source.$textarea);
}
-
- this.core.element().on('destroy.callback.redactor', $.proxy(function()
- {
+
+ this.core.element().on('destroy.callback.redactor', $.proxy(function () {
this.source.$textarea.remove();
-
+
}, this));
-
+
},
- toggle: function()
- {
+ toggle: function () {
return (this.source.$textarea.hasClass('open')) ? this.source.hide() : this.source.show();
},
- setCaretOnShow: function()
- {
- this.source.offset = this.offset.get();
- var scroll = $(window).scrollTop();
-
- var width = this.core.editor().innerWidth();
- var height = this.core.editor().innerHeight();
-
- // caret position sync
- this.source.start = 0;
- this.source.end = 0;
- var $editorDiv = $("<div/>").append($.parseHTML(this.core.editor().html(), document, true));
- var $selectionMarkers = $editorDiv.find("span.redactor-selection-marker");
-
- if ($selectionMarkers.length > 0)
- {
- var editorHtml = $editorDiv.html().replace(/&/g, '&');
-
- if ($selectionMarkers.length === 1)
- {
- this.source.start = this.utils.strpos(editorHtml, $editorDiv.find("#selection-marker-1").prop("outerHTML"));
- this.source.end = this.source.start;
- }
- else if ($selectionMarkers.length === 2)
- {
- this.source.start = this.utils.strpos(editorHtml, $editorDiv.find("#selection-marker-1").prop("outerHTML"));
- this.source.end = this.utils.strpos(editorHtml, $editorDiv.find("#selection-marker-2").prop("outerHTML")) - $editorDiv.find("#selection-marker-1").prop("outerHTML").toString().length;
- }
- }
-
- },
- setCaretOnHide: function(html)
- {
- this.source.start = this.source.$textarea.get(0).selectionStart;
- this.source.end = this.source.$textarea.get(0).selectionEnd;
-
- // if selection starts from end
- if (this.source.start > this.source.end && this.source.end > 0)
- {
- var tempStart = this.source.end;
- var tempEnd = this.source.start;
-
- this.source.start = tempStart;
- this.source.end = tempEnd;
- }
-
- this.source.start = this.source.enlargeOffset(html, this.source.start);
- this.source.end = this.source.enlargeOffset(html, this.source.end);
-
- html = html.substr(0, this.source.start) + this.marker.html(1) + html.substr(this.source.start);
-
- if (this.source.end > this.source.start)
- {
- var markerLength = this.marker.html(1).toString().length;
-
- html = html.substr(0, this.source.end + markerLength) + this.marker.html(2) + html.substr(this.source.end + markerLength);
- }
-
- return html;
-
- },
- hide: function()
- {
+ setCaretOnShow: function () {},
+ setCaretOnHide: function (html) { return html; },
+ hide: function () {
this.source.$textarea.removeClass('open').hide();
this.source.$textarea.off('.redactor-source');
-
+
var code = this.source.$textarea.val();
-
+
code = this.paragraphize.load(code);
- code = this.source.setCaretOnHide(code);
-
+
this.code.start(code);
this.button.enableAll();
this.core.editor().show().focus();
this.selection.restore();
this.code.sync();
},
- show: function()
- {
+ show: function () {
this.selection.save();
- this.source.setCaretOnShow();
-
+
var height = this.core.editor().innerHeight();
var code = this.code.get();
- code = code.replace(/\n\n\n/g, "\n");
- code = code.replace(/\n\n/g, "\n");
-
+ code = code.replace(/\n\n\n/g, '\n');
+ code = code.replace(/\n\n/g, '\n');
+
this.core.editor().hide();
this.button.disableAll('html');
this.source.$textarea.val(code).height(height).addClass('open').show();
- this.source.$textarea.on('keyup.redactor-source', $.proxy(function()
- {
- if (this.opts.type === 'textarea')
- {
+ this.source.$textarea.on('keyup.redactor-source', $.proxy(function () {
+ if (this.opts.type === 'textarea') {
this.core.textarea().val(this.source.$textarea.val());
}
-
+
}, this));
-
+
this.marker.remove();
-
+
$(window).scrollTop(scroll);
-
- if (this.source.$textarea[0].setSelectionRange)
- {
+
+ if (this.source.$textarea[0].setSelectionRange) {
this.source.$textarea[0].setSelectionRange(this.source.start, this.source.end);
}
-
+
this.source.$textarea[0].scrollTop = 0;
-
- setTimeout($.proxy(function()
- {
+
+ setTimeout($.proxy(function () {
this.source.$textarea.focus();
-
+ this.button.setActive('html');
}, this), 0);
},
- enlargeOffset: function(html, offset)
- {
- var htmlLength = html.length;
- var c = 0;
-
- if (html[offset] === '>')
- {
- c++;
- }
- else
- {
- for(var i = offset; i <= htmlLength; i++)
- {
- c++;
-
- if (html[i] === '>')
- {
- break;
- }
- else if (html[i] === '<' || i === htmlLength)
- {
- c = 0;
- break;
- }
- }
- }
-
- return offset + c;
- }
+ enlargeOffset: function () {}
};
};
})(jQuery);
}).bind(this));
elData(button, 'a11y-mouse-event', 'mousedown');
+ elData(button, 'aria-expanded', false);
button.addEventListener('click', function (event) {
event.preventDefault();
clickCallback: function (e, callback, btnName, args) {
var func;
+ if (e instanceof Event) {
+ e.preventDefault();
+ }
+
args = (typeof args === 'undefined') ? btnName : args;
if ($.isFunction(callback)) {
$btns = $btns.not('.re-' + key);
}
- $btns.removeClass('redactor-act');
+ $btns.removeClass('redactor-act').attr({
+ 'aria-pressed': false,
+ tabindex: (key === 'html') ? 0 : -1
+ });
},
disable: function (key) {
- this.button.get(key).addClass('redactor-button-disabled');
+ this.button.get(key).addClass('redactor-button-disabled').attr('aria-disabled', true);
},
enable: function (key) {
- this.button.get(key).removeClass('redactor-button-disabled');
+ this.button.get(key).removeClass('redactor-button-disabled').attr('aria-disabled', false);
},
disableAll: function (key) {
var $btns = this.button.toolbar().find('a.re-button');
$btns = $btns.not('.re-' + key);
}
- $btns.addClass('redactor-button-disabled');
+ $btns.addClass('redactor-button-disabled').attr('aria-disabled', true);
},
enableAll: function () {
- this.button.toolbar().find('a.re-button').removeClass('redactor-button-disabled');
+ this.button.toolbar().find('a.re-button').removeClass('redactor-button-disabled').attr('aria-disabled', false);
},
remove: function (key) {
this.button.get(key).remove();
});
this.button.setActive(this.dropdown.key);
- this.dropdown.button.addClass('dropact');
+ this.dropdown.button.addClass('dropact').attr('aria-expanded', true);
this.dropdown.enableCallback();
}
UiSimpleDropdown.close(id);
});
- this.dropdown.button.removeClass('redactor-act dropact');
+ this.dropdown.button.removeClass('redactor-act dropact').attr('aria-expanded', false);
this.dropdown.button = false;
this.dropdown.key = false;
this.dropdown.active = false;