* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @module WoltLabSuite/Core/Ui/Redactor/Code
*/
-define(['EventHandler', 'EventKey', 'Language', 'StringUtil', 'Dom/Util', 'Ui/Dialog'], function (EventHandler, EventKey, Language, StringUtil, DomUtil, UiDialog) {
+define(['EventHandler', 'EventKey', 'Language', 'StringUtil', 'Dom/Util', 'Ui/Dialog', './PseudoHeader'], function (EventHandler, EventKey, Language, StringUtil, DomUtil, UiDialog, UiRedactorPseudoHeader) {
"use strict";
var _headerHeight = 0;
var pre = event.currentTarget;
if (_headerHeight === 0) {
- _headerHeight = ~~window.getComputedStyle(pre).paddingTop.replace(/px$/, '');
-
- var styles = window.getComputedStyle(pre, '::before');
- _headerHeight += ~~styles.paddingTop.replace(/px$/, '');
- _headerHeight += ~~styles.height.replace(/px$/, '');
- _headerHeight += ~~styles.paddingBottom.replace(/px$/, '');
+ _headerHeight = UiRedactorPseudoHeader.getHeight(pre);
}
// check if the click hit the header
--- /dev/null
+/**
+ * Helper class to deal with clickable block headers using the pseudo
+ * `::before` element.
+ *
+ * @author Alexander Ebert
+ * @copyright 2001-2016 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @module WoltLabSuite/Core/Ui/Redactor/PseudoHeader
+ */
+define([], function() {
+ "use strict";
+
+ return {
+ /**
+ * Returns the height within a click should be treated as a click
+ * within the block element's title. This method expects that the
+ * `::before` element is used and that removing the attribute
+ * `data-title` does cause the title to collapse.
+ *
+ * @param {Element} element block element
+ * @return {int} clickable height spanning from the top border down to the bottom of the title
+ */
+ getHeight: function (element) {
+ var height = ~~window.getComputedStyle(element).paddingTop.replace(/px$/, '');
+
+ var styles = window.getComputedStyle(element, '::before');
+ height += ~~styles.paddingTop.replace(/px$/, '');
+ height += ~~styles.paddingBottom.replace(/px$/, '');
+
+ var titleHeight = ~~styles.height.replace(/px$/, '');
+ if (titleHeight === 0) {
+ // firefox returns garbage for pseudo element height
+ // https://bugzilla.mozilla.org/show_bug.cgi?id=925694#c7
+
+ titleHeight = element.scrollHeight;
+ element.classList.add('redactorCalcHeight');
+ titleHeight -= element.scrollHeight;
+ element.classList.remove('redactorCalcHeight');
+ }
+
+ height += titleHeight;
+
+ return height;
+ }
+ }
+});
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @module WoltLabSuite/Core/Ui/Redactor/Quote
*/
-define(['Core', 'EventHandler', 'EventKey', 'Language', 'StringUtil', 'Dom/Util', 'Ui/Dialog'], function (Core, EventHandler, EventKey, Language, StringUtil, DomUtil, UiDialog) {
+define(['Core', 'EventHandler', 'EventKey', 'Language', 'StringUtil', 'Dom/Util', 'Ui/Dialog', './PseudoHeader'], function (Core, EventHandler, EventKey, Language, StringUtil, DomUtil, UiDialog, UiRedactorPseudoHeader) {
"use strict";
var _headerHeight = 0;
*/
init: function(editor, button) {
this._quote = null;
+ this._quotes = elByTag('woltlab-quote', editor.$editor[0]);
this._editor = editor;
this._elementId = this._editor.$element[0].id;
this._editor.selection.restore();
var content = data.content;
- console.debug(data);
if (data.isText) {
content = StringUtil.escapeHTML(content);
content = '<p>' + content + '</p>';
* @protected
*/
_observeLoad: function() {
- elBySelAll('woltlab-quote', this._editor.$editor[0], (function(quote) {
+ var quote;
+ for (var i = 0, length = this._quotes.length; i < length; i++) {
+ quote = this._quotes[i];
+
quote.addEventListener(WCF_CLICK_EVENT, this._callbackEdit);
this._setTitle(quote);
- }).bind(this));
+ }
},
/**
var quote = event.currentTarget;
if (_headerHeight === 0) {
- _headerHeight = ~~window.getComputedStyle(quote).paddingTop.replace(/px$/, '');
-
- var styles = window.getComputedStyle(quote, '::before');
- _headerHeight += ~~styles.paddingTop.replace(/px$/, '');
- _headerHeight += ~~styles.height.replace(/px$/, '');
- _headerHeight += ~~styles.paddingBottom.replace(/px$/, '');
+ _headerHeight = UiRedactorPseudoHeader.getHeight(quote);
}
// check if the click hit the header
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @module WoltLabSuite/Core/Ui/Redactor/Spoiler
*/
-define(['EventHandler', 'EventKey', 'Language', 'StringUtil', 'Dom/Util', 'Ui/Dialog'], function (EventHandler, EventKey, Language, StringUtil, DomUtil, UiDialog) {
+define(['EventHandler', 'EventKey', 'Language', 'StringUtil', 'Dom/Util', 'Ui/Dialog', './PseudoHeader'], function (EventHandler, EventKey, Language, StringUtil, DomUtil, UiDialog, UiRedactorPseudoHeader) {
"use strict";
var _headerHeight = 0;
var spoiler = event.currentTarget;
if (_headerHeight === 0) {
- _headerHeight = ~~window.getComputedStyle(spoiler).paddingTop.replace(/px$/, '');
-
- var styles = window.getComputedStyle(spoiler, '::before');
- _headerHeight += ~~styles.paddingTop.replace(/px$/, '');
- _headerHeight += ~~styles.height.replace(/px$/, '');
- _headerHeight += ~~styles.paddingBottom.replace(/px$/, '');
+ _headerHeight = UiRedactorPseudoHeader.getHeight(spoiler);
}
// check if the click hit the header
position: relative;
white-space: pre;
- &::before {
+ &:not(.redactorCalcHeight)::before {
content: attr(data-title);
cursor: pointer;
display: block;
}
}
-woltlab-quote::before {
+woltlab-quote:not(.redactorCalcHeight)::before {
content: attr(data-title);
cursor: pointer;
display: block;
padding: 10px 20px;
position: relative;
- &::before {
+ &:not(.redactorCalcHeight)::before {
content: attr(data-title);
cursor: pointer;
display: block;