/[drupal]/contributions/modules/textlinkads/colorpicker2.js
ViewVC logotype

Diff of /contributions/modules/textlinkads/colorpicker2.js

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.2, Thu Feb 8 20:01:10 2007 UTC revision 1.3, Thu Jun 5 23:36:00 2008 UTC
# Line 11  Line 11 
11  // use. That means, you can include it in your product, or your web  // use. That means, you can include it in your product, or your web
12  // site, or any other form where the code is actually being used. You  // site, or any other form where the code is actually being used. You
13  // may not put the plain javascript up on your site for download or  // may not put the plain javascript up on your site for download or
14  // include it in your javascript libraries for download.  // include it in your javascript libraries for download.
15  // If you wish to share this code with others, please just point them  // If you wish to share this code with others, please just point them
16  // to the URL instead.  // to the URL instead.
17  // Please DO NOT link directly to my .js files from your site. Copy  // Please DO NOT link directly to my .js files from your site. Copy
# Line 27  function AnchorPosition_getPageOffsetTop Line 27  function AnchorPosition_getPageOffsetTop
27  function AnchorPosition_getWindowOffsetTop(el){return AnchorPosition_getPageOffsetTop(el)-document.body.scrollTop;}  function AnchorPosition_getWindowOffsetTop(el){return AnchorPosition_getPageOffsetTop(el)-document.body.scrollTop;}
28  /* SOURCE FILE: PopupWindow.js */  /* SOURCE FILE: PopupWindow.js */
29    
30  /*  /*
31  PopupWindow.js  PopupWindow.js
32  Author: Matt Kruse  Author: Matt Kruse
33  Last modified: 02/16/04  Last modified: 02/16/04
# Line 37  in a certain place. The window can eithe Line 37  in a certain place. The window can eithe
37  window.  window.
38    
39  COMPATABILITY: Works with Netscape 4.x, 6.x, IE 5.x on Windows. Some small  COMPATABILITY: Works with Netscape 4.x, 6.x, IE 5.x on Windows. Some small
40  positioning errors - usually with Window positioning - occur on the  positioning errors - usually with Window positioning - occur on the
41  Macintosh platform. Due to bugs in Netscape 4.x, populating the popup  Macintosh platform. Due to bugs in Netscape 4.x, populating the popup
42  window with <STYLE> tags may cause errors.  window with <STYLE> tags may cause errors.
43    
44  USAGE:  USAGE:
45  // Create an object for a WINDOW popup  // Create an object for a WINDOW popup
46  var win = new PopupWindow();  var win = new PopupWindow();
47    
48  // Create an object for a DIV window using the DIV named 'mydiv'  // Create an object for a DIV window using the DIV named 'mydiv'
49  var win = new PopupWindow('mydiv');  var win = new PopupWindow('mydiv');
50    
51  // Set the window to automatically hide itself when the user clicks  // Set the window to automatically hide itself when the user clicks
52  // anywhere else on the page except the popup  // anywhere else on the page except the popup
53  win.autoHide();  win.autoHide();
54    
55  // Show the window relative to the anchor name passed in  // Show the window relative to the anchor name passed in
56  win.showPopup(anchorname);  win.showPopup(anchorname);
# Line 61  win.hidePopup(); Line 61  win.hidePopup();
61  // Set the size of the popup window (only applies to WINDOW popups  // Set the size of the popup window (only applies to WINDOW popups
62  win.setSize(width,height);  win.setSize(width,height);
63    
64  // Populate the contents of the popup window that will be shown. If you  // Populate the contents of the popup window that will be shown. If you
65  // change the contents while it is displayed, you will need to refresh()  // change the contents while it is displayed, you will need to refresh()
66  win.populate(string);  win.populate(string);
67    
# Line 81  win.offsetY = 100; Line 81  win.offsetY = 100;
81  NOTES:  NOTES:
82  1) Requires the functions in AnchorPosition.js  1) Requires the functions in AnchorPosition.js
83    
84  2) Your anchor tag MUST contain both NAME and ID attributes which are the  2) Your anchor tag MUST contain both NAME and ID attributes which are the
85     same. For example:     same. For example:
86     <A NAME="test" ID="test"> </A>     <A NAME="test" ID="test"> </A>
87    
88  3) There must be at least a space between <A> </A> for IE5.5 to see the  3) There must be at least a space between <A> </A> for IE5.5 to see the
89     anchor tag correctly. Do not do <A></A> with no space.     anchor tag correctly. Do not do <A></A> with no space.
90    
91  4) When a PopupWindow object is created, a handler for 'onmouseup' is  4) When a PopupWindow object is created, a handler for 'onmouseup' is
92     attached to any event handler you may have already defined. Do NOT define     attached to any event handler you may have already defined. Do NOT define
93     an event handler for 'onmouseup' after you define a PopupWindow object or     an event handler for 'onmouseup' after you define a PopupWindow object or
94     the autoHide() will not work correctly.     the autoHide() will not work correctly.
95  */  */
96    
97  // Set the position of the popup window based on the anchor  // Set the position of the popup window based on the anchor
98  function PopupWindow_getXYPosition(anchorname) {  function PopupWindow_getXYPosition(anchorname) {
# Line 131  function PopupWindow_refresh() { Line 131  function PopupWindow_refresh() {
131                  if (this.use_gebi) {                  if (this.use_gebi) {
132                          document.getElementById(this.divName).innerHTML = this.contents;                          document.getElementById(this.divName).innerHTML = this.contents;
133                          }                          }
134                  else if (this.use_css) {                  else if (this.use_css) {
135                          document.all[this.divName].innerHTML = this.contents;                          document.all[this.divName].innerHTML = this.contents;
136                          }                          }
137                  else if (this.use_layers) {                  else if (this.use_layers) {
138                          var d = document.layers[this.divName];                          var d = document.layers[this.divName];
139                          d.document.open();                          d.document.open();
140                          d.document.writeln(this.contents);                          d.document.writeln(this.contents);
141                          d.document.close();                          d.document.close();
# Line 310  function PopupWindow() { Line 310  function PopupWindow() {
310          this.populated = false;          this.populated = false;
311          this.visible = false;          this.visible = false;
312          this.autoHideEnabled = false;          this.autoHideEnabled = false;
313    
314          this.contents = "";          this.contents = "";
315          this.url="";          this.url="";
316          this.windowProperties="toolbar=no,location=no,status=no,menubar=no,scrollbars=auto,resizable,alwaysRaised,dependent,titlebar=no";          this.windowProperties="toolbar=no,location=no,status=no,menubar=no,scrollbars=auto,resizable,alwaysRaised,dependent,titlebar=no";
# Line 345  function PopupWindow() { Line 345  function PopupWindow() {
345          }          }
346  /* SOURCE FILE: ColorPicker2.js */  /* SOURCE FILE: ColorPicker2.js */
347    
348  /*  /*
349  Last modified: 02/24/2003  Last modified: 02/24/2003
350    
351  DESCRIPTION: This widget is used to select a color, in hexadecimal #RRGGBB  DESCRIPTION: This widget is used to select a color, in hexadecimal #RRGGBB
352  form. It uses a color "swatch" to display the standard 216-color web-safe  form. It uses a color "swatch" to display the standard 216-color web-safe
353  palette. The user can then click on a color to select it.  palette. The user can then click on a color to select it.
354    
355  COMPATABILITY: See notes in AnchorPosition.js and PopupWindow.js.  COMPATABILITY: See notes in AnchorPosition.js and PopupWindow.js.
# Line 375  var cp = new ColorPicker('window'); Line 375  var cp = new ColorPicker('window');
375    
376  // Write the 'pickColor' function that will be called when the user clicks  // Write the 'pickColor' function that will be called when the user clicks
377  // a color and do something with the value. This is only required if you  // a color and do something with the value. This is only required if you
378  // want to do something other than simply populate a form field, which is  // want to do something other than simply populate a form field, which is
379  // what the 'select' function will give you.  // what the 'select' function will give you.
380  function pickColor(color) {  function pickColor(color) {
381          field.value = color;          field.value = color;
# Line 384  function pickColor(color) { Line 384  function pickColor(color) {
384  NOTES:  NOTES:
385  1) Requires the functions in AnchorPosition.js and PopupWindow.js  1) Requires the functions in AnchorPosition.js and PopupWindow.js
386    
387  2) Your anchor tag MUST contain both NAME and ID attributes which are the  2) Your anchor tag MUST contain both NAME and ID attributes which are the
388     same. For example:     same. For example:
389     <A NAME="test" ID="test"> </A>     <A NAME="test" ID="test"> </A>
390    
391  3) There must be at least a space between <A> </A> for IE5.5 to see the  3) There must be at least a space between <A> </A> for IE5.5 to see the
392     anchor tag correctly. Do not do <A></A> with no space.     anchor tag correctly. Do not do <A></A> with no space.
393    
394  4) When a ColorPicker object is created, a handler for 'onmouseup' is  4) When a ColorPicker object is created, a handler for 'onmouseup' is
395     attached to any event handler you may have already defined. Do NOT define     attached to any event handler you may have already defined. Do NOT define
396     an event handler for 'onmouseup' after you define a ColorPicker object or     an event handler for 'onmouseup' after you define a ColorPicker object or
397     the color picker will not hide itself correctly.     the color picker will not hide itself correctly.
398  */  */
399  ColorPicker_targetInput = null;  ColorPicker_targetInput = null;
400  function ColorPicker_writeDiv() {  function ColorPicker_writeDiv() {
401          document.writeln("<DIV ID=\"colorPickerDiv\" STYLE=\"position:absolute;visibility:hidden;\"> </DIV>");          document.writeln("<DIV ID=\"colorPickerDiv\" STYLE=\"position:absolute;visibility:hidden;\"> </DIV>");
# Line 418  function pickColor(color) { Line 418  function pickColor(color) {
418                  return;                  return;
419                  }                  }
420          ColorPicker_targetInput.value = color;          ColorPicker_targetInput.value = color;
421                  if (ColorPicker_targetInput.id == 'edit-textlinkads_link_color') {                  if (ColorPicker_targetInput.id == 'edit-textlinkads-link-color') {
422                          update_link_color(color);                          update_link_color(color);
423                  }                  }
424                  else if (ColorPicker_targetInput.id == 'edit-textlinkads_bg_color') {                  else if (ColorPicker_targetInput.id == 'edit-textlinkads-bg-color') {
425                          update_bg_color(color);                          update_bg_color(color);
426                  }                  }
427                  else if (ColorPicker_targetInput.id == 'edit-textlinkads_border_color') {                  else if (ColorPicker_targetInput.id == 'edit-textlinkads-border-color') {
428                          update_border_color(color);                          update_border_color(color);
429                  }                  }
430          }          }
431    
432  // This function is the easiest way to popup the window, select a color, and  // This function is the easiest way to popup the window, select a color, and
433  // have the value populate a form field, which is what most people want to do.  // have the value populate a form field, which is what most people want to do.
434  function ColorPicker_select(inputobj,linkname) {  function ColorPicker_select(inputobj, linkname) {
435          if (inputobj.type!="text" && inputobj.type!="hidden" && inputobj.type!="textarea") {          if (inputobj.type!="text" && inputobj.type!="hidden" && inputobj.type!="textarea") {
436                  alert("colorpicker.select: Input object passed is not a valid form input object");                  alert("colorpicker.select: Input object passed is not a valid form input object");
437                  window.ColorPicker_targetInput=null;                  window.ColorPicker_targetInput=null;
438                  return;                  return;
439                  }                  }
440          window.ColorPicker_targetInput = inputobj;          window.ColorPicker_targetInput = inputobj;
441          this.show(linkname);          this.show(linkname);
442          }          }
443    
444  // This function runs when you move your mouse over a color block, if you have a newer browser  // This function runs when you move your mouse over a color block, if you have a newer browser
445  function ColorPicker_highlightColor(c) {  function ColorPicker_highlightColor(c) {
446          var thedoc = (arguments.length>1)?arguments[1]:window.document;          var thedoc = (arguments.length>1)?arguments[1]:window.document;
# Line 463  function ColorPicker() { Line 463  function ColorPicker() {
463          else {          else {
464                  var divname = arguments[0];                  var divname = arguments[0];
465                  }                  }
466    
467          if (divname != "") {          if (divname != "") {
468                  var cp = new PopupWindow(divname);                  var cp = new PopupWindow(divname);
469                  }                  }
# Line 474  function ColorPicker() { Line 474  function ColorPicker() {
474    
475          // Object variables          // Object variables
476          cp.currentValue = "#FFFFFF";          cp.currentValue = "#FFFFFF";
477    
478          // Method Mappings          // Method Mappings
479          cp.writeDiv = ColorPicker_writeDiv;          cp.writeDiv = ColorPicker_writeDiv;
480          cp.highlightColor = ColorPicker_highlightColor;          cp.highlightColor = ColorPicker_highlightColor;
# Line 517  function ColorPicker() { Line 517  function ColorPicker() {
517                  if (use_highlight) { var mo = 'onMouseOver="'+windowRef+'ColorPicker_highlightColor(\''+colors[i]+'\',window.document)"'; }                  if (use_highlight) { var mo = 'onMouseOver="'+windowRef+'ColorPicker_highlightColor(\''+colors[i]+'\',window.document)"'; }
518                  else { mo = ""; }                  else { mo = ""; }
519                  cp_contents += '<TD BGCOLOR="'+colors[i]+'"><FONT SIZE="-3"><A HREF="#" onClick="'+windowRef+'ColorPicker_pickColor(\''+colors[i]+'\','+windowRef+'window.popupWindowObjects['+cp.index+']);return false;" '+mo+' STYLE="text-decoration:none;">&nbsp;&nbsp;&nbsp;</A></FONT></TD>';                  cp_contents += '<TD BGCOLOR="'+colors[i]+'"><FONT SIZE="-3"><A HREF="#" onClick="'+windowRef+'ColorPicker_pickColor(\''+colors[i]+'\','+windowRef+'window.popupWindowObjects['+cp.index+']);return false;" '+mo+' STYLE="text-decoration:none;">&nbsp;&nbsp;&nbsp;</A></FONT></TD>';
520                  if ( ((i+1)>=total) || (((i+1) % width) == 0)) {                  if ( ((i+1)>=total) || (((i+1) % width) == 0)) {
521                          cp_contents += "</TR>";                          cp_contents += "</TR>";
522                          }                          }
523                  }                  }

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

  ViewVC Help
Powered by ViewVC 1.1.2