Meta Box - Version 4.3.2

Version Description

  • Bug fix: allow to have more than 1 map on a page
  • Bug fix: use HTTPS for Google Maps to work both in HTTP & HTTPS
  • Bug fix: allow to clear all terms in taxonomy field
  • Bug fix: "std" value for select fields is no longer "placeholder"
  • Improvement: add "placeholder" param for select fields
  • Improvement: add to helper function ability to show Google Maps in the front end. Check documentation for usage.
  • Improvement: add spaces between radio inputs
  • Improvement: add more params to "rwmb_meta" filter
  • Improvement: using CSS animation for delete image
Download this release

Release Info

Developer rilwis
Plugin Icon 128x128 Meta Box
Version 4.3.2
Comparing to
See all releases

Code changes from version 4.3.1 to 4.3.2

css/file.css CHANGED
@@ -4,6 +4,10 @@
4
  .rwmb-file li{
5
  width: 250px;
6
  margin:0 10px 10px 0;;
 
 
 
 
7
  }
8
  .rwmb-file .rwmb-icon {
9
  width: 60px;
@@ -32,4 +36,25 @@
32
  }
33
  .rwmb-file .rwmb-icon, .rwmb-file .rwmb-info {
34
  margin:0 0 2px 2px;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  }
4
  .rwmb-file li{
5
  width: 250px;
6
  margin:0 10px 10px 0;;
7
+ -moz-transition:width 0.25s, opacity 0.25s, -moz-opacity 0.25s;
8
+ -webkit-transition:width 0.25s, opacity 0.25s, -webkit-opacity 0.25s;
9
+ -o-transition:width 0.25s, opacity 0.25s, -o-opacity 0.25s;
10
+ transition:width 0.25s, opacity 0.25s;
11
  }
12
  .rwmb-file .rwmb-icon {
13
  width: 60px;
36
  }
37
  .rwmb-file .rwmb-icon, .rwmb-file .rwmb-info {
38
  margin:0 0 2px 2px;
39
+ }
40
+
41
+ .rwmb-file li.removed {
42
+ width: 0;
43
+ margin: 0;
44
+ opacity: 0;
45
+ -webkit-opacity: 0;
46
+ -moz-opacity: 0;
47
+ -o-opacity: 0;
48
+ }
49
+
50
+ .rwmb-file li.removed:after {
51
+ content: ' ';
52
+ position: absolute;
53
+ top:0;
54
+ left:0;
55
+ right:0;
56
+ bottom:0;
57
+ z-index: 2;
58
+ opacity: .4;
59
+ background-color: #F00;
60
  }
css/image.css CHANGED
@@ -11,6 +11,10 @@
11
  border: 2px solid #ccc;
12
  cursor: move;
13
  position: relative;
 
 
 
 
14
  }
15
  .rwmb-images img {
16
  width: 150px;
@@ -46,3 +50,24 @@ li:hover .rwmb-image-bar{
46
  font-size:23px;
47
  width:18px;
48
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  border: 2px solid #ccc;
12
  cursor: move;
13
  position: relative;
14
+ -moz-transition:width 0.25s, opacity 0.25s, -moz-opacity 0.25s;
15
+ -webkit-transition:width 0.25s, opacity 0.25s, -webkit-opacity 0.25s;
16
+ -o-transition:width 0.25s, opacity 0.25s, -o-opacity 0.25s;
17
+ transition:width 0.25s, opacity 0.25s;
18
  }
19
  .rwmb-images img {
20
  width: 150px;
50
  font-size:23px;
51
  width:18px;
52
  }
53
+
54
+ .rwmb-images li.removed {
55
+ width: 0;
56
+ margin: 0;
57
+ opacity: 0;
58
+ -webkit-opacity: 0;
59
+ -moz-opacity: 0;
60
+ -o-opacity: 0;
61
+ }
62
+
63
+ .rwmb-images li.removed:after {
64
+ content: ' ';
65
+ position: absolute;
66
+ top:0;
67
+ left:0;
68
+ right:0;
69
+ bottom:0;
70
+ z-index: 2;
71
+ opacity: .4;
72
+ background-color: #F00;
73
+ }
demo/demo.php CHANGED
@@ -92,8 +92,9 @@ $meta_boxes[] = array(
92
  'value2' => __( 'Label2', 'rwmb' ),
93
  ),
94
  // Select multiple values, optional. Default is false.
95
- 'multiple' => false,
96
- 'std' => __( 'Select an Item', 'rwmb' ),
 
97
  ),
98
  // HIDDEN
99
  array(
@@ -267,6 +268,21 @@ $meta_boxes[] = array(
267
  'desc' => __( 'oEmbed description', 'rwmb' ),
268
  'type' => 'oembed',
269
  ),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
270
  // TAXONOMY
271
  array(
272
  'name' => __( 'Taxonomy', 'rwmb' ),
@@ -275,8 +291,8 @@ $meta_boxes[] = array(
275
  'options' => array(
276
  // Taxonomy name
277
  'taxonomy' => 'category',
278
- // How to show taxonomy: 'checkbox_list' (default) or 'checkbox_tree', 'select_tree' or 'select'. Optional
279
- 'type' => 'select_tree',
280
  // Additional arguments for get_terms() function. Optional
281
  'args' => array()
282
  ),
92
  'value2' => __( 'Label2', 'rwmb' ),
93
  ),
94
  // Select multiple values, optional. Default is false.
95
+ 'multiple' => false,
96
+ 'std' => 'value2',
97
+ 'placeholder' => __( 'Select an Item', 'rwmb' ),
98
  ),
99
  // HIDDEN
100
  array(
268
  'desc' => __( 'oEmbed description', 'rwmb' ),
269
  'type' => 'oembed',
270
  ),
271
+ // SELECT ADVANCED BOX
272
+ array(
273
+ 'name' => __( 'Select', 'rwmb' ),
274
+ 'id' => "{$prefix}select_advanced",
275
+ 'type' => 'select_advanced',
276
+ // Array of 'value' => 'Label' pairs for select box
277
+ 'options' => array(
278
+ 'value1' => __( 'Label1', 'rwmb' ),
279
+ 'value2' => __( 'Label2', 'rwmb' ),
280
+ ),
281
+ // Select multiple values, optional. Default is false.
282
+ 'multiple' => false,
283
+ // 'std' => 'value2', // Default value, optional
284
+ 'placeholder' => __( 'Select an Item', 'rwmb' ),
285
+ ),
286
  // TAXONOMY
287
  array(
288
  'name' => __( 'Taxonomy', 'rwmb' ),
291
  'options' => array(
292
  // Taxonomy name
293
  'taxonomy' => 'category',
294
+ // How to show taxonomy: 'checkbox_list' (default) or 'checkbox_tree', 'select_tree', select_advanced or 'select'. Optional
295
+ 'type' => 'checkbox_list',
296
  // Additional arguments for get_terms() function. Optional
297
  'args' => array()
298
  ),
inc/fields/fieldset-text.php ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ // Prevent loading this file directly
3
+ defined( 'ABSPATH' ) || exit;
4
+
5
+ if ( ! class_exists( 'RWMB_Fieldset_Text_Field' ) )
6
+ {
7
+ class RWMB_Fieldset_Text_Field
8
+ {
9
+ /**
10
+ * Get field HTML
11
+ *
12
+ * @param string $html
13
+ * @param mixed $meta
14
+ * @param array $field
15
+ *
16
+ * @return string
17
+ */
18
+ static function html( $html, $meta, $field )
19
+ {
20
+ $out = '';
21
+
22
+ if (count($meta)==1 && trim($meta[0])=='') {
23
+ $meta = "";
24
+ }
25
+
26
+ $html = array();
27
+ $before = '<fieldset><legend>'.$field['desc'].'</legend>';
28
+ $after = '</fieldset>';
29
+
30
+ $tpl = '<label>%s <input type="text" class="rwmb-fieldset-text" name="%s[%s][%d]" placeholder="%s" value="%s" /></label>';
31
+
32
+ for($n=0;$n<$field['rows'];$n++) {
33
+ foreach( $field['options'] as $k => $v ) {
34
+ $fid = $field['id'];
35
+ if (is_array($meta) && !empty($meta)) {
36
+ $html[] = sprintf($tpl, $k, $fid, $v, $n, $k, $meta[$v][$n]);
37
+ } else {
38
+ $html[] = sprintf($tpl, $k, $fid, $v, $n, $k, '');
39
+ }
40
+ }
41
+ $html[] = "<br/>\n";
42
+ }
43
+
44
+ $out = $before . implode( ' ', $html ) . $after;
45
+ return $out;
46
+ }
47
+
48
+ /**
49
+ * Get meta value
50
+ *
51
+ * @param $meta
52
+ * @param $post_id
53
+ * @param $saved
54
+ * @param $field
55
+ *
56
+ * @return array
57
+ */
58
+ static function meta( $meta, $post_id, $saved, $field )
59
+ {
60
+ $meta = get_post_meta( $post_id, $field['id'] );
61
+
62
+ if (is_array($meta) && !empty($meta)) {
63
+ $meta = $meta[0];
64
+ }
65
+
66
+ return $meta;
67
+ }
68
+
69
+ /**
70
+ * Save meta value
71
+ *
72
+ * @param $new
73
+ * @param $old
74
+ * @param $post_id
75
+ * @param $field
76
+ */
77
+ static function save( $new, $old, $post_id, $field )
78
+ {
79
+ update_post_meta($post_id, $field['id'], $new, $old);
80
+ }
81
+
82
+ }
83
+ }
inc/fields/map.php CHANGED
@@ -13,7 +13,7 @@ if ( !class_exists( 'RWMB_Map_Field' ) )
13
  */
14
  static function admin_enqueue_scripts()
15
  {
16
- wp_enqueue_script( 'googlemap', 'http://maps.google.com/maps/api/js?sensor=false', array(), '', true );
17
  wp_enqueue_script( 'rwmb-map', RWMB_JS_URL . 'map.js', array( 'jquery', 'jquery-ui-autocomplete', 'googlemap' ), RWMB_VER, true );
18
  }
19
 
@@ -34,7 +34,7 @@ if ( !class_exists( 'RWMB_Map_Field' ) )
34
 
35
  $html .= sprintf(
36
  '<div class="rwmb-map-canvas" style="%s"></div>
37
- <input type="hidden" name="%s" class="rwmb-map-coordinate" value="%s" />',
38
  isset( $field['style'] ) ? $field['style'] : '',
39
  $field['field_name'],
40
  $meta
@@ -43,7 +43,7 @@ if ( !class_exists( 'RWMB_Map_Field' ) )
43
  if ( $address )
44
  {
45
  $html .= sprintf(
46
- '<button class="button rwmb-map-goto-address-button" type="button" value="%s">%s</button>',
47
  is_array( $address ) ? implode( ',', $address ) : $address,
48
  __( 'Find Address', 'rwmb' )
49
  );
@@ -54,4 +54,4 @@ if ( !class_exists( 'RWMB_Map_Field' ) )
54
  return $html;
55
  }
56
  }
57
- }
13
  */
14
  static function admin_enqueue_scripts()
15
  {
16
+ wp_enqueue_script( 'googlemap', 'https://maps.google.com/maps/api/js?sensor=false', array(), '', true );
17
  wp_enqueue_script( 'rwmb-map', RWMB_JS_URL . 'map.js', array( 'jquery', 'jquery-ui-autocomplete', 'googlemap' ), RWMB_VER, true );
18
  }
19
 
34
 
35
  $html .= sprintf(
36
  '<div class="rwmb-map-canvas" style="%s"></div>
37
+ <input type="hidden" name="%s" class="rwmb-map-coordinate" value="%s">',
38
  isset( $field['style'] ) ? $field['style'] : '',
39
  $field['field_name'],
40
  $meta
43
  if ( $address )
44
  {
45
  $html .= sprintf(
46
+ '<button class="button rwmb-map-goto-address-button" value="%s">%s</button>',
47
  is_array( $address ) ? implode( ',', $address ) : $address,
48
  __( 'Find Address', 'rwmb' )
49
  );
54
  return $html;
55
  }
56
  }
57
+ }
inc/fields/radio.php CHANGED
@@ -17,12 +17,12 @@ if ( ! class_exists( 'RWMB_Radio_Field' ) )
17
  */
18
  static function html( $html, $meta, $field )
19
  {
20
- $html = '';
21
- $tpl = '<label><input type="radio" class="rwmb-radio" name="%s" value="%s" %s /> %s</label>';
22
 
23
  foreach ( $field['options'] as $value => $label )
24
  {
25
- $html .= sprintf(
26
  $tpl,
27
  $field['field_name'],
28
  $value,
@@ -31,7 +31,7 @@ if ( ! class_exists( 'RWMB_Radio_Field' ) )
31
  );
32
  }
33
 
34
- return $html;
35
  }
36
  }
37
- }
17
  */
18
  static function html( $html, $meta, $field )
19
  {
20
+ $html = array();
21
+ $tpl = '<label><input type="radio" class="rwmb-radio" name="%s" value="%s"%s> %s</label>';
22
 
23
  foreach ( $field['options'] as $value => $label )
24
  {
25
+ $html[] = sprintf(
26
  $tpl,
27
  $field['field_name'],
28
  $value,
31
  );
32
  }
33
 
34
+ return implode( ' ', $html );
35
  }
36
  }
37
+ }
inc/fields/select-advanced.php CHANGED
@@ -60,7 +60,7 @@ if ( !class_exists( 'RWMB_Select_Advanced_Field' ) )
60
  static function normalize_field( $field )
61
  {
62
  $field = parent::normalize_field( $field );
63
-
64
  $field = wp_parse_args( $field, array(
65
  'js_options' => array(),
66
  ) );
@@ -68,10 +68,8 @@ if ( !class_exists( 'RWMB_Select_Advanced_Field' ) )
68
  $field['js_options'] = wp_parse_args( $field['js_options'], array(
69
  'allowClear' => true,
70
  'width' => 'resolve',
71
- 'placeholder' => empty( $field['std'] ) ? __( 'Select a value', 'rwmb' ) : $field['std']
72
  ) );
73
-
74
- $field['std'] = '';
75
 
76
  return $field;
77
  }
60
  static function normalize_field( $field )
61
  {
62
  $field = parent::normalize_field( $field );
63
+
64
  $field = wp_parse_args( $field, array(
65
  'js_options' => array(),
66
  ) );
68
  $field['js_options'] = wp_parse_args( $field['js_options'], array(
69
  'allowClear' => true,
70
  'width' => 'resolve',
71
+ 'placeholder' => $field['placeholder'],
72
  ) );
 
 
73
 
74
  return $field;
75
  }
inc/fields/select.php CHANGED
@@ -34,9 +34,9 @@ if ( !class_exists( 'RWMB_Select_Field' ) )
34
  $field['size'],
35
  $field['multiple'] ? ' multiple="multiple"' : ''
36
  );
37
-
38
  $html .= self::options_html( $field, $meta );
39
-
40
  $html .= '</select>';
41
 
42
  return $html;
@@ -105,15 +105,16 @@ if ( !class_exists( 'RWMB_Select_Field' ) )
105
  static function normalize_field( $field )
106
  {
107
  $field = wp_parse_args( $field, array(
108
- 'desc'=> '',
109
- 'name' => $field['id'],
110
- 'size' => $field['multiple'] ? 5 : 0,
 
111
  ) );
112
  if ( !$field['clone'] && $field['multiple'] )
113
  $field['field_name'] .= '[]';
114
  return $field;
115
  }
116
-
117
  /**
118
  * Creates html for options
119
  *
@@ -123,10 +124,12 @@ if ( !class_exists( 'RWMB_Select_Field' ) )
123
  */
124
  static function options_html( $field, $meta )
125
  {
126
- $html = "<option value=''>{$field['std']}</option>";
127
-
128
- $option = '<option value="%s" %s>%s</option>';
129
-
 
 
130
  foreach ( $field['options'] as $value => $label )
131
  {
132
  $html .= sprintf(
@@ -136,8 +139,8 @@ if ( !class_exists( 'RWMB_Select_Field' ) )
136
  $label
137
  );
138
  }
139
-
140
  return $html;
141
  }
142
  }
143
- }
34
  $field['size'],
35
  $field['multiple'] ? ' multiple="multiple"' : ''
36
  );
37
+
38
  $html .= self::options_html( $field, $meta );
39
+
40
  $html .= '</select>';
41
 
42
  return $html;
105
  static function normalize_field( $field )
106
  {
107
  $field = wp_parse_args( $field, array(
108
+ 'desc' => '',
109
+ 'name' => $field['id'],
110
+ 'size' => $field['multiple'] ? 5 : 0,
111
+ 'placeholder' => '',
112
  ) );
113
  if ( !$field['clone'] && $field['multiple'] )
114
  $field['field_name'] .= '[]';
115
  return $field;
116
  }
117
+
118
  /**
119
  * Creates html for options
120
  *
124
  */
125
  static function options_html( $field, $meta )
126
  {
127
+ $html = '';
128
+ if ( $field['placeholder'] )
129
+ $html = 'select' == $field['type'] ? "<option value=''>{$field['placeholder']}</option>" : '<option></option>';
130
+
131
+ $option = '<option value="%s"%s>%s</option>';
132
+
133
  foreach ( $field['options'] as $value => $label )
134
  {
135
  $html .= sprintf(
139
  $label
140
  );
141
  }
142
+
143
  return $html;
144
  }
145
  }
146
+ }
inc/fields/taxonomy.php CHANGED
@@ -33,11 +33,11 @@ if ( ! class_exists( 'RWMB_Taxonomy_Field' ) )
33
  'hide_empty' => false,
34
  );
35
 
36
- //Set default args
37
- $field['options']['args'] = ( ! isset( $field['options']['args'] ) ) ? $default_args : wp_parse_args( $field['options']['args'], $default_args );
38
 
39
  $tax = get_taxonomy( $field['options']['taxonomy'] );
40
- $field['std'] = empty( $field['std'] ) ? sprintf( __( 'Select a %s' , 'rwmb' ), $tax->labels->singular_name ) : $field['std'];
41
 
42
  switch( $field['options']['type'] )
43
  {
@@ -69,9 +69,9 @@ if ( ! class_exists( 'RWMB_Taxonomy_Field' ) )
69
  $field['options']['parent'] = 0;
70
  }
71
  }
72
-
73
  $field['field_name'] = "{$field['id']}[]";
74
-
75
  return $field;
76
  }
77
 
@@ -86,7 +86,6 @@ if ( ! class_exists( 'RWMB_Taxonomy_Field' ) )
86
  */
87
  static function html( $html, $meta, $field )
88
  {
89
-
90
  $options = $field['options'];
91
  $terms = get_terms( $options['taxonomy'], $options['args'] );
92
 
@@ -223,6 +222,21 @@ if ( ! class_exists( 'RWMB_Taxonomy_Field' ) )
223
  return $options;
224
  }
225
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
226
  /**
227
  * Save post taxonomy
228
  *
33
  'hide_empty' => false,
34
  );
35
 
36
+ // Set default args
37
+ $field['options']['args'] = ! isset( $field['options']['args'] ) ? $default_args : wp_parse_args( $field['options']['args'], $default_args );
38
 
39
  $tax = get_taxonomy( $field['options']['taxonomy'] );
40
+ $field['placeholder'] = empty( $field['placeholder'] ) ? sprintf( __( 'Select a %s' , 'rwmb' ), $tax->labels->singular_name ) : $field['placeholder'];
41
 
42
  switch( $field['options']['type'] )
43
  {
69
  $field['options']['parent'] = 0;
70
  }
71
  }
72
+
73
  $field['field_name'] = "{$field['id']}[]";
74
+
75
  return $field;
76
  }
77
 
86
  */
87
  static function html( $html, $meta, $field )
88
  {
 
89
  $options = $field['options'];
90
  $terms = get_terms( $options['taxonomy'], $options['args'] );
91
 
222
  return $options;
223
  }
224
 
225
+ /**
226
+ * Get meta values to save
227
+ *
228
+ * @param mixed $new
229
+ * @param mixed $old
230
+ * @param int $post_id
231
+ * @param array $field
232
+ *
233
+ * @return mixed Faked value to make sure the "save" method is run when all terms are unchecked/unselected
234
+ */
235
+ static function value( $new, $old, $post_id, $field )
236
+ {
237
+ return 1;
238
+ }
239
+
240
  /**
241
  * Save post taxonomy
242
  *
inc/helpers.php CHANGED
@@ -124,7 +124,7 @@ function rwmb_meta( $key, $args = array(), $post_id = null )
124
  ) );
125
 
126
  // Set 'multiple' for fields based on 'type'
127
- $args['multiple'] = in_array( $args['type'], array( 'checkbox_list', 'file', 'image', 'plupload_image', 'thickbox_image' ) );
128
 
129
  $meta = get_post_meta( $post_id, $key, !$args['multiple'] );
130
 
@@ -173,7 +173,13 @@ function rwmb_meta( $key, $args = array(), $post_id = null )
173
  $meta = empty( $args['taxonomy'] ) ? array() : wp_get_post_terms( $post_id, $args['taxonomy'] );
174
  }
175
 
176
- return apply_filters( __FUNCTION__, $meta );
 
 
 
 
 
 
177
  }
178
 
179
  /**
@@ -228,4 +234,102 @@ function rwmb_image_info( $id, $args = array() )
228
  'description' => $attachment->post_content,
229
  'alt' => get_post_meta( $id, '_wp_attachment_image_alt', true ),
230
  );
231
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
124
  ) );
125
 
126
  // Set 'multiple' for fields based on 'type'
127
+ $args['multiple'] = in_array( $args['type'], array( 'checkbox_list', 'file', 'file_advanced', 'image', 'image_advanced', 'plupload_image', 'thickbox_image' ) );
128
 
129
  $meta = get_post_meta( $post_id, $key, !$args['multiple'] );
130
 
173
  $meta = empty( $args['taxonomy'] ) ? array() : wp_get_post_terms( $post_id, $args['taxonomy'] );
174
  }
175
 
176
+ // Get map
177
+ elseif ( 'map' == $args['type'] )
178
+ {
179
+ $meta = rwmb_meta_map( $key, $args, $post_id );
180
+ }
181
+
182
+ return apply_filters( __FUNCTION__, $meta, $key, $args, $post_id );
183
  }
184
 
185
  /**
234
  'description' => $attachment->post_content,
235
  'alt' => get_post_meta( $id, '_wp_attachment_image_alt', true ),
236
  );
237
+ }
238
+
239
+ /**
240
+ * Display map using Google API
241
+ *
242
+ * @param string $key Meta key
243
+ * @param array $args Map parameter
244
+ * @param int|null $post_id Post ID
245
+ *
246
+ * @return string
247
+ */
248
+ function rwmb_meta_map( $key, $args = array(), $post_id = null )
249
+ {
250
+ $post_id = empty( $post_id ) ? get_the_ID() : $post_id;
251
+ $loc = get_post_meta( $post_id, $key, true );
252
+ if ( !$loc )
253
+ return '';
254
+
255
+ $parts = array_map( 'trim', explode( ',', $loc ) );
256
+
257
+ // No zoom entered, set it to 14 by default
258
+ if ( count( $parts ) < 3 )
259
+ $parts[2] = 14;
260
+
261
+ // Map parameters
262
+ $args = wp_parse_args( $args, array(
263
+ 'width' => 640,
264
+ 'height' => 480,
265
+ 'zoom' => $parts[2], // Default to 'zoom' level set in admin, but can be overwritten
266
+ 'marker' => true, // Display marker?
267
+ 'marker_title' => '', // Marker title, when hover
268
+ 'info_window' => '', // Content of info window (when click on marker). HTML allowed
269
+ ) );
270
+
271
+ // Counter to display multiple maps on same page
272
+ static $counter = 0;
273
+
274
+ $html = sprintf(
275
+ '<div id="rwmb-map-canvas-%d" style="width:%s;height:%s"></div>',
276
+ $counter,
277
+ $args['width'] . 'px',
278
+ $args['height'] . 'px'
279
+ );
280
+ $html .= '<script src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>';
281
+ $html .= '<script>
282
+ (function()
283
+ {
284
+ function initialize()
285
+ {
286
+ ';
287
+
288
+ $html .= sprintf( '
289
+ var center = new google.maps.LatLng( %s, %s ),
290
+ mapOptions = {
291
+ center: center,
292
+ zoom: %d,
293
+ mapTypeId: google.maps.MapTypeId.ROADMAP
294
+ },
295
+ map = new google.maps.Map( document.getElementById( "rwmb-map-canvas-%d" ), mapOptions );',
296
+ $parts[0], $parts[1],
297
+ $args['zoom'],
298
+ $counter
299
+ );
300
+
301
+ if ( $args['marker'] )
302
+ {
303
+ $html .= sprintf( '
304
+ var marker = new google.maps.Marker( {
305
+ position: center,
306
+ map: map%s
307
+ } );',
308
+ $args['marker_title'] ? ', title: "' . $args['marker_title'] . '"' : ''
309
+ );
310
+
311
+ if ( $args['info_window'] )
312
+ {
313
+ $html .= sprintf( '
314
+ var infoWindow = new google.maps.InfoWindow( {
315
+ content: "%s"
316
+ } );
317
+
318
+ google.maps.event.addListener( marker, "click", function()
319
+ {
320
+ infoWindow.open( map, marker );
321
+ } );',
322
+ $args['info_window']
323
+ );
324
+ }
325
+ }
326
+
327
+ $html .= '
328
+ }
329
+ google.maps.event.addDomListener(window, "load", initialize);
330
+ }());
331
+ </script>';
332
+
333
+ $counter++;
334
+ return $html;
335
+ }
js/file.js CHANGED
@@ -62,14 +62,22 @@ jQuery( document ).ready( function( $ )
62
  }
63
  else
64
  {
65
- $parent.remove();
 
 
 
66
  $container.trigger( 'update.rwmbFile' );
67
  }
68
  }, 'xml' );
69
 
70
  return false;
71
  } );
72
-
 
 
 
 
 
73
  $( 'body' ).on( 'update.rwmbFile', '.rwmb-uploaded', function()
74
  {
75
  var $fileList = $( this ),
62
  }
63
  else
64
  {
65
+ $parent.addClass( 'removed' );
66
+ //If transition events not supported
67
+ if( !('ontransitionend' in window) && ('onwebkittransitionend' in window) && !('onotransitionend' in myDiv || navigator.appName == 'Opera') )
68
+ $parent.remove();
69
  $container.trigger( 'update.rwmbFile' );
70
  }
71
  }, 'xml' );
72
 
73
  return false;
74
  } );
75
+
76
+ //Remove deleted file
77
+ $( '.rwmb-uploaded' ).on( 'transitionend webkitTransitionEnd otransitionend', 'li.removed', function() {
78
+ $( this ).remove();
79
+ });
80
+
81
  $( 'body' ).on( 'update.rwmbFile', '.rwmb-uploaded', function()
82
  {
83
  var $fileList = $( this ),
js/map.js CHANGED
@@ -1,183 +1,179 @@
1
- (function($)
2
  {
3
- var mapField = {};
4
 
5
- (function()
 
6
  {
7
- "use strict";
 
8
 
9
- var thisMapField = this;
10
-
11
- this.container = null;
12
- this.canvas = null;
13
- this.latlng = null;
14
- this.map = null;
15
- this.marker = null;
16
- this.geocoder = null;
17
-
18
- this.init = function($container)
19
  {
20
- this.container = $container;
21
- this.canvas = $container.find('.rwmb-map-canvas');
22
- this.initLatLng(53.346881, -6.258860);
23
- this.initMap();
24
- this.initMarker();
25
- this.initGeocoder();
26
  this.initMarkerPosition();
27
- this.initListeners();
28
- this.initAutoComplete();
29
- this.bindHandlers();
30
- }
31
 
32
- this.initLatLng = function($lat, $lng)
 
33
  {
34
- this.latlng = new window.google.maps.LatLng($lat, $lng);
35
- }
36
-
37
- this.initMap = function()
 
 
 
 
38
  {
39
- this.map = new window.google.maps.Map(this.canvas[0], {
40
- zoom: 8,
41
- center: this.latlng,
42
- streetViewControl: 0,
43
- mapTypeId: window.google.maps.MapTypeId.ROADMAP
44
- });
45
- }
46
 
47
- this.initMarker = function()
48
- {
49
- this.marker = new window.google.maps.Marker({position: this.latlng, map: this.map, draggable: true});
50
- }
51
-
52
- this.initMarkerPosition = function()
 
 
 
 
 
 
53
  {
54
- var coord = this.container.find('.rwmb-map-coordinate').val();
55
- var addressField = this.container.find('.rwmb-map-goto-address-button').val();
56
- var l;
57
- var zoom;
58
 
59
- if (coord)
60
  {
61
  l = coord.split( ',' );
62
- this.marker.setPosition( new window.google.maps.LatLng( l[0], l[1] ) );
63
 
64
- zoom = l.length > 2 ? parseInt( l[2], 10 ) : 15;
65
 
66
- this.map.setCenter(this.marker.position);
67
- this.map.setZoom(zoom);
68
  }
69
- else if (addressField)
70
  {
71
- this.geocodeAddress(addressField);
72
  }
 
73
 
74
- }
75
-
76
- this.initGeocoder = function()
77
  {
78
- this.geocoder = new window.google.maps.Geocoder();
79
- }
80
-
81
- this.initListeners = function()
82
- {
83
- var that = thisMapField;
84
- window.google.maps.event.addListener(this.map, 'click', function (event)
85
  {
86
- that.marker.setPosition(event.latLng);
87
- that.updatePositionInput(event.latLng);
88
- });
89
- window.google.maps.event.addListener(this.marker, 'drag', function (event)
90
  {
91
- that.updatePositionInput(event.latLng);
92
- });
93
- }
94
 
95
- this.updatePositionInput = function(latLng)
96
- {
97
- this.container.find('.rwmb-map-coordinate').val(latLng.lat() + ',' + latLng.lng());
98
- }
 
 
99
 
100
- this.geocodeAddress = function(addressField)
 
101
  {
102
- var address = '';
103
- var fieldList = addressField.split(',');
104
- var loop;
105
 
106
- for (loop = 0; loop < fieldList.length; loop++)
107
- {
108
- address += jQuery('#' + fieldList[loop] ).val();
109
- if(loop+1 < fieldList.length) { address += ', '; }
110
- }
111
-
112
- address = address.replace( /\n/g, ',' );
113
- address = address.replace( /,,/g, ',' );
114
 
115
- var that = thisMapField;
116
- this.geocoder.geocode({'address': address}, function (results, status)
117
- {
118
- if ( status == window.google.maps.GeocoderStatus.OK )
119
  {
120
- that.updatePositionInput(results[0].geometry.location);
121
- that.marker.setPosition(results[0].geometry.location);
122
- that.map.setCenter(that.marker.position);
123
- that.map.setZoom(15);
124
- }
125
- });
126
- }
127
-
128
- this.initAutoComplete = function()
129
- {
130
- var addressField = this.container.find('.rwmb-map-goto-address-button').val();
131
- if (!addressField) return null;
132
-
133
- var that = thisMapField;
134
- $('#' + addressField).autocomplete({
135
- source: function(request, response) {
136
  // TODO: add 'region' option, to help bias geocoder.
137
- that.geocoder.geocode( {'address': request.term }, function(results, status) {
138
- response($.map(results, function(item) {
 
 
 
 
139
  return {
140
  label: item.formatted_address,
141
  value: item.formatted_address,
142
  latitude: item.geometry.location.lat(),
143
  longitude: item.geometry.location.lng()
144
  };
145
- }));
146
- });
147
  },
148
- select: function(event, ui) {
149
- that.container.find(".rwmb-map-coordinate").val(ui.item.latitude + ',' + ui.item.longitude );
150
- var location = new window.google.maps.LatLng(ui.item.latitude, ui.item.longitude);
151
- that.map.setCenter(location);
152
- // Drop the Marker
153
- setTimeout(function(){
154
- that.marker.setValues({
155
- position: location,
156
- animation: window.google.maps.Animation.DROP
157
- });
158
- }, 1500);
159
- }
160
- });
161
- }
162
-
163
- this.bindHandlers = function()
164
  {
165
- var that = thisMapField;
166
- this.container.find('.rwmb-map-goto-address-button').bind('click', function() { that.onFindAddressClick($(this)); });
167
- }
168
 
169
- this.onFindAddressClick = function($that)
 
170
  {
171
- var $this = $that;
172
- this.geocodeAddress($this.val());
173
- }
 
174
 
175
- }).apply(mapField);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
176
 
177
- $(document).ready(function() {
178
- $('.rwmb-map-field').each(function(){
179
- mapField.init($(this));
180
- });
181
- });
 
 
 
182
 
183
- })(jQuery);
1
+ ( function( $ )
2
  {
3
+ 'use strict';
4
 
5
+ // Use function construction to store map & DOM elements separately for each instance
6
+ var mapField = function( $container )
7
  {
8
+ this.$container = $container;
9
+ };
10
 
11
+ // Use prototype for better performance
12
+ mapField.prototype = {
13
+ // Initialize everything
14
+ init: function()
 
 
 
 
 
 
15
  {
16
+ this.initDomElements();
17
+ this.initMapElements();
18
+
 
 
 
19
  this.initMarkerPosition();
20
+ this.addListeners();
21
+ this.autocomplete();
22
+ },
 
23
 
24
+ // Initialize DOM elements
25
+ initDomElements: function()
26
  {
27
+ this.canvas = this.$container.find( '.rwmb-map-canvas' )[0];
28
+ this.$coordinate = this.$container.find( '.rwmb-map-coordinate' );
29
+ this.$findButton = this.$container.find( '.rwmb-map-goto-address-button' );
30
+ this.addressField = this.$findButton.val();
31
+ },
32
+
33
+ // Initialize map elements
34
+ initMapElements: function()
35
  {
36
+ var latLng = new google.maps.LatLng( 53.346881, -6.258860 ); // Initial position for map
 
 
 
 
 
 
37
 
38
+ this.map = new google.maps.Map( this.canvas, {
39
+ center: latLng,
40
+ zoom: 14,
41
+ streetViewControl: 0,
42
+ mapTypeId: google.maps.MapTypeId.ROADMAP
43
+ } );
44
+ this.marker = new google.maps.Marker( {position: latLng, map: this.map, draggable: true} );
45
+ this.geocoder = new google.maps.Geocoder();
46
+ },
47
+
48
+ // Initialize marker position
49
+ initMarkerPosition: function()
50
  {
51
+ var coord = this.$coordinate.val(),
52
+ l,
53
+ zoom;
 
54
 
55
+ if ( coord )
56
  {
57
  l = coord.split( ',' );
58
+ this.marker.setPosition( new google.maps.LatLng( l[0], l[1] ) );
59
 
60
+ zoom = l.length > 2 ? parseInt( l[2], 10 ) : 14;
61
 
62
+ this.map.setCenter( this.marker.position );
63
+ this.map.setZoom( zoom );
64
  }
65
+ else if ( this.addressField )
66
  {
67
+ this.geocodeAddress();
68
  }
69
+ },
70
 
71
+ // Add event listeners for 'click' & 'drag'
72
+ addListeners: function()
 
73
  {
74
+ var that = this;
75
+ google.maps.event.addListener( this.map, 'click', function ( event )
 
 
 
 
 
76
  {
77
+ that.marker.setPosition( event.latLng );
78
+ that.updateCoordinate( event.latLng );
79
+ } );
80
+ google.maps.event.addListener( this.marker, 'drag', function ( event )
81
  {
82
+ that.updateCoordinate( event.latLng );
83
+ } );
 
84
 
85
+ this.$findButton.on( 'click', function()
86
+ {
87
+ that.geocodeAddress();
88
+ return false;
89
+ } );
90
+ },
91
 
92
+ // Autocomplete address
93
+ autocomplete: function()
94
  {
95
+ var that = this;
 
 
96
 
97
+ // No address field or more than 1 address fields, ignore
98
+ if ( !this.addressField || this.addressField.split( ',' ).length > 1 )
99
+ return;
 
 
 
 
 
100
 
101
+ $( '#' + this.addressField ).autocomplete( {
102
+ source: function( request, response )
 
 
103
  {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104
  // TODO: add 'region' option, to help bias geocoder.
105
+ that.geocoder.geocode( {
106
+ 'address': request.term
107
+ }, function( results )
108
+ {
109
+ response( $.map( results, function( item )
110
+ {
111
  return {
112
  label: item.formatted_address,
113
  value: item.formatted_address,
114
  latitude: item.geometry.location.lat(),
115
  longitude: item.geometry.location.lng()
116
  };
117
+ } ) );
118
+ } );
119
  },
120
+ select: function( event, ui )
121
+ {
122
+ var latLng = new google.maps.LatLng( ui.item.latitude, ui.item.longitude );
123
+
124
+ that.map.setCenter( latLng );
125
+ that.marker.setPosition( latLng );
126
+ that.updateCoordinate( latLng );
127
+ }
128
+ } );
129
+ },
130
+
131
+ // Update coordinate to input field
132
+ updateCoordinate: function( latLng )
 
 
 
133
  {
134
+ this.$coordinate.val( latLng.lat() + ',' + latLng.lng() );
135
+ },
 
136
 
137
+ // Find coordinates by address
138
+ geocodeAddress: function()
139
  {
140
+ var address = '',
141
+ fieldList = this.addressField.split( ',' ),
142
+ loop,
143
+ that = this;
144
 
145
+ for ( loop = 0; loop < fieldList.length; loop++ )
146
+ {
147
+ address += jQuery( '#' + fieldList[loop] ).val();
148
+ if ( loop+1 < fieldList.length )
149
+ {
150
+ address += ', ';
151
+ }
152
+ }
153
+ address = address.replace( /\n/g, ',' ).replace( /,,/g, ',' );
154
+
155
+ if ( !address )
156
+ return;
157
+
158
+ this.geocoder.geocode( {'address': address}, function( results, status )
159
+ {
160
+ if ( status !== google.maps.GeocoderStatus.OK )
161
+ return;
162
+
163
+ that.map.setCenter( results[0].geometry.location );
164
+ that.marker.setPosition( results[0].geometry.location );
165
+ that.updateCoordinate( results[0].geometry.location );
166
+ } );
167
+ },
168
+ };
169
 
170
+ $( function()
171
+ {
172
+ $( '.rwmb-map-field' ).each( function()
173
+ {
174
+ var field = new mapField( $( this ) );
175
+ field.init();
176
+ } );
177
+ } );
178
 
179
+ } )( jQuery );
meta-box.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Meta Box
4
  Plugin URI: http://www.deluxeblogtips.com/meta-box
5
  Description: Create meta box for editing pages in WordPress. Compatible with custom post types since WP 3.0
6
- Version: 4.3.1
7
  Author: Rilwis
8
  Author URI: http://www.deluxeblogtips.com
9
  License: GPL2+
@@ -13,7 +13,7 @@ License: GPL2+
13
  defined( 'ABSPATH' ) || exit;
14
 
15
  // Script version, used to add version for scripts and styles
16
- define( 'RWMB_VER', '4.3.1' );
17
 
18
  // Define plugin URLs, for fast enqueuing scripts and styles
19
  if ( ! defined( 'RWMB_URL' ) )
3
  Plugin Name: Meta Box
4
  Plugin URI: http://www.deluxeblogtips.com/meta-box
5
  Description: Create meta box for editing pages in WordPress. Compatible with custom post types since WP 3.0
6
+ Version: 4.3.2
7
  Author: Rilwis
8
  Author URI: http://www.deluxeblogtips.com
9
  License: GPL2+
13
  defined( 'ABSPATH' ) || exit;
14
 
15
  // Script version, used to add version for scripts and styles
16
+ define( 'RWMB_VER', '4.3.2' );
17
 
18
  // Define plugin URLs, for fast enqueuing scripts and styles
19
  if ( ! defined( 'RWMB_URL' ) )
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: rilwis, franz-josef-kaiser, Omnicia, funkedgeek, PerWiklander, rua
3
  Donate link: http://www.deluxeblogtips.com/donate
4
  Tags: meta-box, custom-fields, custom-field, meta, meta-boxes
5
  Requires at least: 3.3
6
- Tested up to: 3.5.1
7
- Stable tag: 4.3.1
8
 
9
  Meta Box plugin helps you easily implement multiple meta boxes in editing pages in WordPress. Works with custom post types and various field types.
10
 
@@ -71,6 +71,17 @@ To getting started with the plugin API, please read [this tutorial](http://www.d
71
 
72
  == Changelog ==
73
 
 
 
 
 
 
 
 
 
 
 
 
74
  = 4.3.1 =
75
  * Bug fix: fatal error if ASP open tag is allowed in php.ini
76
 
3
  Donate link: http://www.deluxeblogtips.com/donate
4
  Tags: meta-box, custom-fields, custom-field, meta, meta-boxes
5
  Requires at least: 3.3
6
+ Tested up to: 3.5.2
7
+ Stable tag: 4.3.2
8
 
9
  Meta Box plugin helps you easily implement multiple meta boxes in editing pages in WordPress. Works with custom post types and various field types.
10
 
71
 
72
  == Changelog ==
73
 
74
+ = 4.3.2 =
75
+ * Bug fix: allow to have more than 1 map on a page
76
+ * Bug fix: use HTTPS for Google Maps to work both in HTTP & HTTPS
77
+ * Bug fix: allow to clear all terms in taxonomy field
78
+ * Bug fix: "std" value for select fields is no longer "placeholder"
79
+ * Improvement: add "placeholder" param for select fields
80
+ * Improvement: add to helper function ability to show Google Maps in the front end. Check documentation for usage.
81
+ * Improvement: add spaces between radio inputs
82
+ * Improvement: add more params to "rwmb_meta" filter
83
+ * Improvement: using CSS animation for delete image
84
+
85
  = 4.3.1 =
86
  * Bug fix: fatal error if ASP open tag is allowed in php.ini
87