├── colorpicker
├── images
│ ├── grid.gif
│ ├── color.png
│ ├── graybar.jpg
│ ├── meta100.png
│ ├── colorpicker.png
│ └── transparentpixel.gif
└── mColorPicker.js
├── localization
├── ru_RU.inc
├── nl_NL.inc
├── en_US.inc
├── de_DE.inc
├── sk_SK.inc
├── cs_CZ.inc
├── pl_PL.inc
├── it_IT.inc
├── pt_BR.inc
├── hu_HU.inc
└── fr_FR.inc
├── config.inc.php-dist
├── README.md
├── composer.json
├── package.xml
├── skins
├── elastic
│ └── message_highlight.css
├── larry
│ └── message_highlight.css
└── classic
│ └── message_highlight.css
├── CHANGELOG
├── message_highlight.js
├── message_highlight.php
└── LICENSE
/colorpicker/images/grid.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/corbosman/message_highlight/HEAD/colorpicker/images/grid.gif
--------------------------------------------------------------------------------
/colorpicker/images/color.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/corbosman/message_highlight/HEAD/colorpicker/images/color.png
--------------------------------------------------------------------------------
/colorpicker/images/graybar.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/corbosman/message_highlight/HEAD/colorpicker/images/graybar.jpg
--------------------------------------------------------------------------------
/colorpicker/images/meta100.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/corbosman/message_highlight/HEAD/colorpicker/images/meta100.png
--------------------------------------------------------------------------------
/colorpicker/images/colorpicker.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/corbosman/message_highlight/HEAD/colorpicker/images/colorpicker.png
--------------------------------------------------------------------------------
/colorpicker/images/transparentpixel.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/corbosman/message_highlight/HEAD/colorpicker/images/transparentpixel.gif
--------------------------------------------------------------------------------
/localization/ru_RU.inc:
--------------------------------------------------------------------------------
1 |
15 |
16 |
--------------------------------------------------------------------------------
/config.inc.php-dist:
--------------------------------------------------------------------------------
1 | 'subject',
6 | 'input' => 'My Subject',
7 | 'color' => '#ff0000'
8 | ),
9 | array(
10 | 'header' => 'from',
11 | 'input' => 'nobody@example.com',
12 | 'color' => '#00ff00'
13 | ),
14 | array(
15 | 'header' => 'to',
16 | 'input' => 'nobody@example.com',
17 | 'color' => '#0000ff'
18 | ),
19 | array(
20 | 'header' => 'cc',
21 | 'input' => 'nobody@example.com',
22 | 'color' => '#0000ff'
23 | ),
24 | );
--------------------------------------------------------------------------------
/localization/nl_NL.inc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/localization/en_US.inc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | message_highlight
2 | =================
3 |
4 | With this plugin you can colorize the message index rows based on specific criteria like sender, recipient and subject.
5 |
6 | FEATURES
7 | --------
8 |
9 | Go to roundcube settings area and select rules to highlight emails in your mailview.
10 |
11 | CONTACT
12 | -------
13 | Author: Cor Bosman (cor@roundcu.be)
14 |
15 | Bug reports through github (https://github.com/corbosman/message_highlight/issues)
16 |
17 | LICENSE
18 | -------
19 |
20 | This plugin is distributed under the GNU General Public License Version 2.
21 | Please read through the file LICENSE for more information about this license.
22 |
--------------------------------------------------------------------------------
/localization/de_DE.inc:
--------------------------------------------------------------------------------
1 |
16 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name":"cor/message_highlight",
3 | "description":"Assign colors to your emails based on Subject, Sender, Recipient or CC",
4 | "license":"GPL-2.0",
5 | "homepage":"https://github.com/corbosman/message_highlight",
6 | "type": "roundcube-plugin",
7 | "authors": [
8 | {
9 | "name": "Cor Bosman",
10 | "email": "cor@roundcu.be",
11 | "homepage": "http://underwa.ter.net",
12 | "role": "Developer"
13 | }
14 | ],
15 | "support": {
16 | "email": "cor@roundcu.be",
17 | "issues": "https://github.com/corbosman/message_highlight/issues"
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/localization/sk_SK.inc:
--------------------------------------------------------------------------------
1 |
17 |
--------------------------------------------------------------------------------
/localization/cs_CZ.inc:
--------------------------------------------------------------------------------
1 |
17 |
--------------------------------------------------------------------------------
/localization/pl_PL.inc:
--------------------------------------------------------------------------------
1 |
17 |
--------------------------------------------------------------------------------
/localization/it_IT.inc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/localization/pt_BR.inc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/localization/hu_HU.inc:
--------------------------------------------------------------------------------
1 |
16 |
--------------------------------------------------------------------------------
/localization/fr_FR.inc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/package.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 | message_highlight
7 |
8 | Cor Bosman
9 | cor
10 | cor@roundcu.be
11 | yes
12 |
13 | https://github.com/corbosman/message_highlight
14 |
15 | 2.0
16 |
17 | GNU GPLv2
18 |
19 |
--------------------------------------------------------------------------------
/skins/elastic/message_highlight.css:
--------------------------------------------------------------------------------
1 | /* mail list */
2 | .rcmfd_mh_row td {
3 | background-color: transparent !important;
4 | color: #fff !important;
5 | }
6 |
7 | .rcmfd_mh_row_dark td * {
8 | color: #fff !important;
9 | }
10 |
11 | /* preferences */
12 |
13 | .mh_preferences_row {
14 | display: flex;
15 | align-items: center;
16 | }
17 |
18 | .mh_preferences_row .mh_button {
19 | border: 1px solid #ced4da;
20 | }
21 |
22 | /* pencil icon for settings item */
23 | .listing.iconized tr.mh_preferences>td.section:before {
24 | content: "\f303";
25 | }
26 |
27 | /* remove some colorpicker elements */
28 | #mColorPickerTransparent, #mColorPickerSwatches, #mColorPickerImgGray {
29 | display: none;
30 | }
31 |
32 | #mColorPickerFooter {
33 | background-color: #ffffff !important;
34 | }
35 |
36 |
37 | #mColorPicker {
38 | height: 83px !important;
39 | padding: 2px !important;
40 | background-color: #ffffff !important;
41 | }
42 |
--------------------------------------------------------------------------------
/skins/larry/message_highlight.css:
--------------------------------------------------------------------------------
1 | /* mail list */
2 | .rcmfd_mh_row td {
3 | background-color: transparent !important;
4 | }
5 |
6 | .rcmfd_mh_row_dark td * {
7 | color: #fff !important;
8 | }
9 |
10 |
11 | /* settings */
12 | .mh_preferences_row {
13 | display: flex;
14 | align-items: center;
15 | }
16 |
17 | .mh_preferences_row .ml-3 {
18 | margin-left: 10px;
19 | }
20 |
21 | .mh_preferences_row .ml-5 {
22 | margin-left: 15px;
23 | }
24 |
25 |
26 | /* icon */
27 | #sections-table #rcmrowmh_preferences td.section {
28 | background-position: 6px -238px;
29 | }
30 |
31 | #sections-table #rcmrowmh_preferences.selected td.section {
32 | background-position: 6px -262px;
33 | }
34 |
35 | /* remove some colorpicker elements */
36 | #mColorPickerTransparent, #mColorPickerSwatches, #mColorPickerImgGray {
37 | display: none;
38 | }
39 |
40 | #mColorPickerFooter {
41 | background-color: #ffffff !important;
42 | }
43 |
44 |
45 | #mColorPicker {
46 | height: 83px !important;
47 | padding: 2px !important;
48 | background-color: #ffffff !important;
49 | }
50 |
--------------------------------------------------------------------------------
/skins/classic/message_highlight.css:
--------------------------------------------------------------------------------
1 | /* mail list */
2 | .rcmfd_mh_row td {
3 | background-color: transparent !important;
4 | }
5 |
6 | .rcmfd_mh_row_dark td * {
7 | color: #fff !important;
8 | }
9 |
10 |
11 | /* settings */
12 | .mh_preferences_row {
13 | display: flex;
14 | align-items: center;
15 | }
16 |
17 | .mh_preferences_row .ml-3 {
18 | margin-left: 10px;
19 | }
20 |
21 | .mh_preferences_row .ml-5 {
22 | margin-left: 15px;
23 | }
24 |
25 |
26 | /* icon */
27 | #sections-table #rcmrowmh_preferences td.section {
28 | background-position: 6px -238px;
29 | }
30 |
31 | #sections-table #rcmrowmh_preferences.selected td.section {
32 | background-position: 6px -262px;
33 | }
34 |
35 | /* remove some colorpicker elements */
36 | #mColorPickerTransparent, #mColorPickerSwatches, #mColorPickerImgGray {
37 | display: none;
38 | }
39 |
40 | #mColorPickerFooter {
41 | background-color: #ffffff !important;
42 | }
43 |
44 |
45 | #mColorPicker {
46 | height: 83px !important;
47 | padding: 2px !important;
48 | background-color: #ffffff !important;
49 | }
--------------------------------------------------------------------------------
/CHANGELOG:
--------------------------------------------------------------------------------
1 | CHANGELOG message_highlight
2 | ===========================
3 |
4 | RELEASE 4.4
5 |
6 | - allow shorthand colors and better error handling, thanks to PR from Andreas Pakulat
7 |
8 | RELEASE 4.3
9 |
10 | - polish and czech translations
11 |
12 | RELEASE 4.2
13 |
14 | - support config file
15 |
16 | RELEASE 4.1
17 |
18 | - support darker colors
19 |
20 | RELEASE 4.0
21 |
22 | - support elastic skin
23 |
24 | RELEASE 3.1
25 |
26 | - fix some 1.3 deprecated functions
27 |
28 | RELEASE 2.6
29 |
30 | - some text changes
31 |
32 | RELEASE 2.5.2
33 |
34 | - fix composer.json
35 |
36 | RELEASE 2.5
37 |
38 | - js bug fix, dont respond to insertrow except for message view
39 |
40 | RELEASE 2.4
41 |
42 | - live() jquery call replaced with on()
43 |
44 | RELEASE 2.3
45 |
46 | - bugfix: initial row was malformed.
47 |
48 | RELEASE 2.2
49 |
50 | - bugfix: removed a td in javascript
51 |
52 | RELEASE 2.1
53 |
54 | - bugfix: minor fix for table layout
55 | - icon for larry theme
56 | - fixes for larry theme
57 |
58 | RELEASE 2.0.1
59 |
60 | - minor version bump for composer test
61 |
62 | RELEASE 2.0
63 | -----------
64 |
65 | - bugfix: change insertrow code to work with larry skin
66 | - move to github
67 |
68 |
--------------------------------------------------------------------------------
/message_highlight.js:
--------------------------------------------------------------------------------
1 | var mh_cur_row;
2 |
3 | $(document).ready(function() {
4 | if(window.rcmail) {
5 |
6 | /* listen to roundcube insertrow event so we can color the rows */
7 | rcmail.addEventListener('insertrow', mh_insert_row);
8 |
9 | /* listen to receive row event after asking for another row */
10 | rcmail.addEventListener('plugin.mh_receive_row', mh_receive_row);
11 |
12 | /* initialise button click events */
13 | $('.mh_delete').click(function(e) {
14 | e.preventDefault();
15 | mh_delete(this);
16 | });
17 |
18 | $('.mh_add').click(function(e) {
19 | e.preventDefault();
20 | mh_add(this);
21 | });
22 | }
23 | });
24 |
25 | /* insert row event to color a mail row */
26 | function mh_insert_row(evt) {
27 |
28 | if(!rcmail.env.messages) return;
29 |
30 | var message = rcmail.env.messages[evt.row.uid];
31 |
32 | // check if our color info is present
33 | if(message.flags && message.flags.plugin_mh_color) {
34 | var row = $(evt.row.obj);
35 | row.addClass('rcmfd_mh_row');
36 |
37 | evt.row.obj.style.backgroundColor = message.flags.plugin_mh_color;
38 |
39 | var color_brightness = brightness(message.flags.plugin_mh_color);
40 | if (color_brightness !== null && color_brightness < 123) {
41 | row.addClass('rcmfd_mh_row_dark');
42 | }
43 |
44 | }
45 | }
46 |
47 | /* delete a settings row */
48 | function mh_delete(button) {
49 | if (confirm(rcmail.get_label('message_highlight.deleteconfirm'))) {
50 | $(button).closest('tr').remove();
51 | }
52 | }
53 |
54 | // do an ajax call to get a new row
55 | function mh_add(button) {
56 | mh_cur_row = $(button).closest('tr', '.mh_preferences');
57 | lock = rcmail.set_busy(true, 'loading');
58 | rcmail.http_request('plugin.mh_add_row', '', lock);
59 | }
60 |
61 | // ajax return call
62 | function mh_receive_row(data) {
63 | var row = $('
| '+data.row+' |
');
64 | $(mh_cur_row).after(row);
65 |
66 | $(row).find('.mh_color_input').mColorPicker();
67 |
68 | $('.mh_delete').unbind('click').click(function(e) {
69 | e.preventDefault();
70 | mh_delete(this);
71 | });
72 |
73 | $('.mh_add').unbind('click').click(function(e) {
74 | e.preventDefault();
75 | mh_add(this);
76 | });
77 |
78 | }
79 |
80 | /* calculate the brightness of a color */
81 | function brightness(hex) {
82 | var shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
83 | hex = hex.replace(shorthandRegex, function(m, r, g, b) {
84 | return r + r + g + g + b + b;
85 | });
86 | var rgb = hex.match(/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i)
87 | if (rgb === null) {
88 | return null;
89 | }
90 | rgb = rgb.slice(1,4)
91 | .map(function(x) { return parseInt(x, 16); });
92 |
93 | return (rgb[0] * 299 + rgb[1] * 587 + rgb[2] * 114) / 1000
94 | }
95 |
96 |
--------------------------------------------------------------------------------
/message_highlight.php:
--------------------------------------------------------------------------------
1 | rc = rcube::get_instance();
18 |
19 | if ($this->rc->task === 'settings') {
20 |
21 | $this->add_texts('localization/', array('deleteconfirm'));
22 |
23 | $this->add_hook('preferences_list', array($this, 'mh_preferences'));
24 | $this->add_hook('preferences_save', array($this, 'mh_save'));
25 | $this->add_hook('preferences_sections_list',array($this, 'mh_preferences_section'));
26 |
27 | $this->include_script('colorpicker/mColorPicker.js');
28 |
29 | $this->register_action('plugin.mh_add_row', array($this, 'mh_add_row'));
30 | } elseif ($this->rc->task === 'mail') {
31 | $this->add_hook('storage_init', array($this, 'storage_init'));
32 | $this->add_hook('messages_list', array($this, 'mh_highlight'));
33 | }
34 |
35 | $this->include_script('message_highlight.js');
36 | $this->load_config();
37 |
38 | $skin_path = $this->local_skin_path();
39 | $this->include_stylesheet("$skin_path/message_highlight.css");
40 |
41 |
42 | }
43 |
44 | /**
45 | * add the CC header to fetched headers
46 | *
47 | * @param $p
48 | * @return mixed
49 | */
50 | function storage_init($p)
51 | {
52 | $p['fetch_headers'] .= trim($p['fetch_headers']. ' ' . 'CC');
53 | return($p);
54 | }
55 |
56 |
57 | /**
58 | * add highlight data to messages
59 | *
60 | * @param $p
61 | * @return mixed
62 | */
63 | function mh_highlight($p)
64 | {
65 | $this->prefs = array_merge($this->rc->config->get('message_highlight', array()), $this->rc->config->get('message_highlight_default', array()));
66 |
67 | // dont loop over all messages if we dont have any highlights or no msgs
68 | if(!count($this->prefs) or !isset($p['messages']) or !is_array($p['messages'])) return $p;
69 |
70 | // loop over all messages and add highlight color to each message
71 | foreach($p['messages'] as $message) {
72 | if(($color = $this->mh_find_match($message)) !== false ) {
73 | $message->list_flags['extra_flags']['plugin_mh_color'] = $color;
74 | }
75 | }
76 | return($p);
77 | }
78 |
79 |
80 | /**
81 | * find a match
82 | *
83 | * @param $message
84 | * @return bool
85 | */
86 | function mh_find_match($message) {
87 | foreach($this->prefs as $p) {
88 | if(stristr(rcube_mime::decode_header($message->{$p['header']}), $p['input'])) {
89 | return($p['color']);
90 | }
91 | }
92 | return false;
93 | }
94 |
95 | // user preferences
96 | function mh_preferences($args) {
97 | if($args['section'] == 'mh_preferences') {
98 | $this->add_texts('localization/', false);
99 |
100 | $args['blocks']['mh_preferences'] = array(
101 | 'options' => array(),
102 | 'name' => rcube::Q($this->gettext('mh_title'))
103 | );
104 |
105 | $i = 1;
106 | $prefs = $this->rc->config->get('message_highlight', array());
107 |
108 | foreach($prefs as $p) {
109 | $args['blocks']['mh_preferences']['options'][$i++] = array(
110 | 'content' => $this->mh_get_form_row($p['header'], $p['input'], $p['color'], true)
111 | );
112 | }
113 |
114 | // no rows yet, add 1 empty row
115 | if($i == 1) {
116 | $args['blocks']['mh_preferences']['options'][$i] = array(
117 | 'content' => $this->mh_get_form_row()
118 | );
119 | }
120 | }
121 |
122 | return($args);
123 | }
124 |
125 | function mh_add_row() {
126 | $this->rc->output->command('plugin.mh_receive_row', array('row' => $this->mh_get_form_row()));
127 | }
128 |
129 | // create a form row
130 | function mh_get_form_row($header = 'from', $input = '', $color = '#ffffff', $delete = false) {
131 |
132 | // header select box
133 | $header_select = new html_select(array('name' => '_mh_header[]', 'class' => 'rcmfd_mh_header form-control custom-select pretty-select'));
134 | $header_select->add(rcube::Q($this->gettext('subject')), 'subject');
135 | $header_select->add(rcube::Q($this->gettext('from')), 'from');
136 | $header_select->add(rcube::Q($this->gettext('to')), 'to');
137 | $header_select->add(rcube::Q($this->gettext('cc')), 'cc');
138 |
139 | // input field
140 | $input = new html_inputfield(array('name' => '_mh_input[]', 'class' => 'rcmfd_mh_input form-control', 'type' => 'text', 'autocomplete' => 'off', 'value' => $input));
141 |
142 | // color box
143 | $color = html::tag('input', array('id' => uniqid() ,'name' => '_mh_color[]', 'class' => 'mh_color_input', 'value' => $color, 'data-text' => 'hidden', 'data-hex' => 'true'));
144 |
145 | // delete button
146 | // $button = html::a(array('href' => '#', 'class' => ' ', 'title' => $this->gettext('mh_delete')) , 'del');
147 | $button = html::tag('a', array('href' => '#', 'class' => 'button icon mh_delete ', 'title' => $this->gettext('mh_delete')), '');
148 | // $add_button = html::a(array('href' => '#', 'class' => 'button icon mh_add', 'title' => $this->gettext('mh_add')), '');
149 | // add button
150 | $button = html::tag('input', array('class' => 'button mh_delete mh_button form-control btn btn-defaut', 'type' => 'button', 'value' => $this->gettext('mh_delete'), 'title' => $this->gettext('mh_delete_description')));
151 | $add_button = html::tag('input', array('class' => 'button mh_add mh_button form-control btn btn-default', 'type' => 'button', 'value' => $this->gettext('mh_add'), 'title' => $this->gettext('mh_add_description')));
152 |
153 | $content = html::div('mh_preferences_row',
154 | html::div('', $header_select->show($header)) .
155 | html::div('ml-3 text-center', html::span('mh_matches', rcube::Q($this->gettext('mh_matches')))) .
156 | html::div('ml-3', $input->show()) .
157 | html::div('ml-5 text-center', html::span('mh_color', rcube::Q($this->gettext('mh_color')))) .
158 | html::div('ml-3', $color) .
159 | html::div('ml-3', $button) .
160 | html::div('ml-3', $add_button)
161 | );
162 |
163 | return($content);
164 | }
165 |
166 | // add a section to the preferences tab
167 | function mh_preferences_section($args) {
168 | $this->add_texts('localization/', false);
169 | $args['list']['mh_preferences'] = array(
170 | 'id' => 'mh_preferences',
171 | 'section' => rcube::Q($this->gettext('mh_title'))
172 | );
173 | return($args);
174 | }
175 |
176 | // save preferences
177 | function mh_save($args) {
178 | if($args['section'] != 'mh_preferences') return;
179 |
180 | $rcmail = rcmail::get_instance();
181 |
182 | $header = rcube_utils::get_input_value('_mh_header', rcube_utils::INPUT_POST);
183 | $input = rcube_utils::get_input_value('_mh_input', rcube_utils::INPUT_POST);
184 | $color = rcube_utils::get_input_value('_mh_color', rcube_utils::INPUT_POST);
185 |
186 |
187 | for($i=0; $i < count($header); $i++) {
188 | if(!in_array($header[$i], array('subject', 'from', 'to', 'cc'))) {
189 | $rcmail->output->show_message('message_highlight.headererror', 'error');
190 | return;
191 | }
192 | if(!preg_match('/^#[0-9a-fA-F]{2,6}$/', $color[$i])) {
193 | $rcmail->output->show_message('message_highlight.invalidcolor', 'error');
194 | return;
195 | }
196 | if($input[$i] == '') {
197 | continue;
198 | }
199 | $prefs[] = array('header' => $header[$i], 'input' => $input[$i], 'color' => $color[$i]);
200 | }
201 |
202 | $args['prefs']['message_highlight'] = $prefs;
203 | return($args);
204 | }
205 | }
206 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 2, June 1991
3 |
4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6 | Everyone is permitted to copy and distribute verbatim copies
7 | of this license document, but changing it is not allowed.
8 |
9 | Preamble
10 |
11 | The licenses for most software are designed to take away your
12 | freedom to share and change it. By contrast, the GNU General Public
13 | License is intended to guarantee your freedom to share and change free
14 | software--to make sure the software is free for all its users. This
15 | General Public License applies to most of the Free Software
16 | Foundation's software and to any other program whose authors commit to
17 | using it. (Some other Free Software Foundation software is covered by
18 | the GNU Lesser General Public License instead.) You can apply it to
19 | your programs, too.
20 |
21 | When we speak of free software, we are referring to freedom, not
22 | price. Our General Public Licenses are designed to make sure that you
23 | have the freedom to distribute copies of free software (and charge for
24 | this service if you wish), that you receive source code or can get it
25 | if you want it, that you can change the software or use pieces of it
26 | in new free programs; and that you know you can do these things.
27 |
28 | To protect your rights, we need to make restrictions that forbid
29 | anyone to deny you these rights or to ask you to surrender the rights.
30 | These restrictions translate to certain responsibilities for you if you
31 | distribute copies of the software, or if you modify it.
32 |
33 | For example, if you distribute copies of such a program, whether
34 | gratis or for a fee, you must give the recipients all the rights that
35 | you have. You must make sure that they, too, receive or can get the
36 | source code. And you must show them these terms so they know their
37 | rights.
38 |
39 | We protect your rights with two steps: (1) copyright the software, and
40 | (2) offer you this license which gives you legal permission to copy,
41 | distribute and/or modify the software.
42 |
43 | Also, for each author's protection and ours, we want to make certain
44 | that everyone understands that there is no warranty for this free
45 | software. If the software is modified by someone else and passed on, we
46 | want its recipients to know that what they have is not the original, so
47 | that any problems introduced by others will not reflect on the original
48 | authors' reputations.
49 |
50 | Finally, any free program is threatened constantly by software
51 | patents. We wish to avoid the danger that redistributors of a free
52 | program will individually obtain patent licenses, in effect making the
53 | program proprietary. To prevent this, we have made it clear that any
54 | patent must be licensed for everyone's free use or not licensed at all.
55 |
56 | The precise terms and conditions for copying, distribution and
57 | modification follow.
58 |
59 | GNU GENERAL PUBLIC LICENSE
60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61 |
62 | 0. This License applies to any program or other work which contains
63 | a notice placed by the copyright holder saying it may be distributed
64 | under the terms of this General Public License. The "Program", below,
65 | refers to any such program or work, and a "work based on the Program"
66 | means either the Program or any derivative work under copyright law:
67 | that is to say, a work containing the Program or a portion of it,
68 | either verbatim or with modifications and/or translated into another
69 | language. (Hereinafter, translation is included without limitation in
70 | the term "modification".) Each licensee is addressed as "you".
71 |
72 | Activities other than copying, distribution and modification are not
73 | covered by this License; they are outside its scope. The act of
74 | running the Program is not restricted, and the output from the Program
75 | is covered only if its contents constitute a work based on the
76 | Program (independent of having been made by running the Program).
77 | Whether that is true depends on what the Program does.
78 |
79 | 1. You may copy and distribute verbatim copies of the Program's
80 | source code as you receive it, in any medium, provided that you
81 | conspicuously and appropriately publish on each copy an appropriate
82 | copyright notice and disclaimer of warranty; keep intact all the
83 | notices that refer to this License and to the absence of any warranty;
84 | and give any other recipients of the Program a copy of this License
85 | along with the Program.
86 |
87 | You may charge a fee for the physical act of transferring a copy, and
88 | you may at your option offer warranty protection in exchange for a fee.
89 |
90 | 2. You may modify your copy or copies of the Program or any portion
91 | of it, thus forming a work based on the Program, and copy and
92 | distribute such modifications or work under the terms of Section 1
93 | above, provided that you also meet all of these conditions:
94 |
95 | a) You must cause the modified files to carry prominent notices
96 | stating that you changed the files and the date of any change.
97 |
98 | b) You must cause any work that you distribute or publish, that in
99 | whole or in part contains or is derived from the Program or any
100 | part thereof, to be licensed as a whole at no charge to all third
101 | parties under the terms of this License.
102 |
103 | c) If the modified program normally reads commands interactively
104 | when run, you must cause it, when started running for such
105 | interactive use in the most ordinary way, to print or display an
106 | announcement including an appropriate copyright notice and a
107 | notice that there is no warranty (or else, saying that you provide
108 | a warranty) and that users may redistribute the program under
109 | these conditions, and telling the user how to view a copy of this
110 | License. (Exception: if the Program itself is interactive but
111 | does not normally print such an announcement, your work based on
112 | the Program is not required to print an announcement.)
113 |
114 | These requirements apply to the modified work as a whole. If
115 | identifiable sections of that work are not derived from the Program,
116 | and can be reasonably considered independent and separate works in
117 | themselves, then this License, and its terms, do not apply to those
118 | sections when you distribute them as separate works. But when you
119 | distribute the same sections as part of a whole which is a work based
120 | on the Program, the distribution of the whole must be on the terms of
121 | this License, whose permissions for other licensees extend to the
122 | entire whole, and thus to each and every part regardless of who wrote it.
123 |
124 | Thus, it is not the intent of this section to claim rights or contest
125 | your rights to work written entirely by you; rather, the intent is to
126 | exercise the right to control the distribution of derivative or
127 | collective works based on the Program.
128 |
129 | In addition, mere aggregation of another work not based on the Program
130 | with the Program (or with a work based on the Program) on a volume of
131 | a storage or distribution medium does not bring the other work under
132 | the scope of this License.
133 |
134 | 3. You may copy and distribute the Program (or a work based on it,
135 | under Section 2) in object code or executable form under the terms of
136 | Sections 1 and 2 above provided that you also do one of the following:
137 |
138 | a) Accompany it with the complete corresponding machine-readable
139 | source code, which must be distributed under the terms of Sections
140 | 1 and 2 above on a medium customarily used for software interchange; or,
141 |
142 | b) Accompany it with a written offer, valid for at least three
143 | years, to give any third party, for a charge no more than your
144 | cost of physically performing source distribution, a complete
145 | machine-readable copy of the corresponding source code, to be
146 | distributed under the terms of Sections 1 and 2 above on a medium
147 | customarily used for software interchange; or,
148 |
149 | c) Accompany it with the information you received as to the offer
150 | to distribute corresponding source code. (This alternative is
151 | allowed only for noncommercial distribution and only if you
152 | received the program in object code or executable form with such
153 | an offer, in accord with Subsection b above.)
154 |
155 | The source code for a work means the preferred form of the work for
156 | making modifications to it. For an executable work, complete source
157 | code means all the source code for all modules it contains, plus any
158 | associated interface definition files, plus the scripts used to
159 | control compilation and installation of the executable. However, as a
160 | special exception, the source code distributed need not include
161 | anything that is normally distributed (in either source or binary
162 | form) with the major components (compiler, kernel, and so on) of the
163 | operating system on which the executable runs, unless that component
164 | itself accompanies the executable.
165 |
166 | If distribution of executable or object code is made by offering
167 | access to copy from a designated place, then offering equivalent
168 | access to copy the source code from the same place counts as
169 | distribution of the source code, even though third parties are not
170 | compelled to copy the source along with the object code.
171 |
172 | 4. You may not copy, modify, sublicense, or distribute the Program
173 | except as expressly provided under this License. Any attempt
174 | otherwise to copy, modify, sublicense or distribute the Program is
175 | void, and will automatically terminate your rights under this License.
176 | However, parties who have received copies, or rights, from you under
177 | this License will not have their licenses terminated so long as such
178 | parties remain in full compliance.
179 |
180 | 5. You are not required to accept this License, since you have not
181 | signed it. However, nothing else grants you permission to modify or
182 | distribute the Program or its derivative works. These actions are
183 | prohibited by law if you do not accept this License. Therefore, by
184 | modifying or distributing the Program (or any work based on the
185 | Program), you indicate your acceptance of this License to do so, and
186 | all its terms and conditions for copying, distributing or modifying
187 | the Program or works based on it.
188 |
189 | 6. Each time you redistribute the Program (or any work based on the
190 | Program), the recipient automatically receives a license from the
191 | original licensor to copy, distribute or modify the Program subject to
192 | these terms and conditions. You may not impose any further
193 | restrictions on the recipients' exercise of the rights granted herein.
194 | You are not responsible for enforcing compliance by third parties to
195 | this License.
196 |
197 | 7. If, as a consequence of a court judgment or allegation of patent
198 | infringement or for any other reason (not limited to patent issues),
199 | conditions are imposed on you (whether by court order, agreement or
200 | otherwise) that contradict the conditions of this License, they do not
201 | excuse you from the conditions of this License. If you cannot
202 | distribute so as to satisfy simultaneously your obligations under this
203 | License and any other pertinent obligations, then as a consequence you
204 | may not distribute the Program at all. For example, if a patent
205 | license would not permit royalty-free redistribution of the Program by
206 | all those who receive copies directly or indirectly through you, then
207 | the only way you could satisfy both it and this License would be to
208 | refrain entirely from distribution of the Program.
209 |
210 | If any portion of this section is held invalid or unenforceable under
211 | any particular circumstance, the balance of the section is intended to
212 | apply and the section as a whole is intended to apply in other
213 | circumstances.
214 |
215 | It is not the purpose of this section to induce you to infringe any
216 | patents or other property right claims or to contest validity of any
217 | such claims; this section has the sole purpose of protecting the
218 | integrity of the free software distribution system, which is
219 | implemented by public license practices. Many people have made
220 | generous contributions to the wide range of software distributed
221 | through that system in reliance on consistent application of that
222 | system; it is up to the author/donor to decide if he or she is willing
223 | to distribute software through any other system and a licensee cannot
224 | impose that choice.
225 |
226 | This section is intended to make thoroughly clear what is believed to
227 | be a consequence of the rest of this License.
228 |
229 | 8. If the distribution and/or use of the Program is restricted in
230 | certain countries either by patents or by copyrighted interfaces, the
231 | original copyright holder who places the Program under this License
232 | may add an explicit geographical distribution limitation excluding
233 | those countries, so that distribution is permitted only in or among
234 | countries not thus excluded. In such case, this License incorporates
235 | the limitation as if written in the body of this License.
236 |
237 | 9. The Free Software Foundation may publish revised and/or new versions
238 | of the General Public License from time to time. Such new versions will
239 | be similar in spirit to the present version, but may differ in detail to
240 | address new problems or concerns.
241 |
242 | Each version is given a distinguishing version number. If the Program
243 | specifies a version number of this License which applies to it and "any
244 | later version", you have the option of following the terms and conditions
245 | either of that version or of any later version published by the Free
246 | Software Foundation. If the Program does not specify a version number of
247 | this License, you may choose any version ever published by the Free Software
248 | Foundation.
249 |
250 | 10. If you wish to incorporate parts of the Program into other free
251 | programs whose distribution conditions are different, write to the author
252 | to ask for permission. For software which is copyrighted by the Free
253 | Software Foundation, write to the Free Software Foundation; we sometimes
254 | make exceptions for this. Our decision will be guided by the two goals
255 | of preserving the free status of all derivatives of our free software and
256 | of promoting the sharing and reuse of software generally.
257 |
258 | NO WARRANTY
259 |
260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268 | REPAIR OR CORRECTION.
269 |
270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278 | POSSIBILITY OF SUCH DAMAGES.
279 |
280 | END OF TERMS AND CONDITIONS
281 |
282 | How to Apply These Terms to Your New Programs
283 |
284 | If you develop a new program, and you want it to be of the greatest
285 | possible use to the public, the best way to achieve this is to make it
286 | free software which everyone can redistribute and change under these terms.
287 |
288 | To do so, attach the following notices to the program. It is safest
289 | to attach them to the start of each source file to most effectively
290 | convey the exclusion of warranty; and each file should have at least
291 | the "copyright" line and a pointer to where the full notice is found.
292 |
293 |
294 | Copyright (C)
295 |
296 | This program is free software; you can redistribute it and/or modify
297 | it under the terms of the GNU General Public License as published by
298 | the Free Software Foundation; either version 2 of the License, or
299 | (at your option) any later version.
300 |
301 | This program is distributed in the hope that it will be useful,
302 | but WITHOUT ANY WARRANTY; without even the implied warranty of
303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304 | GNU General Public License for more details.
305 |
306 | You should have received a copy of the GNU General Public License along
307 | with this program; if not, write to the Free Software Foundation, Inc.,
308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309 |
310 | Also add information on how to contact you by electronic and paper mail.
311 |
312 | If the program is interactive, make it output a short notice like this
313 | when it starts in an interactive mode:
314 |
315 | Gnomovision version 69, Copyright (C) year name of author
316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317 | This is free software, and you are welcome to redistribute it
318 | under certain conditions; type `show c' for details.
319 |
320 | The hypothetical commands `show w' and `show c' should show the appropriate
321 | parts of the General Public License. Of course, the commands you use may
322 | be called something other than `show w' and `show c'; they could even be
323 | mouse-clicks or menu items--whatever suits your program.
324 |
325 | You should also get your employer (if you work as a programmer) or your
326 | school, if any, to sign a "copyright disclaimer" for the program, if
327 | necessary. Here is a sample; alter the names:
328 |
329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330 | `Gnomovision' (which makes passes at compilers) written by James Hacker.
331 |
332 | , 1 April 1989
333 | Ty Coon, President of Vice
334 |
335 | This General Public License does not permit incorporating your program into
336 | proprietary programs. If your program is a subroutine library, you may
337 | consider it more useful to permit linking proprietary applications with the
338 | library. If this is what you want to do, use the GNU Lesser General
339 | Public License instead of this License.
340 |
--------------------------------------------------------------------------------
/colorpicker/mColorPicker.js:
--------------------------------------------------------------------------------
1 | /*
2 | mColorPicker
3 | Version: 1.0 r34
4 |
5 | Copyright (c) 2010 Meta100 LLC.
6 | http://www.meta100.com/
7 |
8 | Licensed under the MIT license
9 | http://www.opensource.org/licenses/mit-license.php
10 | */
11 |
12 | // After this script loads set:
13 | // $.fn.mColorPicker.init.replace = '.myclass'
14 | // to have this script apply to input.myclass,
15 | // instead of the default input[type=color]
16 | // To turn of automatic operation and run manually set:
17 | // $.fn.mColorPicker.init.replace = false
18 | // To use manually call like any other jQuery plugin
19 | // $('input.foo').mColorPicker({options})
20 | // options:
21 | // imageFolder - Change to move image location.
22 | // swatches - Initial colors in the swatch, must an array of 10 colors.
23 | // init:
24 | // $.fn.mColorPicker.init.enhancedSwatches - Turn of saving and loading of swatch to cookies.
25 | // $.fn.mColorPicker.init.allowTransparency - Turn off transperancy as a color option.
26 | // $.fn.mColorPicker.init.showLogo - Turn on/off the meta100 logo (You don't really want to turn it off, do you?).
27 |
28 | (function($){
29 |
30 | var $o;
31 |
32 | $.fn.mColorPicker = function(options) {
33 |
34 | $o = $.extend($.fn.mColorPicker.defaults, options);
35 |
36 | if ($o.swatches.length < 10) $o.swatches = $.fn.mColorPicker.defaults.swatches
37 | if ($("div#mColorPicker").length < 1) $.fn.mColorPicker.drawPicker();
38 |
39 | if ($('#css_disabled_color_picker').length < 1) $('head').prepend('');
40 |
41 | $('body').on('keyup', '.mColorPicker', function () {
42 |
43 | try {
44 |
45 | $(this).css({
46 | 'background-color': $(this).val()
47 | }).css({
48 | 'color': $.fn.mColorPicker.textColor($(this).css('background-color'))
49 | }).trigger('change');
50 | } catch (r) {}
51 | });
52 |
53 | $('body').on('click', '.mColorPickerTrigger', function () {
54 |
55 | $.fn.mColorPicker.colorShow($(this).attr('id').replace('icp_', ''));
56 | });
57 |
58 | this.each(function () {
59 |
60 | $.fn.mColorPicker.drawPickerTriggers($(this));
61 | });
62 |
63 | return this;
64 | };
65 |
66 | $.fn.mColorPicker.currentColor = false;
67 | $.fn.mColorPicker.currentValue = false;
68 | $.fn.mColorPicker.color = false;
69 |
70 | $.fn.mColorPicker.init = {
71 | replace: '[type=color]',
72 | index: 0,
73 | enhancedSwatches: true,
74 | allowTransparency: true,
75 | checkRedraw: 'DOMUpdated', // Change to 'ajaxSuccess' for ajax only or false if not needed
76 | liveEvents: false,
77 | showLogo: false
78 | };
79 |
80 | $.fn.mColorPicker.defaults = {
81 | imageFolder: 'images/',
82 | swatches: [
83 | "#ffffff",
84 | "#ffff00",
85 | "#00ff00",
86 | "#00ffff",
87 | "#0000ff",
88 | "#ff00ff",
89 | "#ff0000",
90 | "#4c2b11",
91 | "#3b3b3b",
92 | "#000000"
93 | ]
94 | };
95 |
96 | $.fn.mColorPicker.liveEvents = function() {
97 |
98 | $.fn.mColorPicker.init.liveEvents = true;
99 |
100 | if ($.fn.mColorPicker.init.checkRedraw && $.fn.mColorPicker.init.replace) {
101 |
102 | $(document).bind($.fn.mColorPicker.init.checkRedraw + '.mColorPicker', function () {
103 |
104 | $('input[data-mcolorpicker!="true"]').filter(function() {
105 |
106 | return ($.fn.mColorPicker.init.replace == '[type=color]')? this.getAttribute("type") == 'color': $(this).is($.fn.mColorPicker.init.replace);
107 | }).mColorPicker();
108 | });
109 | }
110 | };
111 |
112 | $.fn.mColorPicker.drawPickerTriggers = function ($t) {
113 |
114 | if ($t[0].nodeName.toLowerCase() != 'input') return false;
115 |
116 | var id = $t.attr('id') || 'color_' + $.fn.mColorPicker.init.index++,
117 | hidden = false;
118 |
119 | $t.attr('id', id);
120 |
121 | if ($t.attr('text') == 'hidden' || $t.attr('data-text') == 'hidden') hidden = true;
122 |
123 | var color = $t.val(),
124 | width = 75,
125 | height = 25,
126 | flt = $t.css('float'),
127 | image = (color == 'transparent')? "url('" + $o.imageFolder + "/grid.gif')": '',
128 | colorPicker = '';
129 |
130 | $('body').append('');
131 | $('span#color_work_area').append($t.clone(true));
132 | colorPicker = $('span#color_work_area').html().replace(/type="color"/gi, '').replace(/input /gi, (hidden)? 'input type="hidden"': 'input type="text"');
133 | $('span#color_work_area').html('').remove();
134 | $t.after(
135 | (hidden)? ' ': ''
136 | ).after(colorPicker).remove();
137 |
138 | if (hidden) {
139 |
140 | $('#icp_' + id).css({
141 | 'background-color': color,
142 | 'background-image': image,
143 | 'display': 'inline-block'
144 | }).attr(
145 | 'class', $('#' + id).attr('class')
146 | ).addClass(
147 | 'mColorPickerTrigger'
148 | );
149 | } else {
150 |
151 | $('#' + id).css({
152 | 'background-color': color,
153 | 'background-image': image
154 | }).css({
155 | 'color': $.fn.mColorPicker.textColor($('#' + id).css('background-color'))
156 | }).after(
157 | '
'
158 | ).addClass('mColorPickerInput');
159 | }
160 |
161 | $('#icp_' + id).attr('data-mcolorpicker', 'true');
162 |
163 | $('#' + id).addClass('mColorPicker');
164 |
165 | return $('#' + id);
166 | };
167 |
168 | $.fn.mColorPicker.drawPicker = function () {
169 |
170 | $(document.createElement("div")).attr(
171 | "id","mColorPicker"
172 | ).css(
173 | 'display','none'
174 | ).html(
175 | ''
176 | ).appendTo("body");
177 |
178 | $(document.createElement("div")).attr("id","mColorPickerBg").css({
179 | 'display': 'none'
180 | }).appendTo("body");
181 |
182 | for (n = 9; n > -1; n--) {
183 |
184 | $(document.createElement("div")).attr({
185 | 'id': 'cell' + n,
186 | 'class': "mPastColor" + ((n > 0)? ' mNoLeftBorder': '')
187 | }).html(
188 | ' '
189 | ).prependTo("#mColorPickerSwatches");
190 | }
191 |
192 | $('#mColorPicker').css({
193 | 'border':'1px solid #ccc',
194 | 'color':'#fff',
195 | 'z-index':999998,
196 | 'width':'199px',
197 | 'height':'184px',
198 | 'font-size':'12px',
199 | 'font-family':'times'
200 | });
201 |
202 | $('.mPastColor').css({
203 | 'height':'18px',
204 | 'width':'18px',
205 | 'border':'1px solid #000',
206 | 'float':'left'
207 | });
208 |
209 | $('#colorPreview').css({
210 | 'height':'50px'
211 | });
212 |
213 | $('.mNoLeftBorder').css({
214 | 'border-left':0
215 | });
216 |
217 | $('.mClear').css({
218 | 'clear':'both'
219 | });
220 |
221 | $('#mColorPickerWrapper').css({
222 | 'position':'relative',
223 | 'border':'solid 1px gray',
224 | 'z-index':999999
225 | });
226 |
227 | $('#mColorPickerImg').css({
228 | 'height':'128px',
229 | 'width':'192px',
230 | 'border':0,
231 | 'cursor':'crosshair',
232 | 'background-image':"url('" + $o.imageFolder + "colorpicker.png')"
233 | });
234 |
235 | $('#mColorPickerImgGray').css({
236 | 'height':'8px',
237 | 'width':'192px',
238 | 'border':0,
239 | 'cursor':'crosshair',
240 | 'background-image':"url('" + $o.imageFolder + "graybar.jpg')"
241 | });
242 |
243 | $('#mColorPickerInput').css({
244 | 'border':'solid 1px gray',
245 | 'font-size':'10pt',
246 | 'margin':'3px',
247 | 'width':'80px'
248 | });
249 |
250 | $('#mColorPickerImgGrid').css({
251 | 'border':0,
252 | 'height':'20px',
253 | 'width':'20px',
254 | 'vertical-align':'text-bottom'
255 | });
256 |
257 | $('#mColorPickerSwatches').css({
258 | 'border-right':'1px solid #000'
259 | });
260 |
261 |
262 | if ($.fn.mColorPicker.init.allowTransparency) $('#mColorPickerFooter').prepend('transparent');
263 | if ($.fn.mColorPicker.init.showLogo) $('#mColorPickerFooter').prepend('
');
264 |
265 | $("#mColorPickerBg").click($.fn.mColorPicker.closePicker);
266 |
267 | var swatch = $.fn.mColorPicker.getCookie('swatches'),
268 | i = 0;
269 |
270 | if (typeof swatch == 'string') swatch = swatch.split('||');
271 | if (swatch == null || $.fn.mColorPicker.init.enhancedSwatches || swatch.length < 10) swatch = $o.swatches;
272 |
273 | $(".mPastColor").each(function() {
274 |
275 | $(this).css('background-color', swatch[i++].toLowerCase());
276 | });
277 | };
278 |
279 | $.fn.mColorPicker.closePicker = function () {
280 |
281 | $(".mColor, .mPastColor, #mColorPickerInput, #mColorPickerWrapper").unbind();
282 | $("#mColorPickerBg").hide();
283 | $("#mColorPicker").fadeOut()
284 | };
285 |
286 | $.fn.mColorPicker.colorShow = function (id) {
287 |
288 | var $e = $("#icp_" + id);
289 | pos = $e.offset(),
290 | $i = $("#" + id);
291 | hex = $i.attr('data-hex') || $i.attr('hex'),
292 | pickerTop = pos.top + $e.outerHeight(),
293 | pickerLeft = pos.left,
294 | $d = $(document),
295 | $m = $("#mColorPicker");
296 |
297 | if ($i.attr('disabled')) return false;
298 |
299 | // KEEP COLOR PICKER IN VIEWPORT
300 | if (pickerTop + $m.height() > $d.height()) pickerTop = pos.top - $m.height();
301 | if (pickerLeft + $m.width() > $d.width()) pickerLeft = pos.left - $m.width() + $e.outerWidth();
302 |
303 | $m.css({
304 | 'top':(pickerTop) + "px",
305 | 'left':(pickerLeft) + "px",
306 | 'position':'absolute'
307 | }).fadeIn("fast");
308 |
309 | $("#mColorPickerBg").css({
310 | 'z-index':999990,
311 | 'background':'black',
312 | 'opacity': .01,
313 | 'position':'absolute',
314 | 'top':0,
315 | 'left':0,
316 | 'width': parseInt($d.width(), 10) + 'px',
317 | 'height': parseInt($d.height(), 10) + 'px'
318 | }).show();
319 |
320 | var def = $i.val();
321 |
322 | $('#colorPreview span').text(def);
323 | $('#colorPreview').css('background', def);
324 | $('#color').val(def);
325 |
326 | if ($('#' + id).attr('data-text')) $.fn.mColorPicker.currentColor = $e.css('background-color');
327 | else $.fn.mColorPicker.currentColor = $i.css('background-color');
328 |
329 | if (hex == 'true') $.fn.mColorPicker.currentColor = $.fn.mColorPicker.RGBtoHex($.fn.mColorPicker.currentColor);
330 |
331 | $("#mColorPickerInput").val($.fn.mColorPicker.currentColor);
332 |
333 | $('.mColor, .mPastColor').bind('mousemove', function(e) {
334 |
335 | var offset = $(this).offset();
336 |
337 | $.fn.mColorPicker.color = $(this).css("background-color");
338 |
339 | if ($(this).hasClass('mPastColor') && hex == 'true') $.fn.mColorPicker.color = $.fn.mColorPicker.RGBtoHex($.fn.mColorPicker.color);
340 | else if ($(this).hasClass('mPastColor') && hex != 'true') $.fn.mColorPicker.color = $.fn.mColorPicker.hexToRGB($.fn.mColorPicker.color);
341 | else if ($(this).attr('id') == 'mColorPickerTransparent') $.fn.mColorPicker.color = 'transparent';
342 | else if (!$(this).hasClass('mPastColor')) $.fn.mColorPicker.color = $.fn.mColorPicker.whichColor(e.pageX - offset.left, e.pageY - offset.top + (($(this).attr('id') == 'mColorPickerImgGray')? 128: 0), hex);
343 |
344 | $.fn.mColorPicker.setInputColor(id, $.fn.mColorPicker.color);
345 | }).click(function() {
346 |
347 | $.fn.mColorPicker.colorPicked(id);
348 | });
349 |
350 | $('#mColorPickerInput').bind('keyup', function (e) {
351 |
352 | try {
353 |
354 | $.fn.mColorPicker.color = $('#mColorPickerInput').val();
355 | $.fn.mColorPicker.setInputColor(id, $.fn.mColorPicker.color);
356 |
357 | if (e.which == 13) $.fn.mColorPicker.colorPicked(id);
358 | } catch (r) {}
359 |
360 | }).bind('blur', function () {
361 |
362 | $.fn.mColorPicker.setInputColor(id, $.fn.mColorPicker.currentColor);
363 | });
364 |
365 | $('#mColorPickerWrapper').bind('mouseleave', function () {
366 |
367 | $.fn.mColorPicker.setInputColor(id, $.fn.mColorPicker.currentColor);
368 | });
369 | };
370 |
371 | $.fn.mColorPicker.setInputColor = function (id, color) {
372 |
373 | var image = (color == 'transparent')? "url('" + $o.imageFolder + "grid.gif')": '',
374 | textColor = $.fn.mColorPicker.textColor(color);
375 |
376 | if ($('#' + id).attr('data-text') || $('#' + id).attr('text')) $("#icp_" + id).css({'background-color': color, 'background-image': image});
377 | $("#" + id).val(color).css({'background-color': color, 'background-image': image, 'color' : textColor}).trigger('change');
378 | $("#mColorPickerInput").val(color);
379 | };
380 |
381 | $.fn.mColorPicker.textColor = function (val) {
382 |
383 | if (typeof val == 'undefined' || val == 'transparent') return "black";
384 | val = $.fn.mColorPicker.RGBtoHex(val);
385 | return (parseInt(val.substr(1, 2), 16) + parseInt(val.substr(3, 2), 16) + parseInt(val.substr(5, 2), 16) < 400)? 'white': 'black';
386 | };
387 |
388 | $.fn.mColorPicker.setCookie = function (name, value, days) {
389 |
390 | var cookie_string = name + "=" + escape(value),
391 | expires = new Date();
392 | expires.setDate(expires.getDate() + days);
393 | cookie_string += "; expires=" + expires.toGMTString();
394 |
395 | document.cookie = cookie_string;
396 | };
397 |
398 | $.fn.mColorPicker.getCookie = function (name) {
399 |
400 | var results = document.cookie.match ( '(^|;) ?' + name + '=([^;]*)(;|$)' );
401 |
402 | if (results) return (unescape(results[2]));
403 | else return null;
404 | };
405 |
406 | $.fn.mColorPicker.colorPicked = function (id) {
407 |
408 | $.fn.mColorPicker.closePicker();
409 |
410 | if ($.fn.mColorPicker.init.enhancedSwatches) $.fn.mColorPicker.addToSwatch();
411 |
412 | $("#" + id).trigger('colorpicked');
413 | };
414 |
415 | $.fn.mColorPicker.addToSwatch = function (color) {
416 |
417 | var swatch = []
418 | i = 0;
419 |
420 | if (typeof color == 'string') $.fn.mColorPicker.color = color.toLowerCase();
421 |
422 | $.fn.mColorPicker.currentValue = $.fn.mColorPicker.currentColor = $.fn.mColorPicker.color;
423 |
424 | if ($.fn.mColorPicker.color != 'transparent') swatch[0] = $.fn.mColorPicker.color.toLowerCase();
425 |
426 | $('.mPastColor').each(function() {
427 |
428 | $.fn.mColorPicker.color = $(this).css('background-color').toLowerCase();
429 |
430 | if ($.fn.mColorPicker.color != swatch[0] && $.fn.mColorPicker.RGBtoHex($.fn.mColorPicker.color) != swatch[0] && $.fn.mColorPicker.hexToRGB($.fn.mColorPicker.color) != swatch[0] && swatch.length < 10) swatch[swatch.length] = $.fn.mColorPicker.color;
431 |
432 | $(this).css('background-color', swatch[i++])
433 | });
434 |
435 | if ($.fn.mColorPicker.init.enhancedSwatches) $.fn.mColorPicker.setCookie('swatches', swatch.join('||'), 365);
436 | };
437 |
438 | $.fn.mColorPicker.whichColor = function (x, y, hex) {
439 |
440 | var colorR = colorG = colorB = 255;
441 |
442 | if (x < 32) {
443 |
444 | colorG = x * 8;
445 | colorB = 0;
446 | } else if (x < 64) {
447 |
448 | colorR = 256 - (x - 32 ) * 8;
449 | colorB = 0;
450 | } else if (x < 96) {
451 |
452 | colorR = 0;
453 | colorB = (x - 64) * 8;
454 | } else if (x < 128) {
455 |
456 | colorR = 0;
457 | colorG = 256 - (x - 96) * 8;
458 | } else if (x < 160) {
459 |
460 | colorR = (x - 128) * 8;
461 | colorG = 0;
462 | } else {
463 |
464 | colorG = 0;
465 | colorB = 256 - (x - 160) * 8;
466 | }
467 |
468 | if (y < 64) {
469 |
470 | colorR += (256 - colorR) * (64 - y) / 64;
471 | colorG += (256 - colorG) * (64 - y) / 64;
472 | colorB += (256 - colorB) * (64 - y) / 64;
473 | } else if (y <= 128) {
474 |
475 | colorR -= colorR * (y - 64) / 64;
476 | colorG -= colorG * (y - 64) / 64;
477 | colorB -= colorB * (y - 64) / 64;
478 | } else if (y > 128) {
479 |
480 | colorR = colorG = colorB = 256 - ( x / 192 * 256 );
481 | }
482 |
483 | colorR = Math.round(Math.min(colorR, 255));
484 | colorG = Math.round(Math.min(colorG, 255));
485 | colorB = Math.round(Math.min(colorB, 255));
486 |
487 | if (hex == 'true') {
488 |
489 | colorR = colorR.toString(16);
490 | colorG = colorG.toString(16);
491 | colorB = colorB.toString(16);
492 |
493 | if (colorR.length < 2) colorR = 0 + colorR;
494 | if (colorG.length < 2) colorG = 0 + colorG;
495 | if (colorB.length < 2) colorB = 0 + colorB;
496 |
497 | return "#" + colorR + colorG + colorB;
498 | }
499 |
500 | return "rgb(" + colorR + ', ' + colorG + ', ' + colorB + ')';
501 | };
502 |
503 | $.fn.mColorPicker.RGBtoHex = function (color) {
504 |
505 | color = color.toLowerCase();
506 |
507 | if (typeof color == 'undefined') return '';
508 | if (color.indexOf('#') > -1 && color.length > 6) return color;
509 | if (color.indexOf('rgb') < 0) return color;
510 |
511 | if (color.indexOf('#') > -1) {
512 |
513 | return '#' + color.substr(1, 1) + color.substr(1, 1) + color.substr(2, 1) + color.substr(2, 1) + color.substr(3, 1) + color.substr(3, 1);
514 | }
515 |
516 | var hexArray = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"],
517 | decToHex = "#",
518 | code1 = 0;
519 |
520 | color = color.replace(/[^0-9,]/g, '').split(",");
521 |
522 | for (var n = 0; n < color.length; n++) {
523 |
524 | code1 = Math.floor(color[n] / 16);
525 | decToHex += hexArray[code1] + hexArray[color[n] - code1 * 16];
526 | }
527 |
528 | return decToHex;
529 | };
530 |
531 | $.fn.mColorPicker.hexToRGB = function (color) {
532 |
533 | color = color.toLowerCase();
534 |
535 | if (typeof color == 'undefined') return '';
536 | if (color.indexOf('rgb') > -1) return color;
537 | if (color.indexOf('#') < 0) return color;
538 |
539 | var c = color.replace('#', '');
540 |
541 | if (c.length < 6) c = c.substr(0, 1) + c.substr(0, 1) + c.substr(1, 1) + c.substr(1, 1) + c.substr(2, 1) + c.substr(2, 1);
542 |
543 | return 'rgb(' + parseInt(c.substr(0, 2), 16) + ', ' + parseInt(c.substr(2, 2), 16) + ', ' + parseInt(c.substr(4, 2), 16) + ')';
544 | };
545 |
546 | $(document).ready(function () {
547 |
548 | $('.mh_color_input').mColorPicker({
549 | imageFolder: 'plugins/message_highlight/colorpicker/images/',
550 | allowTransparency: false,
551 | showLogo: false,
552 | liveEvents: false,
553 | checkRedraw: 'ajaxSuccess'
554 | });
555 |
556 |
557 |
558 | // if ($.fn.mColorPicker.init.replace) {
559 | //
560 | // $('input[data-mcolorpicker!="true"]').filter(function() {
561 | //
562 | // return ($.fn.mColorPicker.init.replace == '[type=color]') ? this.getAttribute("type") == 'color': $(this).is($.fn.mColorPicker.init.replace);
563 | // }).mColorPicker({
564 | // imageFolder: 'plugins/message_highlight/colorpicker/images/',
565 | // allowTransparency: false,
566 | // showLogo: false,
567 | // liveEvents: false,
568 | // checkRedraw: 'ajaxSuccess'
569 | // });
570 | //
571 | // $.fn.mColorPicker.liveEvents();
572 | // }
573 | });
574 | })(jQuery);
575 |
--------------------------------------------------------------------------------