Using the 'Color Picker' inside the vBulletin Options/Settings Area
1 Attachment(s)
Intro
This article is about how you use the color picker inside the vBulletin Option page. I been working on getting this working for the past 2 days and after some serious sit down, I was able to get it to work, and it works very well let me tell you! This is for 3.7.x series only. I haven't tested this on older versions. Step 1 First thing is create your "Option". Data Validation Type MUST be free. Anything else would not work. Reason? (Assuming you everything else filled out) We will be added custom code, more importantly HTML mixed with eval code. So. The example "Option Code" is this: HTML Code:
<script type=\"text/javascript\" src=\"../clientscript/vbulletin_cpcolorpicker.js\"></script> What's going on? First we are adding the javascript file from clientscripts so we can use the color picker that the CSS editor users. The bottom part is needed to start the color picker. numColors is needed so the previewing colors works correctly when loading the values. In this case it's 0. 0 does equal 1. Next we run some eval code. We need to generate the hidden color picker code that will be on the background. So we have to include the adminfunctions_template.php file to be able to do it. Put the code inside and variable and then output that variable so it "shows". Once you do these steps, you can now create your HTML. HTML is anything you want... But you need a input field (doesn't matter the type) and a div that has the colorpreview CSS tag. Without typing everything out notice how everything lines up with the 0: HTML Code:
<td><input type=\"text\" class=\"bginput\" name=\"setting[MYVARNAME][color0]\" id=\"color_0\" value=\"$MYVARNAME[color0]\" tabindex=\"1\" size=\"22\" onchange=\"preview_color(0)\" /> </td> Plugins Needed Because we need to save this eval code, we need plugins to process the data because the options.php file can not process it. So we need custom code to help. Hook: admin_options_processing (used when saving data.) PHP Code:
Hook: admin_options_print (Used when "reading") PHP Code:
That's it! That's how you add the color picker to your plugin options. Granted there are limitations of more than one plugin will use the color picker because you have to keep the javascript variable "sane", but I am looking into making some changes in the "hard" code to send to vB dev team to implement the change to allow the color picker for two different forms if you were in the overall view. Having your plugin show up by itself in the options will work just fine as it will only load your plugin options and the form only once. So there are currently limitations, but this is how it's done for now! Enjoy! |
Very good Shane. This looks much better than the way I tried to implement this into vbulletin.
|
You should be able to transfer the same technique over to a publicly accessible page. :)
|
EDIT: Figured it out but can't figure out how to have more than one on a settings page.
|
Was this matter worked on any more? Can some one update me on this. I am hoping to get a color picker issue resolved as well and this may be the key. Do any of you guys hire out in the work for pay section?
Thanks Charlie |
Just want to confirm for everyone this still works on VB 4.x with one little change, not sure if it ever worked right n 3.x but you lose the preview color in the box in 4.x after saving. The value saves simply the preview color resets to black.
To fix this I edited the line in the option code: Code:
<td><div id=\"preview_0\" class=\"colorpreview\" onclick=\"open_color_picker(0, event)\"></div></td> Code:
<td><div id=\"preview_0\" class=\"colorpreview\" onclick=\"open_color_picker(0, event)\" style=\"background-color:$MYVARNAME[color0];\"></div></td> |
All times are GMT. The time now is 01:23 PM. |
Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|