Skip to content

Commit 6c25ecf

Browse files
committed
colorpicker
1 parent 3bc51f1 commit 6c25ecf

File tree

5 files changed

+44
-6
lines changed

5 files changed

+44
-6
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ Online Demo: [http://www.atool.org/](http://www.atool.org/)
66

77
## How to use?
88

9+
### One:
10+
11+
Search on wordpress, keywords is `canvas-nest`, then install.
12+
13+
### Two:
14+
915
1. `Download package` from [WP_Canvas_Nest.zip](https://github.com/aTool-org/canvas-nest-for-wp/archive/master.zip)
1016

1117
2. `unzip the package`, and put the folder into `wp-content\plugins` dir, or `upload the zip` in the managment page direactly.

README.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ A wordpress plugin of [canvas-nest.js](https://github.com/aTool-org/canvas-nest.
33

44
## How to use?
55

6+
### One:
7+
8+
Search on wordpress, keywords is `canvas-nest`, then install.
9+
10+
### Two:
11+
612
1. Download package from [WP_Canvas_Nest.zip](https://github.com/aTool-org/canvas-nest-for-wp/raw/master/WP_Canvas_Nest.zip)
713

814
2. unzip the package, and put the folder into `wp-content\plugins` dir.

screenshot/plugin_admin.png

17.8 KB
Loading

settings.php

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,22 @@ private function wrap_var($v) {
1717
if ($v) return true;
1818
return false;
1919
}
20+
21+
private function hex2rgb($hex) {
22+
$hex = str_replace("#", "", $hex);
23+
24+
if(strlen($hex) == 3) {
25+
$r = hexdec(substr($hex,0,1).substr($hex,0,1));
26+
$g = hexdec(substr($hex,1,1).substr($hex,1,1));
27+
$b = hexdec(substr($hex,2,1).substr($hex,2,1));
28+
} else {
29+
$r = hexdec(substr($hex,0,2));
30+
$g = hexdec(substr($hex,2,2));
31+
$b = hexdec(substr($hex,4,2));
32+
}
33+
return array($r, $g, $b);
34+
}
35+
2036
public function add_canvas_nest() {
2137
//判断当前页面是否开启
2238
//is_home 、 is_archive 、 is_singular 、 is_search 、 is_404
@@ -43,6 +59,11 @@ public function add_canvas_nest() {
4359
if ($setting_count === false) $setting_count = '99';
4460
$setting_zindex = get_option('cn_setting_zindex');
4561
if ($setting_zindex === false) $setting_zindex = '-1';
62+
63+
if (strpos($setting_color, '#') === 0) {
64+
$setting_color = $this->hex2rgb($setting_color);
65+
$setting_color = join(',', $setting_color);
66+
}
4667
echo "<script type='text/javascript' color='$setting_color' zIndex='$setting_zindex' opacity='$setting_opacity' count='$setting_count' src='//cdn.bootcss.com/canvas-nest.js/1.0.0/canvas-nest.min.js'></script>";
4768
}
4869
}
@@ -73,7 +94,8 @@ public function admin_init() {
7394
'WP_Canvas_Nest-section',
7495
array(
7596
'field' => 'cn_setting_color',
76-
'value' => '0,0,0'
97+
'value' => '0,0,0',
98+
'type' => 'color'
7799
)
78100
);
79101
add_settings_field(
@@ -84,7 +106,8 @@ public function admin_init() {
84106
'WP_Canvas_Nest-section',
85107
array(
86108
'field' => 'cn_setting_opacity',
87-
'value' => '0.5'
109+
'value' => '0.5',
110+
'type' => 'text'
88111
)
89112
);
90113
add_settings_field(
@@ -95,7 +118,8 @@ public function admin_init() {
95118
'WP_Canvas_Nest-section',
96119
array(
97120
'field' => 'cn_setting_count',
98-
'value' => '99'
121+
'value' => '99',
122+
'type' => 'number'
99123
)
100124
);
101125
add_settings_field(
@@ -106,7 +130,8 @@ public function admin_init() {
106130
'WP_Canvas_Nest-section',
107131
array(
108132
'field' => 'cn_setting_zindex',
109-
'value' => '-1'
133+
'value' => '-1',
134+
'type' => 'number'
110135
)
111136
);
112137

@@ -203,11 +228,12 @@ public function settings_field_checkbox($args) {
203228
*/
204229
public function settings_field_input_text($args) {
205230
$field = $args['field'];
231+
$type = $args['type'];
206232
$value = get_option($field);
207233
if ($value === false) {
208234
$value = $args['value'];
209235
}
210-
echo sprintf('<input type="text" name="%s" id="%s" value="%s" />', $field, $field, $value);
236+
echo sprintf('<input type="%s" name="%s" id="%s" value="%s" />', $type, $field, $field, $value);
211237
}
212238

213239
/**

wp_canvas_nest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Plugin Name: Canvas-Nest.js
44
Plugin URI: https://github.com/aTool-org/canvas-nest-for-wp
55
Description: [正版]A wordpress plugin for canvas-nest.js | 一个很炫酷网页背景效果(canvas-nest.js)的wordpress插件。
6-
Version: 1.0.0
6+
Version: 1.0.1
77
Author: aTool.org
88
Author URI: http://www.aTool.org/
99
License: MIT

0 commit comments

Comments
 (0)