Skip to content
This repository
Browse code

Colorpicker plugin: ability to set bg color, + better integration wit…

…h jQuery UI
  • Loading branch information...
commit 0d59eab5860c59c1e1bc8b0ffcffc0658a3aecef 1 parent 93b32f2
VitaliyMF VitaliyMF authored

Showing 1 changed file with 36 additions and 7 deletions. Show diff stats Hide diff stats

  1. +36 7 controls/wysiwyg.colorpicker.js
43 controls/wysiwyg.colorpicker.js
@@ -55,7 +55,8 @@
55 55 dialogReplacements = {
56 56 legend: "Colorpicker",
57 57 color: "Color",
58   - submit: "Apply",
  58 + applyForeColor: "Set Text",
  59 + applyBgColor: "Set Background",
59 60 reset: "Cancel"
60 61 };
61 62
@@ -63,7 +64,8 @@
63 64 '<ul class="palette"></ul>' +
64 65 '<label>{color}: <input type="text" name="color" value="#123456"/></label>' +
65 66 '<div class="wheel"></div>' +
66   - '<input type="submit" class="button" value="{submit}"/> ' +
  67 + '<input type="button" class="button applyForeColor" value="{applyForeColor}"/> ' +
  68 + '<input type="button" class="button applyBgColor" value="{applyBgColor}"/> ' +
67 69 '<input type="reset" value="{reset}"/></fieldset></form>';
68 70
69 71 for (key in dialogReplacements) {
@@ -134,10 +136,22 @@
134 136 }
135 137
136 138 dialog = elements.appendTo("body");
  139 + var buttonSetup = {};
  140 + buttonSetup[ dialogReplacements['applyForeColor'] ] = function() {
  141 + dialog.find('input.applyForeColor').click();
  142 + };
  143 + buttonSetup[ dialogReplacements['applyBgColor'] ] = function() {
  144 + dialog.find('input.applyBgColor').click();
  145 + };
  146 + buttonSetup[ dialogReplacements['reset'] ] = function() {
  147 + dialog.find('input:reset').click();
  148 + };
  149 +
137 150 dialog.dialog({
138 151 modal: true,
139 152 open: function (event, ui) {
140   - $("input:submit", elements).click(function (e) {
  153 + $("input:button,input:reset", elements).hide();
  154 + $("input.applyForeColor,input.applyBgColor", elements).click(function (e) {
141 155 var color = $('input[name="color"]', dialog).val();
142 156 self.color.fore.prev = color;
143 157 self.addColorToPalette("fore", color);
@@ -146,7 +160,15 @@
146 160 Wysiwyg.ui.returnRange();
147 161 }
148 162
149   - Wysiwyg.editorDoc.execCommand('ForeColor', false, color);
  163 + if ($(this).hasClass('applyForeColor')) {
  164 + Wysiwyg.editorDoc.execCommand('ForeColor', false, color);
  165 + } else {
  166 + if ($.browser.msie)
  167 + Wysiwyg.editorDoc.execCommand('BackColor', false, color);
  168 + else
  169 + Wysiwyg.editorDoc.execCommand('hilitecolor',false,color);
  170 + }
  171 +
150 172 $(dialog).dialog("close");
151 173 return false;
152 174 });
@@ -162,7 +184,7 @@
162 184 e.stopPropagation();
163 185 });
164 186 },
165   -
  187 + buttons : buttonSetup,
166 188 close: function (event, ui) {
167 189 $.wysiwyg.controls.colorpicker.modalOpen = false;
168 190 dialog.dialog("destroy");
@@ -181,7 +203,7 @@
181 203 this.renderPalette(elements, "fore");
182 204 elements.find("input[name=color]").val(self.color.fore.prev);
183 205 elements.find(".wheel").farbtastic(elements.find("input:text"));
184   - $("input:submit", elements).click(function (event) {
  206 + $("input.applyForeColor,input.applyBgColor", elements).click(function (event) {
185 207 var color = $('input[name="color"]', elements).val();
186 208 self.color.fore.prev = color;
187 209 self.addColorToPalette("fore", color);
@@ -190,7 +212,14 @@
190 212 Wysiwyg.ui.returnRange();
191 213 }
192 214
193   - Wysiwyg.editorDoc.execCommand('ForeColor', false, color);
  215 + if ($(this).hasClass('applyForeColor')) {
  216 + Wysiwyg.editorDoc.execCommand('ForeColor', false, color);
  217 + } else {
  218 + if ($.browser.msie)
  219 + Wysiwyg.editorDoc.execCommand('BackColor', false, color);
  220 + else
  221 + Wysiwyg.editorDoc.execCommand('hilitecolor',false,color);
  222 + }
194 223
195 224 $(elements).remove();
196 225 $.wysiwyg.controls.colorpicker.modalOpen = false;

0 comments on commit 0d59eab

Please sign in to comment.
Something went wrong with that request. Please try again.