aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/assets/javascript
diff options
context:
space:
mode:
authorNathan Guse <nathaniel.guse@gmail.com>2013-11-21 13:41:03 -0800
committerNathan Guse <nathaniel.guse@gmail.com>2013-11-21 13:41:03 -0800
commit6f419b0049c5b4ec2bba9fc40a8515a35ced6fb4 (patch)
tree940086df78617fc7d036d631eb5b4eb820e09b7c /phpBB/assets/javascript
parent20885ccb8cef8d497ceacc232d3d864d5c07c455 (diff)
parent97915b467ed2a0f15805b43155eb24ac8b326c35 (diff)
downloadforums-6f419b0049c5b4ec2bba9fc40a8515a35ced6fb4.tar
forums-6f419b0049c5b4ec2bba9fc40a8515a35ced6fb4.tar.gz
forums-6f419b0049c5b4ec2bba9fc40a8515a35ced6fb4.tar.bz2
forums-6f419b0049c5b4ec2bba9fc40a8515a35ced6fb4.tar.xz
forums-6f419b0049c5b4ec2bba9fc40a8515a35ced6fb4.zip
Merge pull request #1869 from prototech/ticket/10810
[ticket/10810] Move color swatches from popup windows to inline blocks.
Diffstat (limited to 'phpBB/assets/javascript')
-rw-r--r--phpBB/assets/javascript/core.js91
-rw-r--r--phpBB/assets/javascript/editor.js61
2 files changed, 91 insertions, 61 deletions
diff --git a/phpBB/assets/javascript/core.js b/phpBB/assets/javascript/core.js
index a3a6d75dd2..69a09427fe 100644
--- a/phpBB/assets/javascript/core.js
+++ b/phpBB/assets/javascript/core.js
@@ -963,6 +963,93 @@ phpbb.registerDropdown = function(toggle, dropdown, options)
};
/**
+* Get the HTML for a color palette table.
+*
+* @param string dir Palette direction - either v or h
+* @param int width Palette cell width.
+* @param int height Palette cell height.
+*/
+phpbb.colorPalette = function(dir, width, height) {
+ var r = 0,
+ g = 0,
+ b = 0,
+ numberList = new Array(6),
+ color = '',
+ html = '';
+
+ numberList[0] = '00';
+ numberList[1] = '40';
+ numberList[2] = '80';
+ numberList[3] = 'BF';
+ numberList[4] = 'FF';
+
+ html += '<table style="width: auto;">';
+
+ for (r = 0; r < 5; r++) {
+ if (dir == 'h') {
+ html += '<tr>';
+ }
+
+ for (g = 0; g < 5; g++) {
+ if (dir == 'v') {
+ html += '<tr>';
+ }
+
+ for (b = 0; b < 5; b++) {
+ color = String(numberList[r]) + String(numberList[g]) + String(numberList[b]);
+ html += '<td style="background-color: #' + color + '; width: ' + width + 'px; height: ' + height + 'px;">';
+ html += '<a href="#" data-color="' + color + '" style="display: block; width: ' + width + 'px; height: ' + height + 'px; " alt="#' + color + '" title="#' + color + '"></a>';
+ html += '</td>';
+ }
+
+ if (dir == 'v') {
+ html += '</tr>';
+ }
+ }
+
+ if (dir == 'h') {
+ html += '</tr>';
+ }
+ }
+ html += '</table>';
+ return html;
+}
+
+/**
+* Register a color palette.
+*
+* @param object el jQuery object for the palette container.
+*/
+phpbb.registerPalette = function(el) {
+ var orientation = el.attr('data-orientation'),
+ height = el.attr('data-height'),
+ width = el.attr('data-width'),
+ target = el.attr('data-target'),
+ bbcode = el.attr('data-bbcode');
+
+ // Insert the palette HTML into the container.
+ el.html(phpbb.colorPalette(orientation, width, height));
+
+ // Add toggle control.
+ $('#color_palette_toggle').click(function(e) {
+ el.toggle();
+ e.preventDefault();
+ });
+
+ // Attach event handler when a palette cell is clicked.
+ $(el).on('click', 'a', function(e) {
+ var color = $(this).attr('data-color');
+
+ if (bbcode) {
+ bbfontstyle('[color=#' + color + ']', '[/color]');
+ } else {
+ $(target).val(color);
+ }
+ e.preventDefault();
+ });
+}
+
+/**
* Apply code editor to all textarea elements with data-bbcode attribute
*/
$(document).ready(function() {
@@ -977,6 +1064,10 @@ $(document).ready(function() {
$(phpbb.dropdownHandles).each(phpbb.toggleDropdown);
}
});
+
+ $('#color_palette_placeholder').each(function() {
+ phpbb.registerPalette($(this));
+ });
});
})(jQuery); // Avoid conflicts with other libraries
diff --git a/phpBB/assets/javascript/editor.js b/phpBB/assets/javascript/editor.js
index 418dd163aa..5222de9fee 100644
--- a/phpBB/assets/javascript/editor.js
+++ b/phpBB/assets/javascript/editor.js
@@ -295,67 +295,6 @@ function storeCaret(textEl) {
}
/**
-* Color pallette
-*/
-function colorPalette(dir, width, height) {
- var r = 0,
- g = 0,
- b = 0,
- numberList = new Array(6),
- color = '',
- html = '';
-
- numberList[0] = '00';
- numberList[1] = '40';
- numberList[2] = '80';
- numberList[3] = 'BF';
- numberList[4] = 'FF';
-
- html += '<table>';
-
- for (r = 0; r < 5; r++) {
- if (dir == 'h') {
- html += '<tr>';
- }
-
- for (g = 0; g < 5; g++) {
- if (dir == 'v') {
- html += '<tr>';
- }
-
- for (b = 0; b < 5; b++) {
- color = String(numberList[r]) + String(numberList[g]) + String(numberList[b]);
- html += '<td style="background-color: #' + color + '; width: ' + width + 'px; height: ' + height + 'px;">';
- html += '<a href="#" onclick="bbfontstyle(\'[color=#' + color + ']\', \'[/color]\'); return false;" style="display: block; width: ' + width + 'px; height: ' + height + 'px; " alt="#' + color + '" title="#' + color + '"></a>';
- html += '</td>';
- }
-
- if (dir == 'v') {
- html += '</tr>';
- }
- }
-
- if (dir == 'h') {
- html += '</tr>';
- }
- }
- html += '</table>';
- return html;
-}
-
-(function($) {
- $(document).ready(function() {
- $('#color_palette_placeholder').each(function() {
- var orientation = $(this).attr('data-orientation'),
- height = $(this).attr('data-height'),
- width = $(this).attr('data-width');
-
- $(this).html(colorPalette(orientation, width, height));
- });
- });
-})(jQuery);
-
-/**
* Caret Position object
*/
function caretPosition() {