Version Description
Download this release
Release Info
Developer | Nikschavan |
Plugin | Lightweight Sidebar Manager |
Version | 1.0.0 |
Comparing to | |
See all releases |
Version 1.0.0
- classes/class-bsf-sb-loader.php +75 -0
- classes/class-bsf-sb-metabox.php +300 -0
- classes/class-bsf-sb-post-type.php +105 -0
- classes/class-bsf-sb-sidebar.php +153 -0
- classes/modules/target-rule/class-bsf-sb-rules-fields.php +860 -0
- classes/modules/target-rule/select2.css +1 -0
- classes/modules/target-rule/select2.js +5738 -0
- classes/modules/target-rule/target-rule.css +155 -0
- classes/modules/target-rule/target-rule.js +237 -0
- classes/modules/target-rule/user-role.js +75 -0
- readme.txt +49 -0
- sidebar-manager.php +14 -0
classes/class-bsf-sb-loader.php
ADDED
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* BSF_SB_Loader
|
4 |
+
*
|
5 |
+
* @package BSF Custom Sidebars
|
6 |
+
*/
|
7 |
+
|
8 |
+
if ( ! class_exists( 'BSF_SB_Loader' ) ) {
|
9 |
+
|
10 |
+
/**
|
11 |
+
* BSF_SB_Loader initial setup
|
12 |
+
*
|
13 |
+
* @since 1.0.0
|
14 |
+
*/
|
15 |
+
final class BSF_SB_Loader {
|
16 |
+
|
17 |
+
/**
|
18 |
+
* Member Variable
|
19 |
+
*
|
20 |
+
* @var instance
|
21 |
+
*/
|
22 |
+
private static $instance;
|
23 |
+
|
24 |
+
/**
|
25 |
+
* Initiator
|
26 |
+
*/
|
27 |
+
public static function get_instance() {
|
28 |
+
if ( ! isset( self::$instance ) ) {
|
29 |
+
self::$instance = new self;
|
30 |
+
}
|
31 |
+
return self::$instance;
|
32 |
+
}
|
33 |
+
|
34 |
+
/**
|
35 |
+
* Constructor
|
36 |
+
*/
|
37 |
+
public function __construct() {
|
38 |
+
$this->define_constants();
|
39 |
+
$this->load_files();
|
40 |
+
}
|
41 |
+
|
42 |
+
/**
|
43 |
+
* Define builder constants.
|
44 |
+
*
|
45 |
+
* @since 1.0.0
|
46 |
+
* @return void
|
47 |
+
*/
|
48 |
+
private function define_constants() {
|
49 |
+
define('BSF_SB_VER', '1.0.0');
|
50 |
+
define('BSF_SB_FILE', trailingslashit(dirname(dirname(__FILE__))) . 'sidebar-manager.php');
|
51 |
+
define('BSF_SB_DIR', plugin_dir_path(BSF_SB_FILE));
|
52 |
+
define('BSF_SB_URL', plugins_url('/', BSF_SB_FILE));
|
53 |
+
define('BSF_SB_PREFIX', 'bsf-sb');
|
54 |
+
define('BSF_SB_POST_TYPE', 'bsf-sidebar');
|
55 |
+
}
|
56 |
+
|
57 |
+
/**
|
58 |
+
* Loads classes and includes.
|
59 |
+
*
|
60 |
+
* @since 1.0.0
|
61 |
+
* @return void
|
62 |
+
*/
|
63 |
+
private function load_files() {
|
64 |
+
|
65 |
+
|
66 |
+
/* Classes */
|
67 |
+
require_once BSF_SB_DIR . 'classes/modules/target-rule/class-bsf-sb-rules-fields.php';
|
68 |
+
require_once BSF_SB_DIR . 'classes/class-bsf-sb-post-type.php';
|
69 |
+
require_once BSF_SB_DIR . 'classes/class-bsf-sb-sidebar.php';
|
70 |
+
require_once BSF_SB_DIR . 'classes/class-bsf-sb-metabox.php';
|
71 |
+
}
|
72 |
+
}
|
73 |
+
}
|
74 |
+
|
75 |
+
BSF_SB_Loader::get_instance();
|
classes/class-bsf-sb-metabox.php
ADDED
@@ -0,0 +1,300 @@
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* BSF_SB_Metabox
|
4 |
+
*
|
5 |
+
* @package BSF Custom Sidebars
|
6 |
+
*/
|
7 |
+
|
8 |
+
if ( ! class_exists( 'BSF_SB_Metabox' ) ) {
|
9 |
+
|
10 |
+
/**
|
11 |
+
* BSF_SB_Metabox initial setup
|
12 |
+
*
|
13 |
+
* @since 1.0.0
|
14 |
+
*/
|
15 |
+
final class BSF_SB_Metabox {
|
16 |
+
|
17 |
+
/**
|
18 |
+
* Member Variable
|
19 |
+
*
|
20 |
+
* @var instance
|
21 |
+
*/
|
22 |
+
private static $instance;
|
23 |
+
|
24 |
+
/**
|
25 |
+
* Initiator
|
26 |
+
*/
|
27 |
+
public static function get_instance() {
|
28 |
+
if ( ! isset( self::$instance ) ) {
|
29 |
+
self::$instance = new self;
|
30 |
+
}
|
31 |
+
return self::$instance;
|
32 |
+
}
|
33 |
+
|
34 |
+
/**
|
35 |
+
* Constructor
|
36 |
+
*/
|
37 |
+
public function __construct() {
|
38 |
+
/* Title filter */
|
39 |
+
add_filter( 'enter_title_here', array( $this, 'change_post_name_palceholder' ), 10, 1 );
|
40 |
+
|
41 |
+
/* Setup metabox */
|
42 |
+
add_action( 'admin_menu', array( $this, 'metabox_actions' ), 25 );
|
43 |
+
|
44 |
+
/* Save meta data */
|
45 |
+
add_action( 'save_post', array( $this, 'metabox_save' ), 10, 1 );
|
46 |
+
}
|
47 |
+
|
48 |
+
/**
|
49 |
+
* Replace sidebar metabox.
|
50 |
+
*
|
51 |
+
* @since 1.0.0
|
52 |
+
* @return void
|
53 |
+
*/
|
54 |
+
public function change_post_name_palceholder( $title ) {
|
55 |
+
if ( get_post_type() == BSF_SB_POST_TYPE ) {
|
56 |
+
$title = __( 'Enter sidebar title here', 'bsfsidebars' );
|
57 |
+
}
|
58 |
+
return $title;
|
59 |
+
}
|
60 |
+
|
61 |
+
/**
|
62 |
+
* Loads classes and includes.
|
63 |
+
*
|
64 |
+
* @since 1.0.0
|
65 |
+
* @return void
|
66 |
+
*/
|
67 |
+
public function metabox_actions() {
|
68 |
+
/* Remove the "Excerpt" meta box for the sidebars. */
|
69 |
+
remove_meta_box( 'postexcerpt', BSF_SB_POST_TYPE, 'normal' );
|
70 |
+
|
71 |
+
/* Target Rule */
|
72 |
+
add_meta_box( 'sidebar-settings', __( 'Sidebar Settings', 'bsfsidebars' ), array( $this, 'sidebar_settings' ), BSF_SB_POST_TYPE, 'normal', 'core' );
|
73 |
+
}
|
74 |
+
|
75 |
+
/**
|
76 |
+
* Replace sidebar metabox.
|
77 |
+
*
|
78 |
+
* @since 1.0.0
|
79 |
+
* @return void
|
80 |
+
*/
|
81 |
+
public function metabox_save( $post_id ) {
|
82 |
+
|
83 |
+
if ( get_post_type() != BSF_SB_POST_TYPE
|
84 |
+
|| ( isset( $_POST[ BSF_SB_POST_TYPE . '-nonce'] ) && ! wp_verify_nonce( $_POST[ BSF_SB_POST_TYPE . '-nonce'], BSF_SB_POST_TYPE ) )
|
85 |
+
) {
|
86 |
+
return $post_id;
|
87 |
+
}
|
88 |
+
|
89 |
+
// Verify if this is an auto save routine.
|
90 |
+
if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
|
91 |
+
return $post_id;
|
92 |
+
|
93 |
+
if ( ! current_user_can( 'edit_post', $post_id ) ) {
|
94 |
+
return $post_id;
|
95 |
+
}
|
96 |
+
|
97 |
+
$store_keys = array( 'bsf-sb-location', 'bsf-sb-exclusion' );
|
98 |
+
|
99 |
+
foreach ($store_keys as $key ) {
|
100 |
+
$meta_value = array();
|
101 |
+
if ( isset( $_POST[ $key ]['rule'] ) ) {
|
102 |
+
$_POST[ $key ]['rule'] = array_unique( $_POST[ $key ]['rule'] );
|
103 |
+
|
104 |
+
if ( isset( $_POST[ $key ]['specific'] ) ) {
|
105 |
+
$_POST[ $key ]['specific'] = array_unique( $_POST[ $key ]['specific'] );
|
106 |
+
}
|
107 |
+
|
108 |
+
// Unset the specifics from rule. This will be readded conditionally in next condition.
|
109 |
+
$index = array_search( '', $_POST[ $key ]['rule'] );
|
110 |
+
if ( false !== $index ) {
|
111 |
+
unset( $_POST[ $key ]['rule'][ $index ] );
|
112 |
+
}
|
113 |
+
$index = array_search( 'specifics', $_POST[ $key ]['rule'] );
|
114 |
+
if ( false !== $index ) {
|
115 |
+
unset( $_POST[ $key ]['rule'][ $index ] );
|
116 |
+
|
117 |
+
// Only re-add the specifics key if there are specific rules added.
|
118 |
+
if ( isset( $_POST[ $key ]['specific'] ) && is_array( $_POST[ $key ]['specific'] ) ) {
|
119 |
+
array_push( $_POST[ $key ]['rule'], 'specifics' );
|
120 |
+
}
|
121 |
+
}
|
122 |
+
|
123 |
+
foreach ( $_POST[ $key ] as $meta_key => $value ) {
|
124 |
+
$meta_value[ $meta_key ] = array_map( 'esc_attr', $value );
|
125 |
+
}
|
126 |
+
if ( ! in_array( 'specifics', $meta_value['rule'] ) ) {
|
127 |
+
$meta_value['specific'] = array();
|
128 |
+
}
|
129 |
+
if ( empty( $meta_value['rule'] ) ) {
|
130 |
+
$meta_value = array();
|
131 |
+
}
|
132 |
+
}
|
133 |
+
|
134 |
+
update_post_meta( $post_id, '_'.$key, $meta_value );
|
135 |
+
}
|
136 |
+
|
137 |
+
if ( isset( $_POST['bsf-sb-users'] ) ) {
|
138 |
+
update_post_meta( $post_id, '_bsf-sb-users', $_POST['bsf-sb-users'] );
|
139 |
+
}
|
140 |
+
|
141 |
+
if ( isset( $_POST['replace_this_sidebar'] ) ) {
|
142 |
+
|
143 |
+
$replace_sidebar = esc_attr( $_POST['replace_this_sidebar'] );
|
144 |
+
|
145 |
+
update_post_meta( $post_id, '_replace_this_sidebar', $replace_sidebar );
|
146 |
+
}
|
147 |
+
}
|
148 |
+
|
149 |
+
/**
|
150 |
+
* Target Rule.
|
151 |
+
*
|
152 |
+
* @since 1.0.0
|
153 |
+
* @return void
|
154 |
+
*/
|
155 |
+
public function sidebar_settings( $post ) {
|
156 |
+
|
157 |
+
$post_id = $post->ID;
|
158 |
+
|
159 |
+
$include_locations = get_post_meta( $post_id, '_bsf-sb-location', true );
|
160 |
+
$exclude_locations = get_post_meta( $post_id, '_bsf-sb-exclusion', true );
|
161 |
+
$users = get_post_meta( $post_id, '_bsf-sb-users', true );
|
162 |
+
$replace_sidebar = get_post_meta( $post_id, '_replace_this_sidebar', true );
|
163 |
+
|
164 |
+
/* Get Sidebars to show in replace list */
|
165 |
+
$sidebars = $this->show_sidebars_to_replace();
|
166 |
+
|
167 |
+
$out = wp_nonce_field( BSF_SB_POST_TYPE, BSF_SB_POST_TYPE . '-nonce', true, false );
|
168 |
+
$out .= '<table class="bsf-sb-table widefat">';
|
169 |
+
$out .= '<tbody>';
|
170 |
+
$out .= '<tr class="bsf-sb-row">';
|
171 |
+
$out .= '<td class="bsf-sb-row-heading">';
|
172 |
+
$out .= '<label>' . esc_html__( 'Sidebar To Replace', 'bsfsidebars' ) . '</label>';
|
173 |
+
$out .= '<i class="bsf-sb-help dashicons dashicons-editor-help" title="' . esc_attr__( 'Choose which sidebar you want to replace. Select None to disable this sidebar.', 'bsfsidebars' ) . '"></i>';
|
174 |
+
$out .= '</td>';
|
175 |
+
$out .= '<td class="bsf-sb-row-content">';
|
176 |
+
|
177 |
+
if ( !empty( $sidebars ) ) {
|
178 |
+
$out .= '<select name="replace_this_sidebar" class="widefat">';
|
179 |
+
$out .= '<option value=""' . selected( $replace_sidebar, '', false ) . '>' . __( 'None', 'bsfsidebars' ) . '</option>';
|
180 |
+
|
181 |
+
foreach ( $sidebars as $slug => $name ) {
|
182 |
+
if ( strrpos( $slug, BSF_SB_PREFIX ) !== false ) {
|
183 |
+
continue;
|
184 |
+
}
|
185 |
+
$out .= '<option value="' . $slug . '"' . selected( $replace_sidebar, $slug, false ) . '>' . $name . '</option>';
|
186 |
+
}
|
187 |
+
$out .= '</select>';
|
188 |
+
} else {
|
189 |
+
$out .= '<p>' . __( 'Sidebars are not available.', 'bsfsidebars' ) . '</p>';
|
190 |
+
}
|
191 |
+
|
192 |
+
$out .= '</td>';
|
193 |
+
$out .= '</tr>';
|
194 |
+
|
195 |
+
$out .= '<tr class="bsf-sb-row">';
|
196 |
+
$out .= '<td class="bsf-sb-row-heading">';
|
197 |
+
$out .= '<label>' . esc_html__( 'Description', 'bsfsidebars' ) . '</label>';
|
198 |
+
$out .= '<i class="bsf-sb-help dashicons dashicons-editor-help" title="' . esc_attr__( 'Add an optional description fot the Widgets screen.', 'bsfsidebars' ) . '"></i>';
|
199 |
+
$out .= '</td>';
|
200 |
+
$out .= '<td class="bsf-sb-row-content">';
|
201 |
+
$out .= '<input type="text" rows="1" name="excerpt" value="' . $post->post_excerpt . '">';
|
202 |
+
//$out .= '<textarea rows="1" name="excerpt">' . $post->post_excerpt . '</textarea>';
|
203 |
+
$out .= '</td>';
|
204 |
+
$out .= '</tr>';
|
205 |
+
|
206 |
+
$out .= '<tr class="bsf-sb-row">';
|
207 |
+
$out .= '<td class="bsf-sb-row-heading">';
|
208 |
+
$out .= '<label>' . esc_html__( 'Display On', 'bsfsidebars' ) . '</label>';
|
209 |
+
$out .= '<i class="bsf-sb-help dashicons dashicons-editor-help" title="' . esc_attr__( 'Add locations for where this sidebar should appear.', 'bsfsidebars' ) . '"></i>';
|
210 |
+
$out .= '</td>';
|
211 |
+
$out .= '<td class="bsf-sb-row-content">';
|
212 |
+
|
213 |
+
ob_start();
|
214 |
+
BSF_SB_Target_Rules_Fields::target_rule_settings_field(
|
215 |
+
'bsf-sb-location',
|
216 |
+
array(
|
217 |
+
'title' => __( 'Display Rules', 'bsfsidebars' ),
|
218 |
+
'value' => '[{"type":"basic-global","specific":null}]',
|
219 |
+
'tags' => 'site,enable,target,pages',
|
220 |
+
'rule_type' => 'display',
|
221 |
+
'add_rule_label' => __( 'Add Display Rule', 'bsfsidebars' ),
|
222 |
+
),
|
223 |
+
$include_locations
|
224 |
+
);
|
225 |
+
$out .= ob_get_clean();
|
226 |
+
$out .= '</td>';
|
227 |
+
$out .= '</tr>';
|
228 |
+
|
229 |
+
$out .= '<tr class="bsf-sb-row bsf-sb-hidden">';
|
230 |
+
$out .= '<td class="bsf-sb-row-heading">';
|
231 |
+
$out .= '<label>' . esc_html__( 'Do Not Display On', 'bsfsidebars' ) . '</label>';
|
232 |
+
$out .= '<i class="bsf-sb-help dashicons dashicons-editor-help" title="' . esc_attr__( 'This Sidebar will not appear at these locations.', 'bsfsidebars' ) . '"></i>';
|
233 |
+
$out .= '</td>';
|
234 |
+
$out .= '<td class="bsf-sb-row-content">';
|
235 |
+
ob_start();
|
236 |
+
BSF_SB_Target_Rules_Fields::target_rule_settings_field(
|
237 |
+
'bsf-sb-exclusion',
|
238 |
+
array(
|
239 |
+
'title' => __( 'Exclude On', 'bsfsidebars' ),
|
240 |
+
'value' => '[]',
|
241 |
+
'tags' => 'site,enable,target,pages',
|
242 |
+
'add_rule_label' => __( 'Add Excludion Rule', 'bsfsidebars' ),
|
243 |
+
'rule_type' => 'exclude',
|
244 |
+
),
|
245 |
+
$exclude_locations
|
246 |
+
);
|
247 |
+
$out .= ob_get_clean();
|
248 |
+
$out .= '</td>';
|
249 |
+
$out .= '</tr>';
|
250 |
+
|
251 |
+
$out .= '<tr class="bsf-sb-row">';
|
252 |
+
$out .= '<td class="bsf-sb-row-heading">';
|
253 |
+
$out .= '<label>' . esc_html__( 'User Roles', 'bsfsidebars' ) . '</label>';
|
254 |
+
$out .= '<i class="bsf-sb-help dashicons dashicons-editor-help" title="' . esc_attr__( 'Target header based on user role.', 'bsfsidebars' ) . '"></i>';
|
255 |
+
$out .= '</td>';
|
256 |
+
$out .= '<td class="bsf-sb-row-content">';
|
257 |
+
ob_start();
|
258 |
+
BSF_SB_Target_Rules_Fields::target_user_role_settings_field(
|
259 |
+
'bsf-sb-users',
|
260 |
+
array(
|
261 |
+
'title' => __( 'Users', 'convertpro' ),
|
262 |
+
'value' => '[]',
|
263 |
+
'tags' => 'site,enable,target,pages',
|
264 |
+
'add_rule_label' => __( 'Add User Rule', 'convertpro' ),
|
265 |
+
),
|
266 |
+
$users
|
267 |
+
);
|
268 |
+
$out .= ob_get_clean();
|
269 |
+
$out .= '</td>';
|
270 |
+
$out .= '</tr>';
|
271 |
+
$out .= '</tbody>';
|
272 |
+
$out .= '</table>';
|
273 |
+
|
274 |
+
echo $out;
|
275 |
+
}
|
276 |
+
|
277 |
+
/**
|
278 |
+
* Replace sidebar metabox.
|
279 |
+
*
|
280 |
+
* @since 1.0.0
|
281 |
+
* @return void
|
282 |
+
*/
|
283 |
+
public function show_sidebars_to_replace() {
|
284 |
+
global $wp_registered_sidebars;
|
285 |
+
|
286 |
+
$sidebars_show = array();
|
287 |
+
|
288 |
+
if ( is_array( $wp_registered_sidebars ) ) {
|
289 |
+
|
290 |
+
foreach( $wp_registered_sidebars as $slug => $data ) {
|
291 |
+
$sidebars_show[$slug] = $data['name'];
|
292 |
+
}
|
293 |
+
}
|
294 |
+
|
295 |
+
return $sidebars_show;
|
296 |
+
}
|
297 |
+
}
|
298 |
+
}
|
299 |
+
|
300 |
+
BSF_SB_Metabox::get_instance();
|
classes/class-bsf-sb-post-type.php
ADDED
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* BSF_SB_Post_Type
|
4 |
+
*
|
5 |
+
* @package BSF Custom Sidebars
|
6 |
+
*/
|
7 |
+
|
8 |
+
if ( ! class_exists( 'BSF_SB_Post_Type' ) ) {
|
9 |
+
|
10 |
+
/**
|
11 |
+
* BSF_SB_Post_Type initial setup
|
12 |
+
*
|
13 |
+
* @since 1.0.0
|
14 |
+
*/
|
15 |
+
final class BSF_SB_Post_Type {
|
16 |
+
|
17 |
+
/**
|
18 |
+
* Member Variable
|
19 |
+
*
|
20 |
+
* @var instance
|
21 |
+
*/
|
22 |
+
private static $instance;
|
23 |
+
|
24 |
+
/**
|
25 |
+
* Initiator
|
26 |
+
*/
|
27 |
+
public static function get_instance() {
|
28 |
+
if ( ! isset( self::$instance ) ) {
|
29 |
+
self::$instance = new self;
|
30 |
+
}
|
31 |
+
return self::$instance;
|
32 |
+
}
|
33 |
+
|
34 |
+
/**
|
35 |
+
* Constructor
|
36 |
+
*/
|
37 |
+
public function __construct() {
|
38 |
+
$this->load_actions();
|
39 |
+
}
|
40 |
+
|
41 |
+
/**
|
42 |
+
* Loads classes and includes.
|
43 |
+
*
|
44 |
+
* @since 1.0.0
|
45 |
+
* @return void
|
46 |
+
*/
|
47 |
+
private function load_actions() {
|
48 |
+
add_action( 'init', array( $this, 'register_post_type' ), 25 );
|
49 |
+
}
|
50 |
+
|
51 |
+
/**
|
52 |
+
* Register post-type for sidebars.
|
53 |
+
*
|
54 |
+
* @access public
|
55 |
+
* @return void
|
56 |
+
*/
|
57 |
+
public function register_post_type () {
|
58 |
+
/* Allow users who can edit theme. */
|
59 |
+
if ( ! current_user_can( 'edit_theme_options' ) ) {
|
60 |
+
return;
|
61 |
+
}
|
62 |
+
|
63 |
+
$singular = __( 'Sidebar', 'bsfsidebar' );
|
64 |
+
$plural = __( 'Sidebars', 'bsfsidebar' );
|
65 |
+
$rewrite = array( 'slug' => BSF_SB_POST_TYPE );
|
66 |
+
$supports = array( 'title', 'excerpt' );
|
67 |
+
|
68 |
+
$labels = array(
|
69 |
+
'name' => _x( 'Sidebars', 'post type general name', 'bsfsidebar' ),
|
70 |
+
'singular_name' => _x( 'Sidebar', 'post type singular name', 'bsfsidebar' ),
|
71 |
+
'menu_name' => _x( 'Sidebars', 'admin menu', 'bsfsidebar' ),
|
72 |
+
'add_new' => _x( 'Add New', BSF_SB_POST_TYPE, 'bsfsidebar' ),
|
73 |
+
'add_new_item' => sprintf( __( 'Add New %s', 'bsfsidebar' ), $singular ),
|
74 |
+
'edit_item' => sprintf( __( 'Edit %s', 'bsfsidebar' ), $singular ),
|
75 |
+
'new_item' => sprintf( __( 'New %s', 'bsfsidebar' ), $singular ),
|
76 |
+
'all_items' => $plural,
|
77 |
+
'view_item' => sprintf( __( 'View %s', 'bsfsidebar' ), $singular ),
|
78 |
+
'search_items' => sprintf( __( 'Search %a', 'bsfsidebar' ), $plural ),
|
79 |
+
'not_found' => sprintf( __( 'No %s Found', 'bsfsidebar' ), $plural ),
|
80 |
+
'not_found_in_trash' => sprintf( __( 'No %s Found In Trash', 'bsfsidebar' ), $plural ),
|
81 |
+
'parent_item_colon' => '',
|
82 |
+
|
83 |
+
);
|
84 |
+
$args = array(
|
85 |
+
'labels' => $labels,
|
86 |
+
'public' => false,
|
87 |
+
'publicly_queryable' => true,
|
88 |
+
'show_ui' => true,
|
89 |
+
'show_in_nav_menus' => false,
|
90 |
+
'show_in_admin_bar' => false,
|
91 |
+
'show_in_menu' => 'themes.php',
|
92 |
+
'query_var' => true,
|
93 |
+
'rewrite' => $rewrite,
|
94 |
+
'capability_type' => 'post',
|
95 |
+
'has_archive' => BSF_SB_POST_TYPE,
|
96 |
+
'hierarchical' => false,
|
97 |
+
'menu_position' => null,
|
98 |
+
'supports' => $supports
|
99 |
+
);
|
100 |
+
register_post_type( BSF_SB_POST_TYPE, $args );
|
101 |
+
}
|
102 |
+
}
|
103 |
+
}
|
104 |
+
|
105 |
+
BSF_SB_Post_Type::get_instance();
|
classes/class-bsf-sb-sidebar.php
ADDED
@@ -0,0 +1,153 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* BSF_SB_Sidebar
|
4 |
+
*
|
5 |
+
* @package BSF Custom Sidebars
|
6 |
+
*/
|
7 |
+
|
8 |
+
if ( ! class_exists( 'BSF_SB_Sidebar' ) ) {
|
9 |
+
|
10 |
+
/**
|
11 |
+
* BSF_SB_Sidebar initial setup
|
12 |
+
*
|
13 |
+
* @since 1.0.0
|
14 |
+
*/
|
15 |
+
final class BSF_SB_Sidebar {
|
16 |
+
|
17 |
+
/**
|
18 |
+
* Member Variable
|
19 |
+
*
|
20 |
+
* @var instance
|
21 |
+
*/
|
22 |
+
private static $instance;
|
23 |
+
|
24 |
+
/**
|
25 |
+
* Member Variable
|
26 |
+
*
|
27 |
+
* @var instance
|
28 |
+
*/
|
29 |
+
private static $global_sidebar = null;
|
30 |
+
|
31 |
+
/**
|
32 |
+
* Initiator
|
33 |
+
*/
|
34 |
+
public static function get_instance() {
|
35 |
+
if ( ! isset( self::$instance ) ) {
|
36 |
+
self::$instance = new self;
|
37 |
+
}
|
38 |
+
return self::$instance;
|
39 |
+
}
|
40 |
+
|
41 |
+
/**
|
42 |
+
* Constructor
|
43 |
+
*/
|
44 |
+
public function __construct() {
|
45 |
+
$this->load_actions();
|
46 |
+
}
|
47 |
+
|
48 |
+
/**
|
49 |
+
* Loads classes and includes.
|
50 |
+
*
|
51 |
+
* @since 1.0.0
|
52 |
+
* @return void
|
53 |
+
*/
|
54 |
+
private function load_actions() {
|
55 |
+
/* Register Sidebars */
|
56 |
+
add_action( 'widgets_init', array( $this, 'register_sidebars' ) );
|
57 |
+
|
58 |
+
/* Init Sidebars */
|
59 |
+
add_action( 'get_header', array( $this, 'init_replace_sidebar' ) );
|
60 |
+
}
|
61 |
+
|
62 |
+
/**
|
63 |
+
* Register sidebars.
|
64 |
+
*
|
65 |
+
* @access public
|
66 |
+
* @return void
|
67 |
+
*/
|
68 |
+
public function register_sidebars() {
|
69 |
+
|
70 |
+
$to_register = get_posts( array( 'post_type' => BSF_SB_POST_TYPE, 'posts_per_page' => -1, 'suppress_filters' => 'false' ) );
|
71 |
+
|
72 |
+
if ( !empty( $to_register ) ) {
|
73 |
+
foreach ( $to_register as $index => $data ) {
|
74 |
+
|
75 |
+
register_sidebar( array(
|
76 |
+
'name' => $data->post_title,
|
77 |
+
'id' => BSF_SB_PREFIX . '-' . $data->post_name,
|
78 |
+
'description' => $data->post_excerpt
|
79 |
+
) );
|
80 |
+
}
|
81 |
+
}
|
82 |
+
}
|
83 |
+
|
84 |
+
/**
|
85 |
+
* Init Replace Sidebars.
|
86 |
+
*
|
87 |
+
* @access public
|
88 |
+
* @return void
|
89 |
+
*/
|
90 |
+
public function init_replace_sidebar() {
|
91 |
+
/* Replace Sidebars */
|
92 |
+
add_filter( 'sidebars_widgets', array( $this, 'replace_sidebars' ), 10, 1 );
|
93 |
+
}
|
94 |
+
|
95 |
+
/**
|
96 |
+
* Replace Sidebars.
|
97 |
+
*
|
98 |
+
* @access public
|
99 |
+
* @return void
|
100 |
+
*/
|
101 |
+
public function replace_sidebars( $sidebars ) {
|
102 |
+
if ( !is_admin() ) {
|
103 |
+
|
104 |
+
if ( NULL === self::$global_sidebar ) {
|
105 |
+
global $post;
|
106 |
+
|
107 |
+
$args = array(
|
108 |
+
'post_type' => BSF_SB_POST_TYPE,
|
109 |
+
'posts_per_page' => -1,
|
110 |
+
'suppress_filters' => false,
|
111 |
+
'meta_query' => array(
|
112 |
+
array(
|
113 |
+
'key' => '_replace_this_sidebar',
|
114 |
+
'compare' => '!=',
|
115 |
+
'value' => ''
|
116 |
+
)
|
117 |
+
)
|
118 |
+
);
|
119 |
+
|
120 |
+
$replace_sidebars = get_posts( $args );
|
121 |
+
|
122 |
+
if ( !empty( $replace_sidebars ) ) {
|
123 |
+
|
124 |
+
foreach ( $replace_sidebars as $i => $data ) {
|
125 |
+
|
126 |
+
$post_replace_sidebar = get_post_meta( $data->ID, '_replace_this_sidebar', true );
|
127 |
+
$sidebar_id = BSF_SB_PREFIX . '-' . $data->post_name;
|
128 |
+
|
129 |
+
if ( isset( $sidebars[ $post_replace_sidebar ] ) && isset( $sidebars[ $sidebar_id ] ) ) {
|
130 |
+
|
131 |
+
$is_show = BSF_SB_Target_Rules_Fields::get_instance()->get_current_layout( $data->ID );
|
132 |
+
|
133 |
+
if ( false !== $is_show ) {
|
134 |
+
$sidebars[ $post_replace_sidebar ] = $sidebars[ $sidebar_id ];
|
135 |
+
unset( $sidebars[ $sidebar_id ] );
|
136 |
+
}
|
137 |
+
}
|
138 |
+
}
|
139 |
+
|
140 |
+
self::$global_sidebar = $sidebars;
|
141 |
+
}
|
142 |
+
}else{
|
143 |
+
|
144 |
+
$sidebars = self::$global_sidebar;
|
145 |
+
}
|
146 |
+
}
|
147 |
+
|
148 |
+
return $sidebars;
|
149 |
+
}
|
150 |
+
}
|
151 |
+
}
|
152 |
+
|
153 |
+
BSF_SB_Sidebar::get_instance();
|
classes/modules/target-rule/class-bsf-sb-rules-fields.php
ADDED
@@ -0,0 +1,860 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* BSF_SB_Target_Rules_Fields
|
4 |
+
*
|
5 |
+
* @package BSF Custom Sidebars
|
6 |
+
*/
|
7 |
+
|
8 |
+
/**
|
9 |
+
* Meta Boxes setup
|
10 |
+
*/
|
11 |
+
if ( ! class_exists( 'BSF_SB_Target_Rules_Fields' ) ) {
|
12 |
+
|
13 |
+
/**
|
14 |
+
* Meta Boxes setup
|
15 |
+
*/
|
16 |
+
class BSF_SB_Target_Rules_Fields {
|
17 |
+
|
18 |
+
|
19 |
+
/**
|
20 |
+
* Instance
|
21 |
+
*
|
22 |
+
* @since 1.0.0
|
23 |
+
*
|
24 |
+
* @var $instance
|
25 |
+
*/
|
26 |
+
private static $instance;
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Meta Option
|
30 |
+
*
|
31 |
+
* @since 1.0.0
|
32 |
+
*
|
33 |
+
* @var $meta_option
|
34 |
+
*/
|
35 |
+
private static $meta_option;
|
36 |
+
|
37 |
+
/**
|
38 |
+
* Initiator
|
39 |
+
*
|
40 |
+
* @since 1.0.0
|
41 |
+
*/
|
42 |
+
public static function get_instance() {
|
43 |
+
if ( ! isset( self::$instance ) ) {
|
44 |
+
self::$instance = new self;
|
45 |
+
}
|
46 |
+
|
47 |
+
return self::$instance;
|
48 |
+
}
|
49 |
+
|
50 |
+
/**
|
51 |
+
* Constructor
|
52 |
+
*
|
53 |
+
* @since 1.0.0
|
54 |
+
*/
|
55 |
+
public function __construct() {
|
56 |
+
add_action( 'admin_enqueue_scripts', array( $this, 'admin_styles' ) );
|
57 |
+
add_action( 'wp_ajax_bsf_sb_get_posts_by_query', array( $this, 'get_posts_by_query' ) );
|
58 |
+
}
|
59 |
+
|
60 |
+
/**
|
61 |
+
* Ajax handeler to return the posts based on the search query.
|
62 |
+
* When searching for the post/pages only titles are searched for.
|
63 |
+
*
|
64 |
+
* @since 1.0.0
|
65 |
+
*/
|
66 |
+
function get_posts_by_query() {
|
67 |
+
|
68 |
+
$search_string = isset( $_POST['q'] ) ? sanitize_text_field( $_POST['q'] ) : '';
|
69 |
+
$data = array();
|
70 |
+
$result = array();
|
71 |
+
|
72 |
+
$args = array(
|
73 |
+
'public' => true,
|
74 |
+
'_builtin' => false,
|
75 |
+
);
|
76 |
+
|
77 |
+
$output = 'names'; // names or objects, note names is the default.
|
78 |
+
$operator = 'and'; // 'and' or 'or'.
|
79 |
+
$post_types = get_post_types( $args, $output, $operator );
|
80 |
+
|
81 |
+
$post_types['Posts'] = 'post';
|
82 |
+
$post_types['Pages'] = 'page';
|
83 |
+
|
84 |
+
foreach ( $post_types as $key => $post_type ) {
|
85 |
+
|
86 |
+
$data = array();
|
87 |
+
|
88 |
+
add_filter( 'posts_search', array( $this, 'search_only_titles' ), 10, 2 );
|
89 |
+
|
90 |
+
$query = new WP_Query(
|
91 |
+
array(
|
92 |
+
's' => $search_string,
|
93 |
+
'post_type' => $post_type,
|
94 |
+
'posts_per_page' => - 1,
|
95 |
+
)
|
96 |
+
);
|
97 |
+
|
98 |
+
if ( $query->have_posts() ) {
|
99 |
+
while ( $query->have_posts() ) {
|
100 |
+
$query->the_post();
|
101 |
+
$title = get_the_title();
|
102 |
+
$title .= ( 0 != $query->post->post_parent ) ? ' (' . get_the_title( $query->post->post_parent ) . ')' : '';
|
103 |
+
$id = get_the_id();
|
104 |
+
$data[] = array(
|
105 |
+
'id' => 'post-' . $id,
|
106 |
+
'text' => $title,
|
107 |
+
);
|
108 |
+
}
|
109 |
+
}
|
110 |
+
|
111 |
+
if ( is_array( $data ) && ! empty( $data ) ) {
|
112 |
+
$result[] = array(
|
113 |
+
'text' => $key,
|
114 |
+
'children' => $data,
|
115 |
+
);
|
116 |
+
}
|
117 |
+
}
|
118 |
+
|
119 |
+
$data = array();
|
120 |
+
|
121 |
+
wp_reset_postdata();
|
122 |
+
|
123 |
+
$args = array(
|
124 |
+
'public' => true,
|
125 |
+
);
|
126 |
+
|
127 |
+
$output = 'objects'; // names or objects, note names is the default.
|
128 |
+
$operator = 'and'; // 'and' or 'or'.
|
129 |
+
$taxonomies = get_taxonomies( $args, $output, $operator );
|
130 |
+
|
131 |
+
foreach ( $taxonomies as $taxonomy ) {
|
132 |
+
$terms = get_terms(
|
133 |
+
$taxonomy->name, array(
|
134 |
+
'orderby' => 'count',
|
135 |
+
'hide_empty' => 0,
|
136 |
+
'name__like' => $search_string,
|
137 |
+
)
|
138 |
+
);
|
139 |
+
|
140 |
+
$data = array();
|
141 |
+
|
142 |
+
$label = ucwords( $taxonomy->label );
|
143 |
+
|
144 |
+
if ( ! empty( $terms ) ) {
|
145 |
+
|
146 |
+
foreach ( $terms as $term ) {
|
147 |
+
|
148 |
+
$data[] = array(
|
149 |
+
'id' => 'tax-' . $term->term_id,
|
150 |
+
'text' => $term->name,
|
151 |
+
);
|
152 |
+
|
153 |
+
}
|
154 |
+
}
|
155 |
+
|
156 |
+
if ( is_array( $data ) && ! empty( $data ) ) {
|
157 |
+
$result[] = array(
|
158 |
+
'text' => $label,
|
159 |
+
'children' => $data,
|
160 |
+
);
|
161 |
+
}
|
162 |
+
}
|
163 |
+
|
164 |
+
// return the result in json.
|
165 |
+
wp_send_json( $result );
|
166 |
+
}
|
167 |
+
|
168 |
+
/**
|
169 |
+
* Return search results only by post title.
|
170 |
+
* This is only run from get_posts_by_query()
|
171 |
+
*
|
172 |
+
* @param (string) $search Search SQL for WHERE clause.
|
173 |
+
* @param (WP_Query) $wp_query The current WP_Query object.
|
174 |
+
*
|
175 |
+
* @return (string) The Modified Search SQL for WHERE clause.
|
176 |
+
*/
|
177 |
+
function search_only_titles( $search, $wp_query ) {
|
178 |
+
if ( ! empty( $search ) && ! empty( $wp_query->query_vars['search_terms'] ) ) {
|
179 |
+
global $wpdb;
|
180 |
+
|
181 |
+
$q = $wp_query->query_vars;
|
182 |
+
$n = ! empty( $q['exact'] ) ? '' : '%';
|
183 |
+
|
184 |
+
$search = array();
|
185 |
+
|
186 |
+
foreach ( (array) $q['search_terms'] as $term ) {
|
187 |
+
$search[] = $wpdb->prepare( "$wpdb->posts.post_title LIKE %s", $n . $wpdb->esc_like( $term ) . $n );
|
188 |
+
}
|
189 |
+
|
190 |
+
if ( ! is_user_logged_in() ) {
|
191 |
+
$search[] = "$wpdb->posts.post_password = ''";
|
192 |
+
}
|
193 |
+
|
194 |
+
$search = ' AND ' . implode( ' AND ', $search );
|
195 |
+
}
|
196 |
+
|
197 |
+
return $search;
|
198 |
+
}
|
199 |
+
|
200 |
+
/**
|
201 |
+
* Function Name: admin_styles.
|
202 |
+
* Function Description: admin_styles.
|
203 |
+
*
|
204 |
+
* @param string $hook string parameter.
|
205 |
+
*/
|
206 |
+
public function admin_styles( $hook ) {
|
207 |
+
|
208 |
+
if ( false !== strrpos( $hook, 'post' ) && 'bsf-sidebar' == get_post_type() ) {
|
209 |
+
|
210 |
+
wp_enqueue_script( 'bsf-sb-select2', BSF_SB_URL . 'classes/modules/target-rule/select2.js', array( 'jquery' ), BSF_SB_VER, true );
|
211 |
+
wp_enqueue_script(
|
212 |
+
'bsf-sb-target-rule', BSF_SB_URL . 'classes/modules/target-rule/target-rule.js', array(
|
213 |
+
'jquery',
|
214 |
+
'wp-util',
|
215 |
+
'bsf-sb-select2',
|
216 |
+
), BSF_SB_VER, true
|
217 |
+
);
|
218 |
+
wp_enqueue_script(
|
219 |
+
'bsf-sb-user-role', BSF_SB_URL . 'classes/modules/target-rule/user-role.js', array(
|
220 |
+
'jquery',
|
221 |
+
), BSF_SB_VER, true
|
222 |
+
);
|
223 |
+
wp_enqueue_style( 'bsf-sb-select2', BSF_SB_URL . 'classes/modules/target-rule/select2.css', '', BSF_SB_VER );
|
224 |
+
wp_enqueue_style( 'bsf-sb-target-rule', BSF_SB_URL . 'classes/modules/target-rule/target-rule.css', '', BSF_SB_VER );
|
225 |
+
}
|
226 |
+
|
227 |
+
}
|
228 |
+
|
229 |
+
/**
|
230 |
+
* Function Name: target_rule_settings_field.
|
231 |
+
* Function Description: Function to handle new input type.
|
232 |
+
*
|
233 |
+
* @param string $name string parameter.
|
234 |
+
* @param string $settings string parameter.
|
235 |
+
* @param string $value string parameter.
|
236 |
+
*/
|
237 |
+
public static function target_rule_settings_field( $name, $settings, $value ) {
|
238 |
+
$input_name = $name;
|
239 |
+
$type = isset( $settings['type'] ) ? $settings['type'] : 'target_rule';
|
240 |
+
$class = isset( $settings['class'] ) ? $settings['class'] : '';
|
241 |
+
$rule_type = isset( $settings['rule_type'] ) ? $settings['rule_type'] : 'target_rule';
|
242 |
+
$add_rule_label = isset( $settings['add_rule_label'] ) ? $settings['add_rule_label'] : __( 'Add Rule', 'bsfsidebars' );
|
243 |
+
$saved_values = $value;
|
244 |
+
$output = '';
|
245 |
+
|
246 |
+
$args = array(
|
247 |
+
'public' => true,
|
248 |
+
'_builtin' => true,
|
249 |
+
);
|
250 |
+
|
251 |
+
$builtin_post_types = get_post_types( $args, 'objects' );
|
252 |
+
unset( $builtin_post_types['attachment'] );
|
253 |
+
$builtin_taxonomies = get_taxonomies( $args, 'objects' );
|
254 |
+
unset( $builtin_taxonomies['post_format'] );
|
255 |
+
|
256 |
+
$args = array(
|
257 |
+
'public' => true,
|
258 |
+
'_builtin' => false,
|
259 |
+
);
|
260 |
+
|
261 |
+
$custom_post_type = get_post_types( $args, 'objects' );
|
262 |
+
$custom_taxonomies = get_taxonomies( $args, 'objects' );
|
263 |
+
|
264 |
+
$selection_options = array(
|
265 |
+
'basic' => array(
|
266 |
+
'label' => __( 'Basic', 'bsfsidebars' ),
|
267 |
+
'value' => array(
|
268 |
+
'basic-global' => __( 'Entire Website', 'bsfsidebars' ),
|
269 |
+
'basic-singulars' => __( 'All Singulars', 'bsfsidebars' ),
|
270 |
+
'basic-archives' => __( 'All Archives', 'bsfsidebars' ),
|
271 |
+
),
|
272 |
+
),
|
273 |
+
|
274 |
+
'special-pages' => array(
|
275 |
+
'label' => __( 'Special Pages', 'bsfsidebars' ),
|
276 |
+
'value' => array(
|
277 |
+
'special-404' => __( '404 Page', 'bsfsidebars' ),
|
278 |
+
'special-search' => __( 'Search Page', 'bsfsidebars' ),
|
279 |
+
'special-blog' => __( 'Blog / Posts Page', 'bsfsidebars' ),
|
280 |
+
'special-front' => __( 'Front Page', 'bsfsidebars' ),
|
281 |
+
'special-date' => __( 'Date Archive', 'bsfsidebars' ),
|
282 |
+
'special-author' => __( 'Author Archive', 'bsfsidebars' ),
|
283 |
+
),
|
284 |
+
),
|
285 |
+
);
|
286 |
+
|
287 |
+
/* Builtin post types */
|
288 |
+
foreach ( $builtin_post_types as $post_type ) {
|
289 |
+
|
290 |
+
$post_opt = self::get_post_target_rule_options( $post_type, $builtin_taxonomies );
|
291 |
+
|
292 |
+
$selection_options[ $post_opt['post_key'] ] = array(
|
293 |
+
'label' => $post_opt['label'],
|
294 |
+
'value' => $post_opt['value'],
|
295 |
+
);
|
296 |
+
}
|
297 |
+
|
298 |
+
/* Custom post types */
|
299 |
+
foreach ( $custom_post_type as $c_post_type ) {
|
300 |
+
$post_opt = self::get_post_target_rule_options( $c_post_type, $custom_taxonomies );
|
301 |
+
|
302 |
+
$selection_options[ $post_opt['post_key'] ] = array(
|
303 |
+
'label' => $post_opt['label'],
|
304 |
+
'value' => $post_opt['value'],
|
305 |
+
);
|
306 |
+
}
|
307 |
+
|
308 |
+
$selection_options['specific-target'] = array(
|
309 |
+
'label' => __( 'Specific Target', 'bsfsidebars' ),
|
310 |
+
'value' => array(
|
311 |
+
'specifics' => __( 'Specific Pages / Posts / Taxanomies, etc.', 'bsfsidebars' ),
|
312 |
+
),
|
313 |
+
);
|
314 |
+
|
315 |
+
/* WP Template Format */
|
316 |
+
$output .= '<script type="text/html" id="tmpl-bsf-sb-target-rule-' . $rule_type . '-condition">';
|
317 |
+
$output .= '<div class="bsf-sb-target-rule-condition bsf-sb-target-rule-{{data.id}}" data-rule="{{data.id}}" >';
|
318 |
+
$output .= '<span class="target_rule-condition-delete dashicons dashicons-dismiss"></span>';
|
319 |
+
/* Condition Selection */
|
320 |
+
$output .= '<div class="target_rule-condition-wrap" >';
|
321 |
+
$output .= '<select name="' . esc_attr( $input_name ) . '[rule][{{data.id}}]" class="target_rule-condition form-control bsf-sb-input">';
|
322 |
+
$output .= '<option value="">' . __( 'Select', 'bsfsidebars' ) . '</option>';
|
323 |
+
|
324 |
+
foreach ( $selection_options as $group => $group_data ) {
|
325 |
+
|
326 |
+
$output .= '<optgroup label="' . $group_data['label'] . '">';
|
327 |
+
foreach ( $group_data['value'] as $opt_key => $opt_value ) {
|
328 |
+
$output .= '<option value="' . $opt_key . '">' . $opt_value . '</option>';
|
329 |
+
}
|
330 |
+
$output .= '</optgroup>';
|
331 |
+
}
|
332 |
+
$output .= '</select>';
|
333 |
+
$output .= '</div>';
|
334 |
+
|
335 |
+
$output .= '</div> <!-- bsf-sb-target-rule-condition -->';
|
336 |
+
|
337 |
+
/* Specific page selection */
|
338 |
+
$output .= '<div class="target_rule-specific-page-wrap" style="display:none">';
|
339 |
+
$output .= '<select name="' . esc_attr( $input_name ) . '[specific][]" class="target-rule-select2 target_rule-specific-page form-control bsf-sb-input " multiple="multiple">';
|
340 |
+
$output .= '</select>';
|
341 |
+
$output .= '</div>';
|
342 |
+
|
343 |
+
$output .= '</script>';
|
344 |
+
|
345 |
+
/* Wrapper Start */
|
346 |
+
$output .= '<div class="bsf-sb-target-rule-wrapper bsf-sb-target-rule-' . $rule_type . '-on-wrap" data-type="' . $rule_type . '">';
|
347 |
+
// $output .= '<input type="hidden" class="form-control bsf-sb-input bsf-sb-target_rule-input" name="' . esc_attr( $input_name ) . '" value=' . $value . ' />';
|
348 |
+
$output .= '<div class="bsf-sb-target-rule-selector-wrapper bsf-sb-target-rule-' . $rule_type . '-on">';
|
349 |
+
$output .= self::generate_target_rule_selector( $rule_type, $selection_options, $input_name, $saved_values, $add_rule_label );
|
350 |
+
$output .= '</div>';
|
351 |
+
|
352 |
+
/* Wrapper end */
|
353 |
+
$output .= '</div>';
|
354 |
+
|
355 |
+
echo $output;
|
356 |
+
}
|
357 |
+
|
358 |
+
/**
|
359 |
+
* Get target rules for generating the markup for rule selector.
|
360 |
+
*
|
361 |
+
* @since 1.0.0
|
362 |
+
*
|
363 |
+
* @param object $post_type post type parameter.
|
364 |
+
* @param object $taxonomies Taxanomies for creating the target rule markup.
|
365 |
+
*/
|
366 |
+
public static function get_post_target_rule_options( $post_type, $taxonomies ) {
|
367 |
+
|
368 |
+
$post_key = str_replace( ' ', '-', strtolower( $post_type->label ) );
|
369 |
+
$post_label = ucwords( $post_type->label );
|
370 |
+
$post_name = $post_type->name;
|
371 |
+
$post_option = array();
|
372 |
+
|
373 |
+
/* translators: %s percentage */
|
374 |
+
$all_posts = sprintf( __( 'All %s', 'bsfsidebars' ), $post_label );
|
375 |
+
/* translators: %s percentage */
|
376 |
+
$all_archive = sprintf( __( 'All %s Archive', 'bsfsidebars' ), $post_label );
|
377 |
+
|
378 |
+
$post_option[ $post_name . '|all' ] = $all_posts;
|
379 |
+
$post_option[ $post_name . '|all|archive' ] = $all_archive;
|
380 |
+
|
381 |
+
foreach ( $taxonomies as $taxonomy ) {
|
382 |
+
$tax_label = ucwords( $taxonomy->label );
|
383 |
+
$tax_name = $taxonomy->name;
|
384 |
+
|
385 |
+
/* translators: %s percentage */
|
386 |
+
$tax_archive = sprintf( __( 'All %s Archive', 'bsfsidebars' ), $tax_label );
|
387 |
+
|
388 |
+
$post_option[ $post_name . '|all|taxarchive|' . $tax_name ] = $tax_archive;
|
389 |
+
}
|
390 |
+
|
391 |
+
$post_output['post_key'] = $post_key;
|
392 |
+
$post_output['label'] = $post_label;
|
393 |
+
$post_output['value'] = $post_option;
|
394 |
+
|
395 |
+
return $post_output;
|
396 |
+
}
|
397 |
+
|
398 |
+
/**
|
399 |
+
* Generate markup for rendering the location selction.
|
400 |
+
*
|
401 |
+
* @since 1.0.0
|
402 |
+
* @param String $type Rule type display|exclude.
|
403 |
+
* @param Array $selection_options Array for available selection fields.
|
404 |
+
* @param String $input_name Input name for the settings.
|
405 |
+
* @param Array $saved_values Array of saved valued.
|
406 |
+
* @param String $add_rule_label Label for the Add rule button.
|
407 |
+
*
|
408 |
+
* @return HTML Markup for for the location settings.
|
409 |
+
*/
|
410 |
+
public static function generate_target_rule_selector( $type, $selection_options, $input_name, $saved_values, $add_rule_label ) {
|
411 |
+
|
412 |
+
$output = '<div class="target_rule-builder-wrap">';
|
413 |
+
|
414 |
+
if ( ! is_array( $saved_values ) || ( is_array( $saved_values ) && empty( $saved_values ) ) ) {
|
415 |
+
$saved_values = array();
|
416 |
+
$saved_values['rule'][0] = '';
|
417 |
+
$saved_values['specific'][0] = '';
|
418 |
+
}
|
419 |
+
|
420 |
+
$index = 0;
|
421 |
+
|
422 |
+
foreach ( $saved_values['rule'] as $index => $data ) {
|
423 |
+
|
424 |
+
$output .= '<div class="bsf-sb-target-rule-condition bsf-sb-target-rule-' . $index . '" data-rule="' . $index . '" >';
|
425 |
+
/* Condition Selection */
|
426 |
+
$output .= '<span class="target_rule-condition-delete dashicons dashicons-dismiss"></span>';
|
427 |
+
$output .= '<div class="target_rule-condition-wrap" >';
|
428 |
+
$output .= '<select name="' . esc_attr( $input_name ) . '[rule][' . $index . ']" class="target_rule-condition form-control bsf-sb-input">';
|
429 |
+
$output .= '<option value="">' . __( 'Select', 'bsfsidebars' ) . '</option>';
|
430 |
+
|
431 |
+
foreach ( $selection_options as $group => $group_data ) {
|
432 |
+
|
433 |
+
$output .= '<optgroup label="' . $group_data['label'] . '">';
|
434 |
+
foreach ( $group_data['value'] as $opt_key => $opt_value ) {
|
435 |
+
|
436 |
+
// specific rules.
|
437 |
+
$selected = '';
|
438 |
+
|
439 |
+
if ( $data == $opt_key ) {
|
440 |
+
$selected = 'selected="selected"';
|
441 |
+
}
|
442 |
+
|
443 |
+
$output .= '<option value="' . $opt_key . '" ' . $selected . '>' . $opt_value . '</option>';
|
444 |
+
}
|
445 |
+
$output .= '</optgroup>';
|
446 |
+
}
|
447 |
+
$output .= '</select>';
|
448 |
+
$output .= '</div>';
|
449 |
+
|
450 |
+
$output .= '</div>';
|
451 |
+
|
452 |
+
if ( 'specifics' != $data ) {
|
453 |
+
/* Specific page selection */
|
454 |
+
$output .= '<div class="target_rule-specific-page-wrap" style="display:none">';
|
455 |
+
$output .= '<select name="' . esc_attr( $input_name ) . '[specific][]" class="target-rule-select2 target_rule-specific-page form-control bsf-sb-input " multiple="multiple">';
|
456 |
+
$output .= '</select>';
|
457 |
+
$output .= '</div>';
|
458 |
+
}
|
459 |
+
}
|
460 |
+
|
461 |
+
/* Specific page selection */
|
462 |
+
$output .= '<div class="target_rule-specific-page-wrap" style="display:none">';
|
463 |
+
$output .= '<select name="' . esc_attr( $input_name ) . '[specific][]" class="target-rule-select2 target_rule-specific-page form-control bsf-sb-input " multiple="multiple">';
|
464 |
+
|
465 |
+
if ( isset( $saved_values['specific'] ) && null != $saved_values['specific'] && is_array( $saved_values['specific'] ) ) {
|
466 |
+
|
467 |
+
foreach ( $saved_values['specific'] as $data_key => $sel_value ) {
|
468 |
+
// posts.
|
469 |
+
if ( strpos( $sel_value, 'post-' ) !== false ) {
|
470 |
+
$post_id = (int) str_replace( 'post-', '', $sel_value );
|
471 |
+
$post_title = get_the_title( $post_id );
|
472 |
+
$output .= '<option value="post-' . $post_id . '" selected="selected" >' . $post_title . '</option>';
|
473 |
+
}
|
474 |
+
|
475 |
+
// taxonomy options.
|
476 |
+
if ( strpos( $sel_value, 'tax-' ) !== false ) {
|
477 |
+
$tax_id = (int) str_replace( 'tax-', '', $sel_value );
|
478 |
+
$term = get_term( $tax_id );
|
479 |
+
$term_taxonomy = ucfirst( str_replace( '_', ' ', $term->taxonomy ) );
|
480 |
+
$output .= '<option value="tax-' . $tax_id . '" selected="selected" >' . $term->name . ' - ' . $term_taxonomy . '</option>';
|
481 |
+
|
482 |
+
}
|
483 |
+
}
|
484 |
+
}
|
485 |
+
$output .= '</select>';
|
486 |
+
$output .= '</div>';
|
487 |
+
|
488 |
+
$output .= '</div>';
|
489 |
+
|
490 |
+
/* Add new rule */
|
491 |
+
$output .= '<div class="target_rule-add-rule-wrap">';
|
492 |
+
$output .= '<a href="#" class="button" data-rule-id="' . absint( $index ) . '" data-rule-type="' . $type . '">' . $add_rule_label . '</a>';
|
493 |
+
$output .= '</div>';
|
494 |
+
|
495 |
+
if ( 'display' == $type ) {
|
496 |
+
/* Add new rule */
|
497 |
+
$output .= '<div class="target_rule-add-exclusion-rule">';
|
498 |
+
$output .= '<a href="#" class="button">' . __( 'Add Exclusion Rule', 'bsfsidebars' ) . '</a>';
|
499 |
+
$output .= '</div>';
|
500 |
+
}
|
501 |
+
|
502 |
+
return $output;
|
503 |
+
}
|
504 |
+
|
505 |
+
/**
|
506 |
+
* Get current layout.
|
507 |
+
* Checks of the passed post id of the layout is to be displayed in the page.
|
508 |
+
*
|
509 |
+
* @param (String) $layout_id Layout ID.
|
510 |
+
*
|
511 |
+
* @return int|boolean If the current layout is to be displayed it will be returned back else a boolean will be passed.
|
512 |
+
*/
|
513 |
+
public function get_current_layout( $layout_id ) {
|
514 |
+
$post_id = ( ! is_404() && ! is_search() && ! is_archive() && ! is_home() ) ? get_the_id() : false;
|
515 |
+
$current_layout = false;
|
516 |
+
$is_exclude = false;
|
517 |
+
$is_user_role = false;
|
518 |
+
$display_on = get_post_meta( $layout_id, '_bsf-sb-location', true );
|
519 |
+
$exclude_on = get_post_meta( $layout_id, '_bsf-sb-exclusion', true );
|
520 |
+
$user_roles = get_post_meta( $layout_id, '_bsf-sb-users', true );
|
521 |
+
/* Parse Display On Condition */
|
522 |
+
$is_display = $this->parse_layout_display_condition( $post_id, $display_on );
|
523 |
+
|
524 |
+
if ( true == $is_display ) {
|
525 |
+
/* Parse Exclude On Condition */
|
526 |
+
$is_exclude = $this->parse_layout_display_condition( $post_id, $exclude_on );
|
527 |
+
/* Parse User Role Condition */
|
528 |
+
$is_user_role = $this->parse_user_role_condition( $post_id, $user_roles );
|
529 |
+
}
|
530 |
+
|
531 |
+
if ( $is_display && ! $is_exclude && $is_user_role ) {
|
532 |
+
$current_layout = $layout_id;
|
533 |
+
}
|
534 |
+
|
535 |
+
// filter target page settings.
|
536 |
+
$current_layout = apply_filters( 'bsf_cb_target_page_settings', $current_layout, $layout_id );
|
537 |
+
|
538 |
+
return $current_layout;
|
539 |
+
}
|
540 |
+
|
541 |
+
/**
|
542 |
+
* Checks for the display condition for the current page/
|
543 |
+
*
|
544 |
+
* @param int $post_id Current post ID.
|
545 |
+
* @param Array $rules Array of rules Display on | Exclude on.
|
546 |
+
*
|
547 |
+
* @return Boolean Returns true or false depending on if the $rules match for the current page and the layout is to be displayed.
|
548 |
+
*/
|
549 |
+
public function parse_layout_display_condition( $post_id, $rules ) {
|
550 |
+
|
551 |
+
$show_popup = false;
|
552 |
+
$current_post_type = get_post_type( $post_id );
|
553 |
+
|
554 |
+
if ( isset( $rules['rule'] ) && is_array( $rules['rule'] ) && ! empty( $rules['rule'] ) ) {
|
555 |
+
foreach ( $rules['rule'] as $key => $rule ) {
|
556 |
+
|
557 |
+
if ( strrpos( $rule, 'all' ) !== false ) {
|
558 |
+
$rule_case = 'all';
|
559 |
+
} else {
|
560 |
+
$rule_case = $rule;
|
561 |
+
}
|
562 |
+
|
563 |
+
switch ( $rule_case ) {
|
564 |
+
case 'basic-global':
|
565 |
+
$show_popup = true;
|
566 |
+
break;
|
567 |
+
|
568 |
+
case 'basic-singulars':
|
569 |
+
if ( is_singular() ) {
|
570 |
+
$show_popup = true;
|
571 |
+
}
|
572 |
+
break;
|
573 |
+
|
574 |
+
case 'basic-archives':
|
575 |
+
if ( is_archive() ) {
|
576 |
+
$show_popup = true;
|
577 |
+
}
|
578 |
+
break;
|
579 |
+
|
580 |
+
case 'special-404':
|
581 |
+
if ( is_404() ) {
|
582 |
+
$show_popup = true;
|
583 |
+
}
|
584 |
+
break;
|
585 |
+
|
586 |
+
case 'special-search':
|
587 |
+
if ( is_search() ) {
|
588 |
+
$show_popup = true;
|
589 |
+
}
|
590 |
+
break;
|
591 |
+
|
592 |
+
case 'special-blog':
|
593 |
+
if ( is_home() ) {
|
594 |
+
$show_popup = true;
|
595 |
+
}
|
596 |
+
break;
|
597 |
+
|
598 |
+
case 'special-front':
|
599 |
+
if ( is_front_page() ) {
|
600 |
+
$show_popup = true;
|
601 |
+
}
|
602 |
+
break;
|
603 |
+
|
604 |
+
case 'special-date':
|
605 |
+
if ( is_date() ) {
|
606 |
+
$show_popup = true;
|
607 |
+
}
|
608 |
+
break;
|
609 |
+
|
610 |
+
case 'special-author':
|
611 |
+
if ( is_author() ) {
|
612 |
+
$show_popup = true;
|
613 |
+
}
|
614 |
+
break;
|
615 |
+
|
616 |
+
case 'all':
|
617 |
+
$rule_data = explode( '|', $rule );
|
618 |
+
|
619 |
+
$post_type = isset( $rule_data[0] ) ? $rule_data[0] : false;
|
620 |
+
$archieve_type = isset( $rule_data[2] ) ? $rule_data[2] : false;
|
621 |
+
$taxonomy = isset( $rule_data[3] ) ? $rule_data[3] : false;
|
622 |
+
|
623 |
+
if ( false === $archieve_type ) {
|
624 |
+
|
625 |
+
$current_post_type = get_post_type( $post_id );
|
626 |
+
|
627 |
+
if ( false !== $post_id && $current_post_type == $post_type ) {
|
628 |
+
|
629 |
+
$show_popup = true;
|
630 |
+
}
|
631 |
+
} else {
|
632 |
+
|
633 |
+
if ( is_archive() ) {
|
634 |
+
|
635 |
+
$current_post_type = get_post_type();
|
636 |
+
if ( $current_post_type == $post_type ) {
|
637 |
+
if ( 'archive' == $archieve_type ) {
|
638 |
+
$show_popup = true;
|
639 |
+
} elseif ( 'taxarchive' == $archieve_type ) {
|
640 |
+
|
641 |
+
$obj = get_queried_object();
|
642 |
+
$current_taxonomy = '';
|
643 |
+
if ( '' !== $obj && null !== $obj ) {
|
644 |
+
$current_taxonomy = $obj->taxonomy;
|
645 |
+
}
|
646 |
+
|
647 |
+
if ( $current_taxonomy == $taxonomy ) {
|
648 |
+
$show_popup = true;
|
649 |
+
}
|
650 |
+
}
|
651 |
+
}
|
652 |
+
}
|
653 |
+
}
|
654 |
+
break;
|
655 |
+
|
656 |
+
case 'specifics':
|
657 |
+
if ( isset( $rules['specific'] ) && is_array( $rules['specific'] ) ) {
|
658 |
+
foreach ( $rules['specific'] as $specific_page ) {
|
659 |
+
|
660 |
+
$specific_data = explode( '-', $specific_page );
|
661 |
+
$specific_post_type = isset( $specific_data[0] ) ? $specific_data[0] : false;
|
662 |
+
$specific_post_id = isset( $specific_data[1] ) ? $specific_data[1] : false;
|
663 |
+
if ( 'post' == $specific_post_type ) {
|
664 |
+
if ( $specific_post_id == $post_id ) {
|
665 |
+
$show_popup = true;
|
666 |
+
}
|
667 |
+
} elseif ( 'tax' == $specific_post_type ) {
|
668 |
+
$tax_id = get_queried_object_id();
|
669 |
+
if ( $specific_post_id == $tax_id ) {
|
670 |
+
$show_popup = true;
|
671 |
+
}
|
672 |
+
}
|
673 |
+
}
|
674 |
+
}
|
675 |
+
break;
|
676 |
+
|
677 |
+
default:
|
678 |
+
break;
|
679 |
+
}
|
680 |
+
|
681 |
+
if ( $show_popup ) {
|
682 |
+
break;
|
683 |
+
}
|
684 |
+
}
|
685 |
+
}
|
686 |
+
|
687 |
+
return $show_popup;
|
688 |
+
}
|
689 |
+
|
690 |
+
/**
|
691 |
+
* Function Name: target_user_role_settings_field.
|
692 |
+
* Function Description: Function to handle new input type.
|
693 |
+
*
|
694 |
+
* @param string $name string parameter.
|
695 |
+
* @param string $settings string parameter.
|
696 |
+
* @param string $value string parameter.
|
697 |
+
*/
|
698 |
+
public static function target_user_role_settings_field( $name, $settings, $value ) {
|
699 |
+
$input_name = $name;
|
700 |
+
$type = isset( $settings['type'] ) ? $settings['type'] : 'target_rule';
|
701 |
+
$class = isset( $settings['class'] ) ? $settings['class'] : '';
|
702 |
+
$rule_type = isset( $settings['rule_type'] ) ? $settings['rule_type'] : 'target_rule';
|
703 |
+
$add_rule_label = isset( $settings['add_rule_label'] ) ? $settings['add_rule_label'] : __( 'Add Rule', 'bsfsidebars' );
|
704 |
+
$saved_values = $value;
|
705 |
+
$output = '';
|
706 |
+
|
707 |
+
$selection_options = array(
|
708 |
+
'basic' => array(
|
709 |
+
'label' => __( 'Basic', 'bsfsidebars' ),
|
710 |
+
'value' => array(
|
711 |
+
'all' => __( 'All', 'bsfsidebars' ),
|
712 |
+
'logged-in' => __( 'Logged In', 'bsfsidebars' ),
|
713 |
+
'logged-out' => __( 'Logged Out', 'bsfsidebars' ),
|
714 |
+
),
|
715 |
+
),
|
716 |
+
|
717 |
+
'advanced' => array(
|
718 |
+
'label' => __( 'Advanced', 'bsfsidebars' ),
|
719 |
+
'value' => array(),
|
720 |
+
),
|
721 |
+
);
|
722 |
+
|
723 |
+
/* User roles */
|
724 |
+
$roles = get_editable_roles();
|
725 |
+
|
726 |
+
foreach ( $roles as $slug => $data ) {
|
727 |
+
$selection_options['advanced']['value'][ $slug ] = $data['name'];
|
728 |
+
}
|
729 |
+
|
730 |
+
/* WP Template Format */
|
731 |
+
$output .= '<script type="text/html" id="tmpl-bsf-sb-user-role-condition">';
|
732 |
+
$output .= '<div class="bsf-sb-user-role-condition bsf-sb-user-role-{{data.id}}" data-rule="{{data.id}}" >';
|
733 |
+
$output .= '<span class="user_role-condition-delete dashicons dashicons-dismiss"></span>';
|
734 |
+
/* Condition Selection */
|
735 |
+
$output .= '<div class="user_role-condition-wrap" >';
|
736 |
+
$output .= '<select name="' . esc_attr( $input_name ) . '[{{data.id}}]" class="user_role-condition form-control bsf-sb-input">';
|
737 |
+
$output .= '<option value="">' . __( 'Select', 'bsfsidebars' ) . '</option>';
|
738 |
+
|
739 |
+
foreach ( $selection_options as $group => $group_data ) {
|
740 |
+
|
741 |
+
$output .= '<optgroup label="' . $group_data['label'] . '">';
|
742 |
+
foreach ( $group_data['value'] as $opt_key => $opt_value ) {
|
743 |
+
$output .= '<option value="' . $opt_key . '">' . $opt_value . '</option>';
|
744 |
+
}
|
745 |
+
$output .= '</optgroup>';
|
746 |
+
}
|
747 |
+
$output .= '</select>';
|
748 |
+
$output .= '</div>';
|
749 |
+
$output .= '</div> <!-- bsf-sb-user-role-condition -->';
|
750 |
+
$output .= '</script>';
|
751 |
+
|
752 |
+
if ( ! is_array( $saved_values ) || ( is_array( $saved_values ) && empty( $saved_values ) ) ) {
|
753 |
+
|
754 |
+
$saved_values = array();
|
755 |
+
$saved_values[0] = '';
|
756 |
+
}
|
757 |
+
|
758 |
+
$index = 0;
|
759 |
+
|
760 |
+
$output .= '<div class="bsf-sb-user-role-wrapper bsf-sb-user-role-display-on-wrap" data-type="display">';
|
761 |
+
$output .= '<div class="bsf-sb-user-role-selector-wrapper bsf-sb-user-role-display-on">';
|
762 |
+
$output .= '<div class="user_role-builder-wrap">';
|
763 |
+
foreach ( $saved_values as $index => $data ) {
|
764 |
+
$output .= '<div class="bsf-sb-user-role-condition bsf-sb-user-role-' . $index . '" data-rule="' . $index . '" >';
|
765 |
+
$output .= '<span class="user_role-condition-delete dashicons dashicons-dismiss"></span>';
|
766 |
+
/* Condition Selection */
|
767 |
+
$output .= '<div class="user_role-condition-wrap" >';
|
768 |
+
$output .= '<select name="' . esc_attr( $input_name ) . '[' . $index . ']" class="user_role-condition form-control bsf-sb-input">';
|
769 |
+
$output .= '<option value="">' . __( 'Select', 'bsfsidebars' ) . '</option>';
|
770 |
+
|
771 |
+
foreach ( $selection_options as $group => $group_data ) {
|
772 |
+
|
773 |
+
$output .= '<optgroup label="' . $group_data['label'] . '">';
|
774 |
+
foreach ( $group_data['value'] as $opt_key => $opt_value ) {
|
775 |
+
|
776 |
+
$output .= '<option value="' . $opt_key . '" ' . selected( $data, $opt_key, false ) . '>' . $opt_value . '</option>';
|
777 |
+
}
|
778 |
+
$output .= '</optgroup>';
|
779 |
+
}
|
780 |
+
$output .= '</select>';
|
781 |
+
$output .= '</div>';
|
782 |
+
$output .= '</div> <!-- bsf-sb-user-role-condition -->';
|
783 |
+
}
|
784 |
+
$output .= '</div>';
|
785 |
+
/* Add new rule */
|
786 |
+
$output .= '<div class="user_role-add-rule-wrap">';
|
787 |
+
$output .= '<a href="#" class="button" data-rule-id="' . absint( $index ) . '">' . $add_rule_label . '</a>';
|
788 |
+
$output .= '</div>';
|
789 |
+
$output .= '</div>';
|
790 |
+
$output .= '</div>';
|
791 |
+
|
792 |
+
echo $output;
|
793 |
+
}
|
794 |
+
|
795 |
+
/**
|
796 |
+
* Parse user role condition.
|
797 |
+
*
|
798 |
+
* @since 1.0.0
|
799 |
+
* @param int $post_id Post ID.
|
800 |
+
* @param Array $rules Current user rules.
|
801 |
+
*
|
802 |
+
* @return boolean True = user condition passes. False = User condition does not pass.
|
803 |
+
*/
|
804 |
+
public function parse_user_role_condition( $post_id, $rules ) {
|
805 |
+
|
806 |
+
$show_popup = false;
|
807 |
+
|
808 |
+
if ( is_array( $rules ) && ! empty( $rules ) ) {
|
809 |
+
|
810 |
+
foreach ( $rules as $i => $rule ) {
|
811 |
+
|
812 |
+
switch ( $rule ) {
|
813 |
+
case '':
|
814 |
+
case 'all':
|
815 |
+
$show_popup = true;
|
816 |
+
break;
|
817 |
+
|
818 |
+
case 'logged-in':
|
819 |
+
if ( is_user_logged_in() ) {
|
820 |
+
$show_popup = true;
|
821 |
+
}
|
822 |
+
break;
|
823 |
+
|
824 |
+
case 'logged-out':
|
825 |
+
if ( ! is_user_logged_in() ) {
|
826 |
+
$show_popup = true;
|
827 |
+
}
|
828 |
+
break;
|
829 |
+
|
830 |
+
default:
|
831 |
+
if ( is_user_logged_in() ) {
|
832 |
+
|
833 |
+
$current_user = wp_get_current_user();
|
834 |
+
|
835 |
+
if ( isset( $current_user->roles )
|
836 |
+
&& is_array( $current_user->roles )
|
837 |
+
&& in_array( $rule, $current_user->roles )
|
838 |
+
) {
|
839 |
+
|
840 |
+
$show_popup = true;
|
841 |
+
}
|
842 |
+
}
|
843 |
+
break;
|
844 |
+
}
|
845 |
+
|
846 |
+
if ( $show_popup ) {
|
847 |
+
break;
|
848 |
+
}
|
849 |
+
}
|
850 |
+
}
|
851 |
+
|
852 |
+
return $show_popup;
|
853 |
+
}
|
854 |
+
}
|
855 |
+
}// End if().
|
856 |
+
|
857 |
+
/**
|
858 |
+
* Kicking this off by calling 'get_instance()' method
|
859 |
+
*/
|
860 |
+
BSF_SB_Target_Rules_Fields::get_instance();
|
classes/modules/target-rule/select2.css
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
.select2-container{box-sizing:border-box;display:inline-block;margin:0;position:relative;vertical-align:middle}.select2-container .select2-selection--single{box-sizing:border-box;cursor:pointer;display:block;height:28px;user-select:none;-webkit-user-select:none}.select2-container .select2-selection--single .select2-selection__rendered{display:block;padding-left:8px;padding-right:20px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.select2-container .select2-selection--single .select2-selection__clear{position:relative}.select2-container[dir="rtl"] .select2-selection--single .select2-selection__rendered{padding-right:8px;padding-left:20px}.select2-container .select2-selection--multiple{box-sizing:border-box;cursor:pointer;display:block;min-height:32px;user-select:none;-webkit-user-select:none}.select2-container .select2-selection--multiple .select2-selection__rendered{display:inline-block;overflow:hidden;padding-left:8px;text-overflow:ellipsis;white-space:nowrap}.select2-container .select2-search--inline{float:left}.select2-container .select2-search--inline .select2-search__field{box-sizing:border-box;border:none;font-size:100%;margin-top:5px;padding:0}.select2-container .select2-search--inline .select2-search__field::-webkit-search-cancel-button{-webkit-appearance:none}.select2-dropdown{background-color:white;border:1px solid #aaa;border-radius:4px;box-sizing:border-box;display:block;position:absolute;left:-100000px;width:100%;z-index:1051}.select2-results{display:block}.select2-results__options{list-style:none;margin:0;padding:0}.select2-results__option{padding:6px;user-select:none;-webkit-user-select:none}.select2-results__option[aria-selected]{cursor:pointer}.select2-container--open .select2-dropdown{left:0}.select2-container--open .select2-dropdown--above{border-bottom:none;border-bottom-left-radius:0;border-bottom-right-radius:0}.select2-container--open .select2-dropdown--below{border-top:none;border-top-left-radius:0;border-top-right-radius:0}.select2-search--dropdown{display:block;padding:4px}.select2-search--dropdown .select2-search__field{padding:4px;width:100%;box-sizing:border-box}.select2-search--dropdown .select2-search__field::-webkit-search-cancel-button{-webkit-appearance:none}.select2-search--dropdown.select2-search--hide{display:none}.select2-close-mask{border:0;margin:0;padding:0;display:block;position:fixed;left:0;top:0;min-height:100%;min-width:100%;height:auto;width:auto;opacity:0;z-index:99;background-color:#fff;filter:alpha(opacity=0)}.select2-hidden-accessible{border:0 !important;clip:rect(0 0 0 0) !important;height:1px !important;margin:-1px !important;overflow:hidden !important;padding:0 !important;position:absolute !important;width:1px !important}.select2-container--default .select2-selection--single{background-color:#fff;border:1px solid #aaa;border-radius:4px}.select2-container--default .select2-selection--single .select2-selection__rendered{color:#444;line-height:28px}.select2-container--default .select2-selection--single .select2-selection__clear{cursor:pointer;float:right;font-weight:bold}.select2-container--default .select2-selection--single .select2-selection__placeholder{color:#999}.select2-container--default .select2-selection--single .select2-selection__arrow{height:26px;position:absolute;top:1px;right:1px;width:20px}.select2-container--default .select2-selection--single .select2-selection__arrow b{border-color:#888 transparent transparent transparent;border-style:solid;border-width:5px 4px 0 4px;height:0;left:50%;margin-left:-4px;margin-top:-2px;position:absolute;top:50%;width:0}.select2-container--default[dir="rtl"] .select2-selection--single .select2-selection__clear{float:left}.select2-container--default[dir="rtl"] .select2-selection--single .select2-selection__arrow{left:1px;right:auto}.select2-container--default.select2-container--disabled .select2-selection--single{background-color:#eee;cursor:default}.select2-container--default.select2-container--disabled .select2-selection--single .select2-selection__clear{display:none}.select2-container--default.select2-container--open .select2-selection--single .select2-selection__arrow b{border-color:transparent transparent #888 transparent;border-width:0 4px 5px 4px}.select2-container--default .select2-selection--multiple{background-color:white;border:1px solid #aaa;border-radius:4px;cursor:text}.select2-container--default .select2-selection--multiple .select2-selection__rendered{box-sizing:border-box;list-style:none;margin:0;padding:0 5px;width:100%}.select2-container--default .select2-selection--multiple .select2-selection__rendered li{list-style:none}.select2-container--default .select2-selection--multiple .select2-selection__placeholder{color:#999;margin-top:5px;float:left}.select2-container--default .select2-selection--multiple .select2-selection__clear{cursor:pointer;float:right;font-weight:bold;margin-top:5px;margin-right:10px}.select2-container--default .select2-selection--multiple .select2-selection__choice{background-color:#e4e4e4;border:1px solid #aaa;border-radius:4px;cursor:default;float:left;margin-right:5px;margin-top:5px;padding:0 5px}.select2-container--default .select2-selection--multiple .select2-selection__choice__remove{color:#999;cursor:pointer;display:inline-block;font-weight:bold;margin-right:2px}.select2-container--default .select2-selection--multiple .select2-selection__choice__remove:hover{color:#333}.select2-container--default[dir="rtl"] .select2-selection--multiple .select2-selection__choice,.select2-container--default[dir="rtl"] .select2-selection--multiple .select2-selection__placeholder,.select2-container--default[dir="rtl"] .select2-selection--multiple .select2-search--inline{float:right}.select2-container--default[dir="rtl"] .select2-selection--multiple .select2-selection__choice{margin-left:5px;margin-right:auto}.select2-container--default[dir="rtl"] .select2-selection--multiple .select2-selection__choice__remove{margin-left:2px;margin-right:auto}.select2-container--default.select2-container--focus .select2-selection--multiple{border:solid black 1px;outline:0}.select2-container--default.select2-container--disabled .select2-selection--multiple{background-color:#eee;cursor:default}.select2-container--default.select2-container--disabled .select2-selection__choice__remove{display:none}.select2-container--default.select2-container--open.select2-container--above .select2-selection--single,.select2-container--default.select2-container--open.select2-container--above .select2-selection--multiple{border-top-left-radius:0;border-top-right-radius:0}.select2-container--default.select2-container--open.select2-container--below .select2-selection--single,.select2-container--default.select2-container--open.select2-container--below .select2-selection--multiple{border-bottom-left-radius:0;border-bottom-right-radius:0}.select2-container--default .select2-search--dropdown .select2-search__field{border:1px solid #aaa}.select2-container--default .select2-search--inline .select2-search__field{background:transparent;border:none;outline:0;box-shadow:none;-webkit-appearance:textfield}.select2-container--default .select2-results>.select2-results__options{max-height:200px;overflow-y:auto}.select2-container--default .select2-results__option[role=group]{padding:0}.select2-container--default .select2-results__option[aria-disabled=true]{color:#999}.select2-container--default .select2-results__option[aria-selected=true]{background-color:#ddd}.select2-container--default .select2-results__option .select2-results__option{padding-left:1em}.select2-container--default .select2-results__option .select2-results__option .select2-results__group{padding-left:0}.select2-container--default .select2-results__option .select2-results__option .select2-results__option{margin-left:-1em;padding-left:2em}.select2-container--default .select2-results__option .select2-results__option .select2-results__option .select2-results__option{margin-left:-2em;padding-left:3em}.select2-container--default .select2-results__option .select2-results__option .select2-results__option .select2-results__option .select2-results__option{margin-left:-3em;padding-left:4em}.select2-container--default .select2-results__option .select2-results__option .select2-results__option .select2-results__option .select2-results__option .select2-results__option{margin-left:-4em;padding-left:5em}.select2-container--default .select2-results__option .select2-results__option .select2-results__option .select2-results__option .select2-results__option .select2-results__option .select2-results__option{margin-left:-5em;padding-left:6em}.select2-container--default .select2-results__option--highlighted[aria-selected]{background-color:#5897fb;color:white}.select2-container--default .select2-results__group{cursor:default;display:block;padding:6px}.select2-container--classic .select2-selection--single{background-color:#f7f7f7;border:1px solid #aaa;border-radius:4px;outline:0;background-image:-webkit-linear-gradient(top, #fff 50%, #eee 100%);background-image:-o-linear-gradient(top, #fff 50%, #eee 100%);background-image:linear-gradient(to bottom, #fff 50%, #eee 100%);background-repeat:repeat-x;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#FFFFFFFF', endColorstr='#FFEEEEEE', GradientType=0)}.select2-container--classic .select2-selection--single:focus{border:1px solid #5897fb}.select2-container--classic .select2-selection--single .select2-selection__rendered{color:#444;line-height:28px}.select2-container--classic .select2-selection--single .select2-selection__clear{cursor:pointer;float:right;font-weight:bold;margin-right:10px}.select2-container--classic .select2-selection--single .select2-selection__placeholder{color:#999}.select2-container--classic .select2-selection--single .select2-selection__arrow{background-color:#ddd;border:none;border-left:1px solid #aaa;border-top-right-radius:4px;border-bottom-right-radius:4px;height:26px;position:absolute;top:1px;right:1px;width:20px;background-image:-webkit-linear-gradient(top, #eee 50%, #ccc 100%);background-image:-o-linear-gradient(top, #eee 50%, #ccc 100%);background-image:linear-gradient(to bottom, #eee 50%, #ccc 100%);background-repeat:repeat-x;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#FFEEEEEE', endColorstr='#FFCCCCCC', GradientType=0)}.select2-container--classic .select2-selection--single .select2-selection__arrow b{border-color:#888 transparent transparent transparent;border-style:solid;border-width:5px 4px 0 4px;height:0;left:50%;margin-left:-4px;margin-top:-2px;position:absolute;top:50%;width:0}.select2-container--classic[dir="rtl"] .select2-selection--single .select2-selection__clear{float:left}.select2-container--classic[dir="rtl"] .select2-selection--single .select2-selection__arrow{border:none;border-right:1px solid #aaa;border-radius:0;border-top-left-radius:4px;border-bottom-left-radius:4px;left:1px;right:auto}.select2-container--classic.select2-container--open .select2-selection--single{border:1px solid #5897fb}.select2-container--classic.select2-container--open .select2-selection--single .select2-selection__arrow{background:transparent;border:none}.select2-container--classic.select2-container--open .select2-selection--single .select2-selection__arrow b{border-color:transparent transparent #888 transparent;border-width:0 4px 5px 4px}.select2-container--classic.select2-container--open.select2-container--above .select2-selection--single{border-top:none;border-top-left-radius:0;border-top-right-radius:0;background-image:-webkit-linear-gradient(top, #fff 0%, #eee 50%);background-image:-o-linear-gradient(top, #fff 0%, #eee 50%);background-image:linear-gradient(to bottom, #fff 0%, #eee 50%);background-repeat:repeat-x;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#FFFFFFFF', endColorstr='#FFEEEEEE', GradientType=0)}.select2-container--classic.select2-container--open.select2-container--below .select2-selection--single{border-bottom:none;border-bottom-left-radius:0;border-bottom-right-radius:0;background-image:-webkit-linear-gradient(top, #eee 50%, #fff 100%);background-image:-o-linear-gradient(top, #eee 50%, #fff 100%);background-image:linear-gradient(to bottom, #eee 50%, #fff 100%);background-repeat:repeat-x;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#FFEEEEEE', endColorstr='#FFFFFFFF', GradientType=0)}.select2-container--classic .select2-selection--multiple{background-color:white;border:1px solid #aaa;border-radius:4px;cursor:text;outline:0}.select2-container--classic .select2-selection--multiple:focus{border:1px solid #5897fb}.select2-container--classic .select2-selection--multiple .select2-selection__rendered{list-style:none;margin:0;padding:0 5px}.select2-container--classic .select2-selection--multiple .select2-selection__clear{display:none}.select2-container--classic .select2-selection--multiple .select2-selection__choice{background-color:#e4e4e4;border:1px solid #aaa;border-radius:4px;cursor:default;float:left;margin-right:5px;margin-top:5px;padding:0 5px}.select2-container--classic .select2-selection--multiple .select2-selection__choice__remove{color:#888;cursor:pointer;display:inline-block;font-weight:bold;margin-right:2px}.select2-container--classic .select2-selection--multiple .select2-selection__choice__remove:hover{color:#555}.select2-container--classic[dir="rtl"] .select2-selection--multiple .select2-selection__choice{float:right}.select2-container--classic[dir="rtl"] .select2-selection--multiple .select2-selection__choice{margin-left:5px;margin-right:auto}.select2-container--classic[dir="rtl"] .select2-selection--multiple .select2-selection__choice__remove{margin-left:2px;margin-right:auto}.select2-container--classic.select2-container--open .select2-selection--multiple{border:1px solid #5897fb}.select2-container--classic.select2-container--open.select2-container--above .select2-selection--multiple{border-top:none;border-top-left-radius:0;border-top-right-radius:0}.select2-container--classic.select2-container--open.select2-container--below .select2-selection--multiple{border-bottom:none;border-bottom-left-radius:0;border-bottom-right-radius:0}.select2-container--classic .select2-search--dropdown .select2-search__field{border:1px solid #aaa;outline:0}.select2-container--classic .select2-search--inline .select2-search__field{outline:0;box-shadow:none}.select2-container--classic .select2-dropdown{background-color:#fff;border:1px solid transparent}.select2-container--classic .select2-dropdown--above{border-bottom:none}.select2-container--classic .select2-dropdown--below{border-top:none}.select2-container--classic .select2-results>.select2-results__options{max-height:200px;overflow-y:auto}.select2-container--classic .select2-results__option[role=group]{padding:0}.select2-container--classic .select2-results__option[aria-disabled=true]{color:grey}.select2-container--classic .select2-results__option--highlighted[aria-selected]{background-color:#3875d7;color:#fff}.select2-container--classic .select2-results__group{cursor:default;display:block;padding:6px}.select2-container--classic.select2-container--open .select2-dropdown{border-color:#5897fb}
|
classes/modules/target-rule/select2.js
ADDED
@@ -0,0 +1,5738 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
* Released under the MIT license
|
6 |
+
* https://github.com/select2/select2/blob/master/LICENSE.md
|
7 |
+
*/
|
8 |
+
(function (factory) {
|
9 |
+
var existingVersion = jQuery.fn.select2 || null;
|
10 |
+
|
11 |
+
if (existingVersion) {
|
12 |
+
delete jQuery.fn.select2;
|
13 |
+
}
|
14 |
+
|
15 |
+
if (typeof define === 'function' && define.amd !== undefined && define.amd) {
|
16 |
+
// AMD. Register as an anonymous module.
|
17 |
+
define(['jquery'], factory);
|
18 |
+
} else if (typeof exports === 'object') {
|
19 |
+
// Node/CommonJS
|
20 |
+
factory(require('jquery'));
|
21 |
+
} else {
|
22 |
+
// Browser globals
|
23 |
+
factory(jQuery);
|
24 |
+
}
|
25 |
+
|
26 |
+
jQuery.fn.cpselect2 = jQuery.fn.select2;
|
27 |
+
|
28 |
+
if (existingVersion) {
|
29 |
+
delete jQuery.fn.select2;
|
30 |
+
jQuery.fn.select2 = existingVersion;
|
31 |
+
}
|
32 |
+
}(function (jQuery) {
|
33 |
+
// This is needed so we can catch the AMD loader configuration and use it
|
34 |
+
// The inner file should be wrapped (by `banner.start.js`) in a function that
|
35 |
+
// returns the AMD loader references.
|
36 |
+
var S2 =
|
37 |
+
(function () {
|
38 |
+
// Restore the Select2 AMD loader so it can be used
|
39 |
+
// Needed mostly in the language files, where the loader is not inserted
|
40 |
+
if (jQuery && jQuery.fn && jQuery.fn.select2 && jQuery.fn.select2.amd) {
|
41 |
+
var S2 = jQuery.fn.select2.amd;
|
42 |
+
}
|
43 |
+
var S2;(function () { if (!S2 || !S2.requirejs) {
|
44 |
+
if (!S2) { S2 = {}; } else { require = S2; }
|
45 |
+
/**
|
46 |
+
* @license almond 0.3.1 Copyright (c) 2011-2014, The Dojo Foundation All Rights Reserved.
|
47 |
+
* Available via the MIT or new BSD license.
|
48 |
+
* see: http://github.com/jrburke/almond for details
|
49 |
+
*/
|
50 |
+
//Going sloppy to avoid 'use strict' string cost, but strict practices should
|
51 |
+
//be followed.
|
52 |
+
/*jslint sloppy: true */
|
53 |
+
/*global setTimeout: false */
|
54 |
+
|
55 |
+
var requirejs, require, define;
|
56 |
+
(function (undef) {
|
57 |
+
var main, req, makeMap, handlers,
|
58 |
+
defined = {},
|
59 |
+
waiting = {},
|
60 |
+
config = {},
|
61 |
+
defining = {},
|
62 |
+
hasOwn = Object.prototype.hasOwnProperty,
|
63 |
+
aps = [].slice,
|
64 |
+
jsSuffixRegExp = /\.js$/;
|
65 |
+
|
66 |
+
function hasProp(obj, prop) {
|
67 |
+
return hasOwn.call(obj, prop);
|
68 |
+
}
|
69 |
+
|
70 |
+
/**
|
71 |
+
* Given a relative module name, like ./something, normalize it to
|
72 |
+
* a real name that can be mapped to a path.
|
73 |
+
* @param {String} name the relative name
|
74 |
+
* @param {String} baseName a real name that the name arg is relative
|
75 |
+
* to.
|
76 |
+
* @returns {String} normalized name
|
77 |
+
*/
|
78 |
+
function normalize(name, baseName) {
|
79 |
+
var nameParts, nameSegment, mapValue, foundMap, lastIndex,
|
80 |
+
foundI, foundStarMap, starI, i, j, part,
|
81 |
+
baseParts = baseName && baseName.split("/"),
|
82 |
+
map = config.map,
|
83 |
+
starMap = (map && map['*']) || {};
|
84 |
+
|
85 |
+
//Adjust any relative paths.
|
86 |
+
if (name && name.charAt(0) === ".") {
|
87 |
+
//If have a base name, try to normalize against it,
|
88 |
+
//otherwise, assume it is a top-level require that will
|
89 |
+
//be relative to baseUrl in the end.
|
90 |
+
if (baseName) {
|
91 |
+
name = name.split('/');
|
92 |
+
lastIndex = name.length - 1;
|
93 |
+
|
94 |
+
// Node .js allowance:
|
95 |
+
if (config.nodeIdCompat && jsSuffixRegExp.test(name[lastIndex])) {
|
96 |
+
name[lastIndex] = name[lastIndex].replace(jsSuffixRegExp, '');
|
97 |
+
}
|
98 |
+
|
99 |
+
//Lop off the last part of baseParts, so that . matches the
|
100 |
+
//"directory" and not name of the baseName's module. For instance,
|
101 |
+
//baseName of "one/two/three", maps to "one/two/three.js", but we
|
102 |
+
//want the directory, "one/two" for this normalization.
|
103 |
+
name = baseParts.slice(0, baseParts.length - 1).concat(name);
|
104 |
+
|
105 |
+
//start trimDots
|
106 |
+
for (i = 0; i < name.length; i += 1) {
|
107 |
+
part = name[i];
|
108 |
+
if (part === ".") {
|
109 |
+
name.splice(i, 1);
|
110 |
+
i -= 1;
|
111 |
+
} else if (part === "..") {
|
112 |
+
if (i === 1 && (name[2] === '..' || name[0] === '..')) {
|
113 |
+
//End of the line. Keep at least one non-dot
|
114 |
+
//path segment at the front so it can be mapped
|
115 |
+
//correctly to disk. Otherwise, there is likely
|
116 |
+
//no path mapping for a path starting with '..'.
|
117 |
+
//This can still fail, but catches the most reasonable
|
118 |
+
//uses of ..
|
119 |
+
break;
|
120 |
+
} else if (i > 0) {
|
121 |
+
name.splice(i - 1, 2);
|
122 |
+
i -= 2;
|
123 |
+
}
|
124 |
+
}
|
125 |
+
}
|
126 |
+
//end trimDots
|
127 |
+
|
128 |
+
name = name.join("/");
|
129 |
+
} else if (name.indexOf('./') === 0) {
|
130 |
+
// No baseName, so this is ID is resolved relative
|
131 |
+
// to baseUrl, pull off the leading dot.
|
132 |
+
name = name.substring(2);
|
133 |
+
}
|
134 |
+
}
|
135 |
+
|
136 |
+
//Apply map config if available.
|
137 |
+
if ((baseParts || starMap) && map) {
|
138 |
+
nameParts = name.split('/');
|
139 |
+
|
140 |
+
for (i = nameParts.length; i > 0; i -= 1) {
|
141 |
+
nameSegment = nameParts.slice(0, i).join("/");
|
142 |
+
|
143 |
+
if (baseParts) {
|
144 |
+
//Find the longest baseName segment match in the config.
|
145 |
+
//So, do joins on the biggest to smallest lengths of baseParts.
|
146 |
+
for (j = baseParts.length; j > 0; j -= 1) {
|
147 |
+
mapValue = map[baseParts.slice(0, j).join('/')];
|
148 |
+
|
149 |
+
//baseName segment has config, find if it has one for
|
150 |
+
//this name.
|
151 |
+
if (mapValue) {
|
152 |
+
mapValue = mapValue[nameSegment];
|
153 |
+
if (mapValue) {
|
154 |
+
//Match, update name to the new value.
|
155 |
+
foundMap = mapValue;
|
156 |
+
foundI = i;
|
157 |
+
break;
|
158 |
+
}
|
159 |
+
}
|
160 |
+
}
|
161 |
+
}
|
162 |
+
|
163 |
+
if (foundMap) {
|
164 |
+
break;
|
165 |
+
}
|
166 |
+
|
167 |
+
//Check for a star map match, but just hold on to it,
|
168 |
+
//if there is a shorter segment match later in a matching
|
169 |
+
//config, then favor over this star map.
|
170 |
+
if (!foundStarMap && starMap && starMap[nameSegment]) {
|
171 |
+
foundStarMap = starMap[nameSegment];
|
172 |
+
starI = i;
|
173 |
+
}
|
174 |
+
}
|
175 |
+
|
176 |
+
if (!foundMap && foundStarMap) {
|
177 |
+
foundMap = foundStarMap;
|
178 |
+
foundI = starI;
|
179 |
+
}
|
180 |
+
|
181 |
+
if (foundMap) {
|
182 |
+
nameParts.splice(0, foundI, foundMap);
|
183 |
+
name = nameParts.join('/');
|
184 |
+
}
|
185 |
+
}
|
186 |
+
|
187 |
+
return name;
|
188 |
+
}
|
189 |
+
|
190 |
+
function makeRequire(relName, forceSync) {
|
191 |
+
return function () {
|
192 |
+
//A version of a require function that passes a moduleName
|
193 |
+
//value for items that may need to
|
194 |
+
//look up paths relative to the moduleName
|
195 |
+
var args = aps.call(arguments, 0);
|
196 |
+
|
197 |
+
//If first arg is not require('string'), and there is only
|
198 |
+
//one arg, it is the array form without a callback. Insert
|
199 |
+
//a null so that the following concat is correct.
|
200 |
+
if (typeof args[0] !== 'string' && args.length === 1) {
|
201 |
+
args.push(null);
|
202 |
+
}
|
203 |
+
return req.apply(undef, args.concat([relName, forceSync]));
|
204 |
+
};
|
205 |
+
}
|
206 |
+
|
207 |
+
function makeNormalize(relName) {
|
208 |
+
return function (name) {
|
209 |
+
return normalize(name, relName);
|
210 |
+
};
|
211 |
+
}
|
212 |
+
|
213 |
+
function makeLoad(depName) {
|
214 |
+
return function (value) {
|
215 |
+
defined[depName] = value;
|
216 |
+
};
|
217 |
+
}
|
218 |
+
|
219 |
+
function callDep(name) {
|
220 |
+
if (hasProp(waiting, name)) {
|
221 |
+
var args = waiting[name];
|
222 |
+
delete waiting[name];
|
223 |
+
defining[name] = true;
|
224 |
+
main.apply(undef, args);
|
225 |
+
}
|
226 |
+
|
227 |
+
if (!hasProp(defined, name) && !hasProp(defining, name)) {
|
228 |
+
throw new Error('No ' + name);
|
229 |
+
}
|
230 |
+
return defined[name];
|
231 |
+
}
|
232 |
+
|
233 |
+
//Turns a plugin!resource to [plugin, resource]
|
234 |
+
//with the plugin being undefined if the name
|
235 |
+
//did not have a plugin prefix.
|
236 |
+
function splitPrefix(name) {
|
237 |
+
var prefix,
|
238 |
+
index = name ? name.indexOf('!') : -1;
|
239 |
+
if (index > -1) {
|
240 |
+
prefix = name.substring(0, index);
|
241 |
+
name = name.substring(index + 1, name.length);
|
242 |
+
}
|
243 |
+
return [prefix, name];
|
244 |
+
}
|
245 |
+
|
246 |
+
/**
|
247 |
+
* Makes a name map, normalizing the name, and using a plugin
|
248 |
+
* for normalization if necessary. Grabs a ref to plugin
|
249 |
+
* too, as an optimization.
|
250 |
+
*/
|
251 |
+
makeMap = function (name, relName) {
|
252 |
+
var plugin,
|
253 |
+
parts = splitPrefix(name),
|
254 |
+
prefix = parts[0];
|
255 |
+
|
256 |
+
name = parts[1];
|
257 |
+
|
258 |
+
if (prefix) {
|
259 |
+
prefix = normalize(prefix, relName);
|
260 |
+
plugin = callDep(prefix);
|
261 |
+
}
|
262 |
+
|
263 |
+
//Normalize according
|
264 |
+
if (prefix) {
|
265 |
+
if (plugin && plugin.normalize) {
|
266 |
+
name = plugin.normalize(name, makeNormalize(relName));
|
267 |
+
} else {
|
268 |
+
name = normalize(name, relName);
|
269 |
+
}
|
270 |
+
} else {
|
271 |
+
name = normalize(name, relName);
|
272 |
+
parts = splitPrefix(name);
|
273 |
+
prefix = parts[0];
|
274 |
+
name = parts[1];
|
275 |
+
if (prefix) {
|
276 |
+
plugin = callDep(prefix);
|
277 |
+
}
|
278 |
+
}
|
279 |
+
|
280 |
+
//Using ridiculous property names for space reasons
|
281 |
+
return {
|
282 |
+
f: prefix ? prefix + '!' + name : name, //fullName
|
283 |
+
n: name,
|
284 |
+
pr: prefix,
|
285 |
+
p: plugin
|
286 |
+
};
|
287 |
+
};
|
288 |
+
|
289 |
+
function makeConfig(name) {
|
290 |
+
return function () {
|
291 |
+
return (config && config.config && config.config[name]) || {};
|
292 |
+
};
|
293 |
+
}
|
294 |
+
|
295 |
+
handlers = {
|
296 |
+
require: function (name) {
|
297 |
+
return makeRequire(name);
|
298 |
+
},
|
299 |
+
exports: function (name) {
|
300 |
+
var e = defined[name];
|
301 |
+
if (typeof e !== 'undefined') {
|
302 |
+
return e;
|
303 |
+
} else {
|
304 |
+
return (defined[name] = {});
|
305 |
+
}
|
306 |
+
},
|
307 |
+
module: function (name) {
|
308 |
+
return {
|
309 |
+
id: name,
|
310 |
+
uri: '',
|
311 |
+
exports: defined[name],
|
312 |
+
config: makeConfig(name)
|
313 |
+
};
|
314 |
+
}
|
315 |
+
};
|
316 |
+
|
317 |
+
main = function (name, deps, callback, relName) {
|
318 |
+
var cjsModule, depName, ret, map, i,
|
319 |
+
args = [],
|
320 |
+
callbackType = typeof callback,
|
321 |
+
usingExports;
|
322 |
+
|
323 |
+
//Use name if no relName
|
324 |
+
relName = relName || name;
|
325 |
+
|
326 |
+
//Call the callback to define the module, if necessary.
|
327 |
+
if (callbackType === 'undefined' || callbackType === 'function') {
|
328 |
+
//Pull out the defined dependencies and pass the ordered
|
329 |
+
//values to the callback.
|
330 |
+
//Default to [require, exports, module] if no deps
|
331 |
+
deps = !deps.length && callback.length ? ['require', 'exports', 'module'] : deps;
|
332 |
+
for (i = 0; i < deps.length; i += 1) {
|
333 |
+
map = makeMap(deps[i], relName);
|
334 |
+
depName = map.f;
|
335 |
+
|
336 |
+
//Fast path CommonJS standard dependencies.
|
337 |
+
if (depName === "require") {
|
338 |
+
args[i] = handlers.require(name);
|
339 |
+
} else if (depName === "exports") {
|
340 |
+
//CommonJS module spec 1.1
|
341 |
+
args[i] = handlers.exports(name);
|
342 |
+
usingExports = true;
|
343 |
+
} else if (depName === "module") {
|
344 |
+
//CommonJS module spec 1.1
|
345 |
+
cjsModule = args[i] = handlers.module(name);
|
346 |
+
} else if (hasProp(defined, depName) ||
|
347 |
+
hasProp(waiting, depName) ||
|
348 |
+
hasProp(defining, depName)) {
|
349 |
+
args[i] = callDep(depName);
|
350 |
+
} else if (map.p) {
|
351 |
+
map.p.load(map.n, makeRequire(relName, true), makeLoad(depName), {});
|
352 |
+
args[i] = defined[depName];
|
353 |
+
} else {
|
354 |
+
throw new Error(name + ' missing ' + depName);
|
355 |
+
}
|
356 |
+
}
|
357 |
+
|
358 |
+
ret = callback ? callback.apply(defined[name], args) : undefined;
|
359 |
+
|
360 |
+
if (name) {
|
361 |
+
//If setting exports via "module" is in play,
|
362 |
+
//favor that over return value and exports. After that,
|
363 |
+
//favor a non-undefined return value over exports use.
|
364 |
+
if (cjsModule && cjsModule.exports !== undef &&
|
365 |
+
cjsModule.exports !== defined[name]) {
|
366 |
+
defined[name] = cjsModule.exports;
|
367 |
+
} else if (ret !== undef || !usingExports) {
|
368 |
+
//Use the return value from the function.
|
369 |
+
defined[name] = ret;
|
370 |
+
}
|
371 |
+
}
|
372 |
+
} else if (name) {
|
373 |
+
//May just be an object definition for the module. Only
|
374 |
+
//worry about defining if have a module name.
|
375 |
+
defined[name] = callback;
|
376 |
+
}
|
377 |
+
};
|
378 |
+
|
379 |
+
requirejs = require = req = function (deps, callback, relName, forceSync, alt) {
|
380 |
+
if (typeof deps === "string") {
|
381 |
+
if (handlers[deps]) {
|
382 |
+
//callback in this case is really relName
|
383 |
+
return handlers[deps](callback);
|
384 |
+
}
|
385 |
+
//Just return the module wanted. In this scenario, the
|
386 |
+
//deps arg is the module name, and second arg (if passed)
|
387 |
+
//is just the relName.
|
388 |
+
//Normalize module name, if it contains . or ..
|
389 |
+
return callDep(makeMap(deps, callback).f);
|
390 |
+
} else if (!deps.splice) {
|
391 |
+
//deps is a config object, not an array.
|
392 |
+
config = deps;
|
393 |
+
if (config.deps) {
|
394 |
+
req(config.deps, config.callback);
|
395 |
+
}
|
396 |
+
if (!callback) {
|
397 |
+
return;
|
398 |
+
}
|
399 |
+
|
400 |
+
if (callback.splice) {
|
401 |
+
//callback is an array, which means it is a dependency list.
|
402 |
+
//Adjust args if there are dependencies
|
403 |
+
deps = callback;
|
404 |
+
callback = relName;
|
405 |
+
relName = null;
|
406 |
+
} else {
|
407 |
+
deps = undef;
|
408 |
+
}
|
409 |
+
}
|
410 |
+
|
411 |
+
//Support require(['a'])
|
412 |
+
callback = callback || function () {};
|
413 |
+
|
414 |
+
//If relName is a function, it is an errback handler,
|
415 |
+
//so remove it.
|
416 |
+
if (typeof relName === 'function') {
|
417 |
+
relName = forceSync;
|
418 |
+
forceSync = alt;
|
419 |
+
}
|
420 |
+
|
421 |
+
//Simulate async callback;
|
422 |
+
if (forceSync) {
|
423 |
+
main(undef, deps, callback, relName);
|
424 |
+
} else {
|
425 |
+
//Using a non-zero value because of concern for what old browsers
|
426 |
+
//do, and latest browsers "upgrade" to 4 if lower value is used:
|
427 |
+
//http://www.whatwg.org/specs/web-apps/current-work/multipage/timers.html#dom-windowtimers-settimeout:
|
428 |
+
//If want a value immediately, use require('id') instead -- something
|
429 |
+
//that works in almond on the global level, but not guaranteed and
|
430 |
+
//unlikely to work in other AMD implementations.
|
431 |
+
setTimeout(function () {
|
432 |
+
main(undef, deps, callback, relName);
|
433 |
+
}, 4);
|
434 |
+
}
|
435 |
+
|
436 |
+
return req;
|
437 |
+
};
|
438 |
+
|
439 |
+
/**
|
440 |
+
* Just drops the config on the floor, but returns req in case
|
441 |
+
* the config return value is used.
|
442 |
+
*/
|
443 |
+
req.config = function (cfg) {
|
444 |
+
return req(cfg);
|
445 |
+
};
|
446 |
+
|
447 |
+
/**
|
448 |
+
* Expose module registry for debugging and tooling
|
449 |
+
*/
|
450 |
+
requirejs._defined = defined;
|
451 |
+
|
452 |
+
define = function (name, deps, callback) {
|
453 |
+
if (typeof name !== 'string') {
|
454 |
+
throw new Error('See almond README: incorrect module build, no module name');
|
455 |
+
}
|
456 |
+
|
457 |
+
//This module may not have dependencies
|
458 |
+
if (!deps.splice) {
|
459 |
+
//deps is not an array, so probably means
|
460 |
+
//an object literal or factory function for
|
461 |
+
//the value. Adjust args.
|
462 |
+
callback = deps;
|
463 |
+
deps = [];
|
464 |
+
}
|
465 |
+
|
466 |
+
if (!hasProp(defined, name) && !hasProp(waiting, name)) {
|
467 |
+
waiting[name] = [name, deps, callback];
|
468 |
+
}
|
469 |
+
};
|
470 |
+
|
471 |
+
define.amd = {
|
472 |
+
jQuery: true
|
473 |
+
};
|
474 |
+
}());
|
475 |
+
|
476 |
+
S2.requirejs = requirejs;S2.require = require;S2.define = define;
|
477 |
+
}
|
478 |
+
}());
|
479 |
+
S2.define("almond", function(){});
|
480 |
+
|
481 |
+
/* global jQuery:false, $:false */
|
482 |
+
S2.define('jquery',[],function () {
|
483 |
+
var _$ = jQuery || $;
|
484 |
+
|
485 |
+
if (_$ == null && console && console.error) {
|
486 |
+
console.error(
|
487 |
+
'Select2: An instance of jQuery or a jQuery-compatible library was not ' +
|
488 |
+
'found. Make sure that you are including jQuery before Select2 on your ' +
|
489 |
+
'web page.'
|
490 |
+
);
|
491 |
+
}
|
492 |
+
|
493 |
+
return _$;
|
494 |
+
});
|
495 |
+
|
496 |
+
S2.define('select2/utils',[
|
497 |
+
'jquery'
|
498 |
+
], function ($) {
|
499 |
+
var Utils = {};
|
500 |
+
|
501 |
+
Utils.Extend = function (ChildClass, SuperClass) {
|
502 |
+
var __hasProp = {}.hasOwnProperty;
|
503 |
+
|
504 |
+
function BaseConstructor () {
|
505 |
+
this.constructor = ChildClass;
|
506 |
+
}
|
507 |
+
|
508 |
+
for (var key in SuperClass) {
|
509 |
+
if (__hasProp.call(SuperClass, key)) {
|
510 |
+
ChildClass[key] = SuperClass[key];
|
511 |
+
}
|
512 |
+
}
|
513 |
+
|
514 |
+
BaseConstructor.prototype = SuperClass.prototype;
|
515 |
+
ChildClass.prototype = new BaseConstructor();
|
516 |
+
ChildClass.__super__ = SuperClass.prototype;
|
517 |
+
|
518 |
+
return ChildClass;
|
519 |
+
};
|
520 |
+
|
521 |
+
function getMethods (theClass) {
|
522 |
+
var proto = theClass.prototype;
|
523 |
+
|
524 |
+
var methods = [];
|
525 |
+
|
526 |
+
for (var methodName in proto) {
|
527 |
+
var m = proto[methodName];
|
528 |
+
|
529 |
+
if (typeof m !== 'function') {
|
530 |
+
continue;
|
531 |
+
}
|
532 |
+
|
533 |
+
if (methodName === 'constructor') {
|
534 |
+
continue;
|
535 |
+
}
|
536 |
+
|
537 |
+
methods.push(methodName);
|
538 |
+
}
|
539 |
+
|
540 |
+
return methods;
|
541 |
+
}
|
542 |
+
|
543 |
+
Utils.Decorate = function (SuperClass, DecoratorClass) {
|
544 |
+
var decoratedMethods = getMethods(DecoratorClass);
|
545 |
+
var superMethods = getMethods(SuperClass);
|
546 |
+
|
547 |
+
function DecoratedClass () {
|
548 |
+
var unshift = Array.prototype.unshift;
|
549 |
+
|
550 |
+
var argCount = DecoratorClass.prototype.constructor.length;
|
551 |
+
|
552 |
+
var calledConstructor = SuperClass.prototype.constructor;
|
553 |
+
|
554 |
+
if (argCount > 0) {
|
555 |
+
unshift.call(arguments, SuperClass.prototype.constructor);
|
556 |
+
|
557 |
+
calledConstructor = DecoratorClass.prototype.constructor;
|
558 |
+
}
|
559 |
+
|
560 |
+
calledConstructor.apply(this, arguments);
|
561 |
+
}
|
562 |
+
|
563 |
+
DecoratorClass.displayName = SuperClass.displayName;
|
564 |
+
|
565 |
+
function ctr () {
|
566 |
+
this.constructor = DecoratedClass;
|
567 |
+
}
|
568 |
+
|
569 |
+
DecoratedClass.prototype = new ctr();
|
570 |
+
|
571 |
+
for (var m = 0; m < superMethods.length; m++) {
|
572 |
+
var superMethod = superMethods[m];
|
573 |
+
|
574 |
+
DecoratedClass.prototype[superMethod] =
|
575 |
+
SuperClass.prototype[superMethod];
|
576 |
+
}
|
577 |
+
|
578 |
+
var calledMethod = function (methodName) {
|
579 |
+
// Stub out the original method if it's not decorating an actual method
|
580 |
+
var originalMethod = function () {};
|
581 |
+
|
582 |
+
if (methodName in DecoratedClass.prototype) {
|
583 |
+
originalMethod = DecoratedClass.prototype[methodName];
|
584 |
+
}
|
585 |
+
|
586 |
+
var decoratedMethod = DecoratorClass.prototype[methodName];
|
587 |
+
|
588 |
+
return function () {
|
589 |
+
var unshift = Array.prototype.unshift;
|
590 |
+
|
591 |
+
unshift.call(arguments, originalMethod);
|
592 |
+
|
593 |
+
return decoratedMethod.apply(this, arguments);
|
594 |
+
};
|
595 |
+
};
|
596 |
+
|
597 |
+
for (var d = 0; d < decoratedMethods.length; d++) {
|
598 |
+
var decoratedMethod = decoratedMethods[d];
|
599 |
+
|
600 |
+
DecoratedClass.prototype[decoratedMethod] = calledMethod(decoratedMethod);
|
601 |
+
}
|
602 |
+
|
603 |
+
return DecoratedClass;
|
604 |
+
};
|
605 |
+
|
606 |
+
var Observable = function () {
|
607 |
+
this.listeners = {};
|
608 |
+
};
|
609 |
+
|
610 |
+
Observable.prototype.on = function (event, callback) {
|
611 |
+
this.listeners = this.listeners || {};
|
612 |
+
|
613 |
+
if (event in this.listeners) {
|
614 |
+
this.listeners[event].push(callback);
|
615 |
+
} else {
|
616 |
+
this.listeners[event] = [callback];
|
617 |
+
}
|
618 |
+
};
|
619 |
+
|
620 |
+
Observable.prototype.trigger = function (event) {
|
621 |
+
var slice = Array.prototype.slice;
|
622 |
+
var params = slice.call(arguments, 1);
|
623 |
+
|
624 |
+
this.listeners = this.listeners || {};
|
625 |
+
|
626 |
+
// Params should always come in as an array
|
627 |
+
if (params == null) {
|
628 |
+
params = [];
|
629 |
+
}
|
630 |
+
|
631 |
+
// If there are no arguments to the event, use a temporary object
|
632 |
+
if (params.length === 0) {
|
633 |
+
params.push({});
|
634 |
+
}
|
635 |
+
|
636 |
+
// Set the `_type` of the first object to the event
|
637 |
+
params[0]._type = event;
|
638 |
+
|
639 |
+
if (event in this.listeners) {
|
640 |
+
this.invoke(this.listeners[event], slice.call(arguments, 1));
|
641 |
+
}
|
642 |
+
|
643 |
+
if ('*' in this.listeners) {
|
644 |
+
this.invoke(this.listeners['*'], arguments);
|
645 |
+
}
|
646 |
+
};
|
647 |
+
|
648 |
+
Observable.prototype.invoke = function (listeners, params) {
|
649 |
+
for (var i = 0, len = listeners.length; i < len; i++) {
|
650 |
+
listeners[i].apply(this, params);
|
651 |
+
}
|
652 |
+
};
|
653 |
+
|
654 |
+
Utils.Observable = Observable;
|
655 |
+
|
656 |
+
Utils.generateChars = function (length) {
|
657 |
+
var chars = '';
|
658 |
+
|
659 |
+
for (var i = 0; i < length; i++) {
|
660 |
+
var randomChar = Math.floor(Math.random() * 36);
|
661 |
+
chars += randomChar.toString(36);
|
662 |
+
}
|
663 |
+
|
664 |
+
return chars;
|
665 |
+
};
|
666 |
+
|
667 |
+
Utils.bind = function (func, context) {
|
668 |
+
return function () {
|
669 |
+
func.apply(context, arguments);
|
670 |
+
};
|
671 |
+
};
|
672 |
+
|
673 |
+
Utils._convertData = function (data) {
|
674 |
+
for (var originalKey in data) {
|
675 |
+
var keys = originalKey.split('-');
|
676 |
+
|
677 |
+
var dataLevel = data;
|
678 |
+
|
679 |
+
if (keys.length === 1) {
|
680 |
+
continue;
|
681 |
+
}
|
682 |
+
|
683 |
+
for (var k = 0; k < keys.length; k++) {
|
684 |
+
var key = keys[k];
|
685 |
+
|
686 |
+
// Lowercase the first letter
|
687 |
+
// By default, dash-separated becomes camelCase
|
688 |
+
key = key.substring(0, 1).toLowerCase() + key.substring(1);
|
689 |
+
|
690 |
+
if (!(key in dataLevel)) {
|
691 |
+
dataLevel[key] = {};
|
692 |
+
}
|
693 |
+
|
694 |
+
if (k == keys.length - 1) {
|
695 |
+
dataLevel[key] = data[originalKey];
|
696 |
+
}
|
697 |
+
|
698 |
+
dataLevel = dataLevel[key];
|
699 |
+
}
|
700 |
+
|
701 |
+
delete data[originalKey];
|
702 |
+
}
|
703 |
+
|
704 |
+
return data;
|
705 |
+
};
|
706 |
+
|
707 |
+
Utils.hasScroll = function (index, el) {
|
708 |
+
// Adapted from the function created by @ShadowScripter
|
709 |
+
// and adapted by @BillBarry on the Stack Exchange Code Review website.
|
710 |
+
// The original code can be found at
|
711 |
+
// http://codereview.stackexchange.com/q/13338
|
712 |
+
// and was designed to be used with the Sizzle selector engine.
|
713 |
+
|
714 |
+
var $el = $(el);
|
715 |
+
var overflowX = el.style.overflowX;
|
716 |
+
var overflowY = el.style.overflowY;
|
717 |
+
|
718 |
+
//Check both x and y declarations
|
719 |
+
if (overflowX === overflowY &&
|
720 |
+
(overflowY === 'hidden' || overflowY === 'visible')) {
|
721 |
+
return false;
|
722 |
+
}
|
723 |
+
|
724 |
+
if (overflowX === 'scroll' || overflowY === 'scroll') {
|
725 |
+
return true;
|
726 |
+
}
|
727 |
+
|
728 |
+
return ($el.innerHeight() < el.scrollHeight ||
|
729 |
+
$el.innerWidth() < el.scrollWidth);
|
730 |
+
};
|
731 |
+
|
732 |
+
Utils.escapeMarkup = function (markup) {
|
733 |
+
var replaceMap = {
|
734 |
+
'\\': '\',
|
735 |
+
'&': '&',
|
736 |
+
'<': '<',
|
737 |
+
'>': '>',
|
738 |
+
'"': '"',
|
739 |
+
'\'': ''',
|
740 |
+
'/': '/'
|
741 |
+
};
|
742 |
+
|
743 |
+
// Do not try to escape the markup if it's not a string
|
744 |
+
if (typeof markup !== 'string') {
|
745 |
+
return markup;
|
746 |
+
}
|
747 |
+
|
748 |
+
return String(markup).replace(/[&<>"'\/\\]/g, function (match) {
|
749 |
+
return replaceMap[match];
|
750 |
+
});
|
751 |
+
};
|
752 |
+
|
753 |
+
// Append an array of jQuery nodes to a given element.
|
754 |
+
Utils.appendMany = function ($element, $nodes) {
|
755 |
+
// jQuery 1.7.x does not support $.fn.append() with an array
|
756 |
+
// Fall back to a jQuery object collection using $.fn.add()
|
757 |
+
if ($.fn.jquery.substr(0, 3) === '1.7') {
|
758 |
+
var $jqNodes = $();
|
759 |
+
|
760 |
+
$.map($nodes, function (node) {
|
761 |
+
$jqNodes = $jqNodes.add(node);
|
762 |
+
});
|
763 |
+
|
764 |
+
$nodes = $jqNodes;
|
765 |
+
}
|
766 |
+
|
767 |
+
$element.append($nodes);
|
768 |
+
};
|
769 |
+
|
770 |
+
return Utils;
|
771 |
+
});
|
772 |
+
|
773 |
+
S2.define('select2/results',[
|
774 |
+
'jquery',
|
775 |
+
'./utils'
|
776 |
+
], function ($, Utils) {
|
777 |
+
function Results ($element, options, dataAdapter) {
|
778 |
+
this.$element = $element;
|
779 |
+
this.data = dataAdapter;
|
780 |
+
this.options = options;
|
781 |
+
|
782 |
+
Results.__super__.constructor.call(this);
|
783 |
+
}
|
784 |
+
|
785 |
+
Utils.Extend(Results, Utils.Observable);
|
786 |
+
|
787 |
+
Results.prototype.render = function () {
|
788 |
+
var $results = $(
|
789 |
+
'<ul class="select2-results__options" role="tree"></ul>'
|
790 |
+
);
|
791 |
+
|
792 |
+
if (this.options.get('multiple')) {
|
793 |
+
$results.attr('aria-multiselectable', 'true');
|
794 |
+
}
|
795 |
+
|
796 |
+
this.$results = $results;
|
797 |
+
|
798 |
+
return $results;
|
799 |
+
};
|
800 |
+
|
801 |
+
Results.prototype.clear = function () {
|
802 |
+
this.$results.empty();
|
803 |
+
};
|
804 |
+
|
805 |
+
Results.prototype.displayMessage = function (params) {
|
806 |
+
var escapeMarkup = this.options.get('escapeMarkup');
|
807 |
+
|
808 |
+
this.clear();
|
809 |
+
this.hideLoading();
|
810 |
+
|
811 |
+
var $message = $(
|
812 |
+
'<li role="treeitem" aria-live="assertive"' +
|
813 |
+
' class="select2-results__option"></li>'
|
814 |
+
);
|
815 |
+
|
816 |
+
var message = this.options.get('translations').get(params.message);
|
817 |
+
|
818 |
+
$message.append(
|
819 |
+
escapeMarkup(
|
820 |
+
message(params.args)
|
821 |
+
)
|
822 |
+
);
|
823 |
+
|
824 |
+
$message[0].className += ' select2-results__message';
|
825 |
+
|
826 |
+
this.$results.append($message);
|
827 |
+
};
|
828 |
+
|
829 |
+
Results.prototype.hideMessages = function () {
|
830 |
+
this.$results.find('.select2-results__message').remove();
|
831 |
+
};
|
832 |
+
|
833 |
+
Results.prototype.append = function (data) {
|
834 |
+
this.hideLoading();
|
835 |
+
|
836 |
+
var $options = [];
|
837 |
+
|
838 |
+
if (data.results == null || data.results.length === 0) {
|
839 |
+
if (this.$results.children().length === 0) {
|
840 |
+
this.trigger('results:message', {
|
841 |
+
message: 'noResults'
|
842 |
+
});
|
843 |
+
}
|
844 |
+
|
845 |
+
return;
|
846 |
+
}
|
847 |
+
|
848 |
+
data.results = this.sort(data.results);
|
849 |
+
|
850 |
+
for (var d = 0; d < data.results.length; d++) {
|
851 |
+
var item = data.results[d];
|
852 |
+
|
853 |
+
var $option = this.option(item);
|
854 |
+
|
855 |
+
$options.push($option);
|
856 |
+
}
|
857 |
+
|
858 |
+
this.$results.append($options);
|
859 |
+
};
|
860 |
+
|
861 |
+
Results.prototype.position = function ($results, $dropdown) {
|
862 |
+
var $resultsContainer = $dropdown.find('.select2-results');
|
863 |
+
$resultsContainer.append($results);
|
864 |
+
};
|
865 |
+
|
866 |
+
Results.prototype.sort = function (data) {
|
867 |
+
var sorter = this.options.get('sorter');
|
868 |
+
|
869 |
+
return sorter(data);
|
870 |
+
};
|
871 |
+
|
872 |
+
Results.prototype.highlightFirstItem = function () {
|
873 |
+
var $options = this.$results
|
874 |
+
.find('.select2-results__option[aria-selected]');
|
875 |
+
|
876 |
+
var $selected = $options.filter('[aria-selected=true]');
|
877 |
+
|
878 |
+
// Check if there are any selected options
|
879 |
+
if ($selected.length > 0) {
|
880 |
+
// If there are selected options, highlight the first
|
881 |
+
$selected.first().trigger('mouseenter');
|
882 |
+
} else {
|
883 |
+
// If there are no selected options, highlight the first option
|
884 |
+
// in the dropdown
|
885 |
+
$options.first().trigger('mouseenter');
|
886 |
+
}
|
887 |
+
|
888 |
+
this.ensureHighlightVisible();
|
889 |
+
};
|
890 |
+
|
891 |
+
Results.prototype.setClasses = function () {
|
892 |
+
var self = this;
|
893 |
+
|
894 |
+
this.data.current(function (selected) {
|
895 |
+
var selectedIds = $.map(selected, function (s) {
|
896 |
+
return s.id.toString();
|
897 |
+
});
|
898 |
+
|
899 |
+
var $options = self.$results
|
900 |
+
.find('.select2-results__option[aria-selected]');
|
901 |
+
|
902 |
+
$options.each(function () {
|
903 |
+
var $option = $(this);
|
904 |
+
|
905 |
+
var item = $.data(this, 'data');
|
906 |
+
|
907 |
+
// id needs to be converted to a string when comparing
|
908 |
+
var id = '' + item.id;
|
909 |
+
|
910 |
+
if ((item.element != null && item.element.selected) ||
|
911 |
+
(item.element == null && $.inArray(id, selectedIds) > -1)) {
|
912 |
+
$option.attr('aria-selected', 'true');
|
913 |
+
} else {
|
914 |
+
$option.attr('aria-selected', 'false');
|
915 |
+
}
|
916 |
+
});
|
917 |
+
|
918 |
+
});
|
919 |
+
};
|
920 |
+
|
921 |
+
Results.prototype.showLoading = function (params) {
|
922 |
+
this.hideLoading();
|
923 |
+
|
924 |
+
var loadingMore = this.options.get('translations').get('searching');
|
925 |
+
|
926 |
+
var loading = {
|
927 |
+
disabled: true,
|
928 |
+
loading: true,
|
929 |
+
text: loadingMore(params)
|
930 |
+
};
|
931 |
+
var $loading = this.option(loading);
|
932 |
+
$loading.className += ' loading-results';
|
933 |
+
|
934 |
+
this.$results.prepend($loading);
|
935 |
+
};
|
936 |
+
|
937 |
+
Results.prototype.hideLoading = function () {
|
938 |
+
this.$results.find('.loading-results').remove();
|
939 |
+
};
|
940 |
+
|
941 |
+
Results.prototype.option = function (data) {
|
942 |
+
var option = document.createElement('li');
|
943 |
+
option.className = 'select2-results__option';
|
944 |
+
|
945 |
+
var attrs = {
|
946 |
+
'role': 'treeitem',
|
947 |
+
'aria-selected': 'false'
|
948 |
+
};
|
949 |
+
|
950 |
+
if (data.disabled) {
|
951 |
+
delete attrs['aria-selected'];
|
952 |
+
attrs['aria-disabled'] = 'true';
|
953 |
+
}
|
954 |
+
|
955 |
+
if (data.id == null) {
|
956 |
+
delete attrs['aria-selected'];
|
957 |
+
}
|
958 |
+
|
959 |
+
if (data._resultId != null) {
|
960 |
+
option.id = data._resultId;
|
961 |
+
}
|
962 |
+
|
963 |
+
if (data.title) {
|
964 |
+
option.title = data.title;
|
965 |
+
}
|
966 |
+
|
967 |
+
if (data.children) {
|
968 |
+
attrs.role = 'group';
|
969 |
+
attrs['aria-label'] = data.text;
|
970 |
+
delete attrs['aria-selected'];
|
971 |
+
}
|
972 |
+
|
973 |
+
for (var attr in attrs) {
|
974 |
+
var val = attrs[attr];
|
975 |
+
|
976 |
+
option.setAttribute(attr, val);
|
977 |
+
}
|
978 |
+
|
979 |
+
if (data.children) {
|
980 |
+
var $option = $(option);
|
981 |
+
|
982 |
+
var label = document.createElement('strong');
|
983 |
+
label.className = 'select2-results__group';
|
984 |
+
|
985 |
+
var $label = $(label);
|
986 |
+
this.template(data, label);
|
987 |
+
|
988 |
+
var $children = [];
|
989 |
+
|
990 |
+
for (var c = 0; c < data.children.length; c++) {
|
991 |
+
var child = data.children[c];
|
992 |
+
|
993 |
+
var $child = this.option(child);
|
994 |
+
|
995 |
+
$children.push($child);
|
996 |
+
}
|
997 |
+
|
998 |
+
var $childrenContainer = $('<ul></ul>', {
|
999 |
+
'class': 'select2-results__options select2-results__options--nested'
|
1000 |
+
});
|
1001 |
+
|
1002 |
+
$childrenContainer.append($children);
|
1003 |
+
|
1004 |
+
$option.append(label);
|
1005 |
+
$option.append($childrenContainer);
|
1006 |
+
} else {
|
1007 |
+
this.template(data, option);
|
1008 |
+
}
|
1009 |
+
|
1010 |
+
$.data(option, 'data', data);
|
1011 |
+
|
1012 |
+
return option;
|
1013 |
+
};
|
1014 |
+
|
1015 |
+
Results.prototype.bind = function (container, $container) {
|
1016 |
+
var self = this;
|
1017 |
+
|
1018 |
+
var id = container.id + '-results';
|
1019 |
+
|
1020 |
+
this.$results.attr('id', id);
|
1021 |
+
|
1022 |
+
container.on('results:all', function (params) {
|
1023 |
+
self.clear();
|
1024 |
+
self.append(params.data);
|
1025 |
+
|
1026 |
+
if (container.isOpen()) {
|
1027 |
+
self.setClasses();
|
1028 |
+
self.highlightFirstItem();
|
1029 |
+
}
|
1030 |
+
});
|
1031 |
+
|
1032 |
+
container.on('results:append', function (params) {
|
1033 |
+
self.append(params.data);
|
1034 |
+
|
1035 |
+
if (container.isOpen()) {
|
1036 |
+
self.setClasses();
|
1037 |
+
}
|
1038 |
+
});
|
1039 |
+
|
1040 |
+
container.on('query', function (params) {
|
1041 |
+
self.hideMessages();
|
1042 |
+
self.showLoading(params);
|
1043 |
+
});
|
1044 |
+
|
1045 |
+
container.on('select', function () {
|
1046 |
+
if (!container.isOpen()) {
|
1047 |
+
return;
|
1048 |
+
}
|
1049 |
+
|
1050 |
+
self.setClasses();
|
1051 |
+
self.highlightFirstItem();
|
1052 |
+
});
|
1053 |
+
|
1054 |
+
container.on('unselect', function () {
|
1055 |
+
if (!container.isOpen()) {
|
1056 |
+
return;
|
1057 |
+
}
|
1058 |
+
|
1059 |
+
self.setClasses();
|
1060 |
+
self.highlightFirstItem();
|
1061 |
+
});
|
1062 |
+
|
1063 |
+
container.on('open', function () {
|
1064 |
+
// When the dropdown is open, aria-expended="true"
|
1065 |
+
self.$results.attr('aria-expanded', 'true');
|
1066 |
+
self.$results.attr('aria-hidden', 'false');
|
1067 |
+
|
1068 |
+
self.setClasses();
|
1069 |
+
self.ensureHighlightVisible();
|
1070 |
+
});
|
1071 |
+
|
1072 |
+
container.on('close', function () {
|
1073 |
+
// When the dropdown is closed, aria-expended="false"
|
1074 |
+
self.$results.attr('aria-expanded', 'false');
|
1075 |
+
self.$results.attr('aria-hidden', 'true');
|
1076 |
+
self.$results.removeAttr('aria-activedescendant');
|
1077 |
+
});
|
1078 |
+
|
1079 |
+
container.on('results:toggle', function () {
|
1080 |
+
var $highlighted = self.getHighlightedResults();
|
1081 |
+
|
1082 |
+
if ($highlighted.length === 0) {
|
1083 |
+
return;
|
1084 |
+
}
|
1085 |
+
|
1086 |
+
$highlighted.trigger('mouseup');
|
1087 |
+
});
|
1088 |
+
|
1089 |
+
container.on('results:select', function () {
|
1090 |
+
var $highlighted = self.getHighlightedResults();
|
1091 |
+
|
1092 |
+
if ($highlighted.length === 0) {
|
1093 |
+
return;
|
1094 |
+
}
|
1095 |
+
|
1096 |
+
var data = $highlighted.data('data');
|
1097 |
+
|
1098 |
+
if ($highlighted.attr('aria-selected') == 'true') {
|
1099 |
+
self.trigger('close', {});
|
1100 |
+
} else {
|
1101 |
+
self.trigger('select', {
|
1102 |
+
data: data
|
1103 |
+
});
|
1104 |
+
}
|
1105 |
+
});
|
1106 |
+
|
1107 |
+
container.on('results:previous', function () {
|
1108 |
+
var $highlighted = self.getHighlightedResults();
|
1109 |
+
|
1110 |
+
var $options = self.$results.find('[aria-selected]');
|
1111 |
+
|
1112 |
+
var currentIndex = $options.index($highlighted);
|
1113 |
+
|
1114 |
+
// If we are already at te top, don't move further
|
1115 |
+
if (currentIndex === 0) {
|
1116 |
+
return;
|
1117 |
+
}
|
1118 |
+
|
1119 |
+
var nextIndex = currentIndex - 1;
|
1120 |
+
|
1121 |
+
// If none are highlighted, highlight the first
|
1122 |
+
if ($highlighted.length === 0) {
|
1123 |
+
nextIndex = 0;
|
1124 |
+
}
|
1125 |
+
|
1126 |
+
var $next = $options.eq(nextIndex);
|
1127 |
+
|
1128 |
+
$next.trigger('mouseenter');
|
1129 |
+
|
1130 |
+
var currentOffset = self.$results.offset().top;
|
1131 |
+
var nextTop = $next.offset().top;
|
1132 |
+
var nextOffset = self.$results.scrollTop() + (nextTop - currentOffset);
|
1133 |
+
|
1134 |
+
if (nextIndex === 0) {
|
1135 |
+
self.$results.scrollTop(0);
|
1136 |
+
} else if (nextTop - currentOffset < 0) {
|
1137 |
+
self.$results.scrollTop(nextOffset);
|
1138 |
+
}
|
1139 |
+
});
|
1140 |
+
|
1141 |
+
container.on('results:next', function () {
|
1142 |
+
var $highlighted = self.getHighlightedResults();
|
1143 |
+
|
1144 |
+
var $options = self.$results.find('[aria-selected]');
|
1145 |
+
|
1146 |
+
var currentIndex = $options.index($highlighted);
|
1147 |
+
|
1148 |
+
var nextIndex = currentIndex + 1;
|
1149 |
+
|
1150 |
+
// If we are at the last option, stay there
|
1151 |
+
if (nextIndex >= $options.length) {
|
1152 |
+
return;
|
1153 |
+
}
|
1154 |
+
|
1155 |
+
var $next = $options.eq(nextIndex);
|
1156 |
+
|
1157 |
+
$next.trigger('mouseenter');
|
1158 |
+
|
1159 |
+
var currentOffset = self.$results.offset().top +
|
1160 |
+
self.$results.outerHeight(false);
|
1161 |
+
var nextBottom = $next.offset().top + $next.outerHeight(false);
|
1162 |
+
var nextOffset = self.$results.scrollTop() + nextBottom - currentOffset;
|
1163 |
+
|
1164 |
+
if (nextIndex === 0) {
|
1165 |
+
self.$results.scrollTop(0);
|
1166 |
+
} else if (nextBottom > currentOffset) {
|
1167 |
+
self.$results.scrollTop(nextOffset);
|
1168 |
+
}
|
1169 |
+
});
|
1170 |
+
|
1171 |
+
container.on('results:focus', function (params) {
|
1172 |
+
params.element.addClass('select2-results__option--highlighted');
|
1173 |
+
});
|
1174 |
+
|
1175 |
+
container.on('results:message', function (params) {
|
1176 |
+
self.displayMessage(params);
|
1177 |
+
});
|
1178 |
+
|
1179 |
+
if ($.fn.mousewheel) {
|
1180 |
+
this.$results.on('mousewheel', function (e) {
|
1181 |
+
var top = self.$results.scrollTop();
|
1182 |
+
|
1183 |
+
var bottom = self.$results.get(0).scrollHeight - top + e.deltaY;
|
1184 |
+
|
1185 |
+
var isAtTop = e.deltaY > 0 && top - e.deltaY <= 0;
|
1186 |
+
var isAtBottom = e.deltaY < 0 && bottom <= self.$results.height();
|
1187 |
+
|
1188 |
+
if (isAtTop) {
|
1189 |
+
self.$results.scrollTop(0);
|
1190 |
+
|
1191 |
+
e.preventDefault();
|
1192 |
+
e.stopPropagation();
|
1193 |
+
} else if (isAtBottom) {
|
1194 |
+
self.$results.scrollTop(
|
1195 |
+
self.$results.get(0).scrollHeight - self.$results.height()
|
1196 |
+
);
|
1197 |
+
|
1198 |
+
e.preventDefault();
|
1199 |
+
e.stopPropagation();
|
1200 |
+
}
|
1201 |
+
});
|
1202 |
+
}
|
1203 |
+
|
1204 |
+
this.$results.on('mouseup', '.select2-results__option[aria-selected]',
|
1205 |
+
function (evt) {
|
1206 |
+
var $this = $(this);
|
1207 |
+
|
1208 |
+
var data = $this.data('data');
|
1209 |
+
|
1210 |
+
if ($this.attr('aria-selected') === 'true') {
|
1211 |
+
if (self.options.get('multiple')) {
|
1212 |
+
self.trigger('unselect', {
|
1213 |
+
originalEvent: evt,
|
1214 |
+
data: data
|
1215 |
+
});
|
1216 |
+
} else {
|
1217 |
+
self.trigger('close', {});
|
1218 |
+
}
|
1219 |
+
|
1220 |
+
return;
|
1221 |
+
}
|
1222 |
+
|
1223 |
+
self.trigger('select', {
|
1224 |
+
originalEvent: evt,
|
1225 |
+
data: data
|
1226 |
+
});
|
1227 |
+
});
|
1228 |
+
|
1229 |
+
this.$results.on('mouseenter', '.select2-results__option[aria-selected]',
|
1230 |
+
function (evt) {
|
1231 |
+
var data = $(this).data('data');
|
1232 |
+
|
1233 |
+
self.getHighlightedResults()
|
1234 |
+
.removeClass('select2-results__option--highlighted');
|
1235 |
+
|
1236 |
+
self.trigger('results:focus', {
|
1237 |
+
data: data,
|
1238 |
+
element: $(this)
|
1239 |
+
});
|
1240 |
+
});
|
1241 |
+
};
|
1242 |
+
|
1243 |
+
Results.prototype.getHighlightedResults = function () {
|
1244 |
+
var $highlighted = this.$results
|
1245 |
+
.find('.select2-results__option--highlighted');
|
1246 |
+
|
1247 |
+
return $highlighted;
|
1248 |
+
};
|
1249 |
+
|
1250 |
+
Results.prototype.destroy = function () {
|
1251 |
+
this.$results.remove();
|
1252 |
+
};
|
1253 |
+
|
1254 |
+
Results.prototype.ensureHighlightVisible = function () {
|
1255 |
+
var $highlighted = this.getHighlightedResults();
|
1256 |
+
|
1257 |
+
if ($highlighted.length === 0) {
|
1258 |
+
return;
|
1259 |
+
}
|
1260 |
+
|
1261 |
+
var $options = this.$results.find('[aria-selected]');
|
1262 |
+
|
1263 |
+
var currentIndex = $options.index($highlighted);
|
1264 |
+
|
1265 |
+
var currentOffset = this.$results.offset().top;
|
1266 |
+
var nextTop = $highlighted.offset().top;
|
1267 |
+
var nextOffset = this.$results.scrollTop() + (nextTop - currentOffset);
|
1268 |
+
|
1269 |
+
var offsetDelta = nextTop - currentOffset;
|
1270 |
+
nextOffset -= $highlighted.outerHeight(false) * 2;
|
1271 |
+
|
1272 |
+
if (currentIndex <= 2) {
|
1273 |
+
this.$results.scrollTop(0);
|
1274 |
+
} else if (offsetDelta > this.$results.outerHeight() || offsetDelta < 0) {
|
1275 |
+
this.$results.scrollTop(nextOffset);
|
1276 |
+
}
|
1277 |
+
};
|
1278 |
+
|
1279 |
+
Results.prototype.template = function (result, container) {
|
1280 |
+
var template = this.options.get('templateResult');
|
1281 |
+
var escapeMarkup = this.options.get('escapeMarkup');
|
1282 |
+
|
1283 |
+
var content = template(result, container);
|
1284 |
+
|
1285 |
+
if (content == null) {
|
1286 |
+
container.style.display = 'none';
|
1287 |
+
} else if (typeof content === 'string') {
|
1288 |
+
container.innerHTML = escapeMarkup(content);
|
1289 |
+
} else {
|
1290 |
+
$(container).append(content);
|
1291 |
+
}
|
1292 |
+
};
|
1293 |
+
|
1294 |
+
return Results;
|
1295 |
+
});
|
1296 |
+
|
1297 |
+
S2.define('select2/keys',[
|
1298 |
+
|
1299 |
+
], function () {
|
1300 |
+
var KEYS = {
|
1301 |
+
BACKSPACE: 8,
|
1302 |
+
TAB: 9,
|
1303 |
+
ENTER: 13,
|
1304 |
+
SHIFT: 16,
|
1305 |
+
CTRL: 17,
|
1306 |
+
ALT: 18,
|
1307 |
+
ESC: 27,
|
1308 |
+
SPACE: 32,
|
1309 |
+
PAGE_UP: 33,
|
1310 |
+
PAGE_DOWN: 34,
|
1311 |
+
END: 35,
|
1312 |
+
HOME: 36,
|
1313 |
+
LEFT: 37,
|
1314 |
+
UP: 38,
|
1315 |
+
RIGHT: 39,
|
1316 |
+
DOWN: 40,
|
1317 |
+
DELETE: 46
|
1318 |
+
};
|
1319 |
+
|
1320 |
+
return KEYS;
|
1321 |
+
});
|
1322 |
+
|
1323 |
+
S2.define('select2/selection/base',[
|
1324 |
+
'jquery',
|
1325 |
+
'../utils',
|
1326 |
+
'../keys'
|
1327 |
+
], function ($, Utils, KEYS) {
|
1328 |
+
function BaseSelection ($element, options) {
|
1329 |
+
this.$element = $element;
|
1330 |
+
this.options = options;
|
1331 |
+
|
1332 |
+
BaseSelection.__super__.constructor.call(this);
|
1333 |
+
}
|
1334 |
+
|
1335 |
+
Utils.Extend(BaseSelection, Utils.Observable);
|
1336 |
+
|
1337 |
+
BaseSelection.prototype.render = function () {
|
1338 |
+
var $selection = $(
|
1339 |
+
'<span class="select2-selection" role="combobox" ' +
|
1340 |
+
' aria-haspopup="true" aria-expanded="false">' +
|
1341 |
+
'</span>'
|
1342 |
+
);
|
1343 |
+
|
1344 |
+
this._tabindex = 0;
|
1345 |
+
|
1346 |
+
if (this.$element.data('old-tabindex') != null) {
|
1347 |
+
this._tabindex = this.$element.data('old-tabindex');
|
1348 |
+
} else if (this.$element.attr('tabindex') != null) {
|
1349 |
+
this._tabindex = this.$element.attr('tabindex');
|
1350 |
+
}
|
1351 |
+
|
1352 |
+
$selection.attr('title', this.$element.attr('title'));
|
1353 |
+
$selection.attr('tabindex', this._tabindex);
|
1354 |
+
|
1355 |
+
this.$selection = $selection;
|
1356 |
+
|
1357 |
+
return $selection;
|
1358 |
+
};
|
1359 |
+
|
1360 |
+
BaseSelection.prototype.bind = function (container, $container) {
|
1361 |
+
var self = this;
|
1362 |
+
|
1363 |
+
var id = container.id + '-container';
|
1364 |
+
var resultsId = container.id + '-results';
|
1365 |
+
|
1366 |
+
this.container = container;
|
1367 |
+
|
1368 |
+
this.$selection.on('focus', function (evt) {
|
1369 |
+
self.trigger('focus', evt);
|
1370 |
+
});
|
1371 |
+
|
1372 |
+
this.$selection.on('blur', function (evt) {
|
1373 |
+
self._handleBlur(evt);
|
1374 |
+
});
|
1375 |
+
|
1376 |
+
this.$selection.on('keydown', function (evt) {
|
1377 |
+
self.trigger('keypress', evt);
|
1378 |
+
|
1379 |
+
if (evt.which === KEYS.SPACE) {
|
1380 |
+
evt.preventDefault();
|
1381 |
+
}
|
1382 |
+
});
|
1383 |
+
|
1384 |
+
container.on('results:focus', function (params) {
|
1385 |
+
self.$selection.attr('aria-activedescendant', params.data._resultId);
|
1386 |
+
});
|
1387 |
+
|
1388 |
+
container.on('selection:update', function (params) {
|
1389 |
+
self.update(params.data);
|
1390 |
+
});
|
1391 |
+
|
1392 |
+
container.on('open', function () {
|
1393 |
+
// When the dropdown is open, aria-expanded="true"
|
1394 |
+
self.$selection.attr('aria-expanded', 'true');
|
1395 |
+
self.$selection.attr('aria-owns', resultsId);
|
1396 |
+
|
1397 |
+
self._attachCloseHandler(container);
|
1398 |
+
});
|
1399 |
+
|
1400 |
+
container.on('close', function () {
|
1401 |
+
// When the dropdown is closed, aria-expanded="false"
|
1402 |
+
self.$selection.attr('aria-expanded', 'false');
|
1403 |
+
self.$selection.removeAttr('aria-activedescendant');
|
1404 |
+
self.$selection.removeAttr('aria-owns');
|
1405 |
+
|
1406 |
+
self.$selection.focus();
|
1407 |
+
|
1408 |
+
self._detachCloseHandler(container);
|
1409 |
+
});
|
1410 |
+
|
1411 |
+
container.on('enable', function () {
|
1412 |
+
self.$selection.attr('tabindex', self._tabindex);
|
1413 |
+
});
|
1414 |
+
|
1415 |
+
container.on('disable', function () {
|
1416 |
+
self.$selection.attr('tabindex', '-1');
|
1417 |
+
});
|
1418 |
+
};
|
1419 |
+
|
1420 |
+
BaseSelection.prototype._handleBlur = function (evt) {
|
1421 |
+
var self = this;
|
1422 |
+
|
1423 |
+
// This needs to be delayed as the active element is the body when the tab
|
1424 |
+
// key is pressed, possibly along with others.
|
1425 |
+
window.setTimeout(function () {
|
1426 |
+
// Don't trigger `blur` if the focus is still in the selection
|
1427 |
+
if (
|
1428 |
+
(document.activeElement == self.$selection[0]) ||
|
1429 |
+
($.contains(self.$selection[0], document.activeElement))
|
1430 |
+
) {
|
1431 |
+
return;
|
1432 |
+
}
|
1433 |
+
|
1434 |
+
self.trigger('blur', evt);
|
1435 |
+
}, 1);
|
1436 |
+
};
|
1437 |
+
|
1438 |
+
BaseSelection.prototype._attachCloseHandler = function (container) {
|
1439 |
+
var self = this;
|
1440 |
+
|
1441 |
+
$(document.body).on('mousedown.select2.' + container.id, function (e) {
|
1442 |
+
var $target = $(e.target);
|
1443 |
+
|
1444 |
+
var $select = $target.closest('.select2');
|
1445 |
+
|
1446 |
+
var $all = $('.select2.select2-container--open');
|
1447 |
+
|
1448 |
+
$all.each(function () {
|
1449 |
+
var $this = $(this);
|
1450 |
+
|
1451 |
+
if (this == $select[0]) {
|
1452 |
+
return;
|
1453 |
+
}
|
1454 |
+
|
1455 |
+
var $element = $this.data('element');
|
1456 |
+
|
1457 |
+
$element.select2('close');
|
1458 |
+
});
|
1459 |
+
});
|
1460 |
+
};
|
1461 |
+
|
1462 |
+
BaseSelection.prototype._detachCloseHandler = function (container) {
|
1463 |
+
$(document.body).off('mousedown.select2.' + container.id);
|
1464 |
+
};
|
1465 |
+
|
1466 |
+
BaseSelection.prototype.position = function ($selection, $container) {
|
1467 |
+
var $selectionContainer = $container.find('.selection');
|
1468 |
+
$selectionContainer.append($selection);
|
1469 |
+
};
|
1470 |
+
|
1471 |
+
BaseSelection.prototype.destroy = function () {
|
1472 |
+
this._detachCloseHandler(this.container);
|
1473 |
+
};
|
1474 |
+
|
1475 |
+
BaseSelection.prototype.update = function (data) {
|
1476 |
+
throw new Error('The `update` method must be defined in child classes.');
|
1477 |
+
};
|
1478 |
+
|
1479 |
+
return BaseSelection;
|
1480 |
+
});
|
1481 |
+
|
1482 |
+
S2.define('select2/selection/single',[
|
1483 |
+
'jquery',
|
1484 |
+
'./base',
|
1485 |
+
'../utils',
|
1486 |
+
'../keys'
|
1487 |
+
], function ($, BaseSelection, Utils, KEYS) {
|
1488 |
+
function SingleSelection () {
|
1489 |
+
SingleSelection.__super__.constructor.apply(this, arguments);
|
1490 |
+
}
|
1491 |
+
|
1492 |
+
Utils.Extend(SingleSelection, BaseSelection);
|
1493 |
+
|
1494 |
+
SingleSelection.prototype.render = function () {
|
1495 |
+
var $selection = SingleSelection.__super__.render.call(this);
|
1496 |
+
|
1497 |
+
$selection.addClass('select2-selection--single');
|
1498 |
+
|
1499 |
+
$selection.html(
|
1500 |
+
'<span class="select2-selection__rendered"></span>' +
|
1501 |
+
'<span class="select2-selection__arrow" role="presentation">' +
|
1502 |
+
'<b role="presentation"></b>' +
|
1503 |
+
'</span>'
|
1504 |
+
);
|
1505 |
+
|
1506 |
+
return $selection;
|
1507 |
+
};
|
1508 |
+
|
1509 |
+
SingleSelection.prototype.bind = function (container, $container) {
|
1510 |
+
var self = this;
|
1511 |
+
|
1512 |
+
SingleSelection.__super__.bind.apply(this, arguments);
|
1513 |
+
|
1514 |
+
var id = container.id + '-container';
|
1515 |
+
|
1516 |
+
this.$selection.find('.select2-selection__rendered').attr('id', id);
|
1517 |
+
this.$selection.attr('aria-labelledby', id);
|
1518 |
+
|
1519 |
+
this.$selection.on('mousedown', function (evt) {
|
1520 |
+
// Only respond to left clicks
|
1521 |
+
if (evt.which !== 1) {
|
1522 |
+
return;
|
1523 |
+
}
|
1524 |
+
|
1525 |
+
self.trigger('toggle', {
|
1526 |
+
originalEvent: evt
|
1527 |
+
});
|
1528 |
+
});
|
1529 |
+
|
1530 |
+
this.$selection.on('focus', function (evt) {
|
1531 |
+
// User focuses on the container
|
1532 |
+
});
|
1533 |
+
|
1534 |
+
this.$selection.on('blur', function (evt) {
|
1535 |
+
// User exits the container
|
1536 |
+
});
|
1537 |
+
|
1538 |
+
container.on('focus', function (evt) {
|
1539 |
+
if (!container.isOpen()) {
|
1540 |
+
self.$selection.focus();
|
1541 |
+
}
|
1542 |
+
});
|
1543 |
+
|
1544 |
+
container.on('selection:update', function (params) {
|
1545 |
+
self.update(params.data);
|
1546 |
+
});
|
1547 |
+
};
|
1548 |
+
|
1549 |
+
SingleSelection.prototype.clear = function () {
|
1550 |
+
this.$selection.find('.select2-selection__rendered').empty();
|
1551 |
+
};
|
1552 |
+
|
1553 |
+
SingleSelection.prototype.display = function (data, container) {
|
1554 |
+
var template = this.options.get('templateSelection');
|
1555 |
+
var escapeMarkup = this.options.get('escapeMarkup');
|
1556 |
+
|
1557 |
+
return escapeMarkup(template(data, container));
|
1558 |
+
};
|
1559 |
+
|
1560 |
+
SingleSelection.prototype.selectionContainer = function () {
|
1561 |
+
return $('<span></span>');
|
1562 |
+
};
|
1563 |
+
|
1564 |
+
SingleSelection.prototype.update = function (data) {
|
1565 |
+
if (data.length === 0) {
|
1566 |
+
this.clear();
|
1567 |
+
return;
|
1568 |
+
}
|
1569 |
+
|
1570 |
+
var selection = data[0];
|
1571 |
+
|
1572 |
+
var $rendered = this.$selection.find('.select2-selection__rendered');
|
1573 |
+
var formatted = this.display(selection, $rendered);
|
1574 |
+
|
1575 |
+
$rendered.empty().append(formatted);
|
1576 |
+
$rendered.prop('title', selection.title || selection.text);
|
1577 |
+
};
|
1578 |
+
|
1579 |
+
return SingleSelection;
|
1580 |
+
});
|
1581 |
+
|
1582 |
+
S2.define('select2/selection/multiple',[
|
1583 |
+
'jquery',
|
1584 |
+
'./base',
|
1585 |
+
'../utils'
|
1586 |
+
], function ($, BaseSelection, Utils) {
|
1587 |
+
function MultipleSelection ($element, options) {
|
1588 |
+
MultipleSelection.__super__.constructor.apply(this, arguments);
|
1589 |
+
}
|
1590 |
+
|
1591 |
+
Utils.Extend(MultipleSelection, BaseSelection);
|
1592 |
+
|
1593 |
+
MultipleSelection.prototype.render = function () {
|
1594 |
+
var $selection = MultipleSelection.__super__.render.call(this);
|
1595 |
+
|
1596 |
+
$selection.addClass('select2-selection--multiple');
|
1597 |
+
|
1598 |
+
$selection.html(
|
1599 |
+
'<ul class="select2-selection__rendered"></ul>'
|
1600 |
+
);
|
1601 |
+
|
1602 |
+
return $selection;
|
1603 |
+
};
|
1604 |
+
|
1605 |
+
MultipleSelection.prototype.bind = function (container, $container) {
|
1606 |
+
var self = this;
|
1607 |
+
|
1608 |
+
MultipleSelection.__super__.bind.apply(this, arguments);
|
1609 |
+
|
1610 |
+
this.$selection.on('click', function (evt) {
|
1611 |
+
self.trigger('toggle', {
|
1612 |
+
originalEvent: evt
|
1613 |
+
});
|
1614 |
+
});
|
1615 |
+
|
1616 |
+
this.$selection.on(
|
1617 |
+
'click',
|
1618 |
+
'.select2-selection__choice__remove',
|
1619 |
+
function (evt) {
|
1620 |
+
// Ignore the event if it is disabled
|
1621 |
+
if (self.options.get('disabled')) {
|
1622 |
+
return;
|
1623 |
+
}
|
1624 |
+
console.log("here"+$(this));
|
1625 |
+
var $remove = $(this);
|
1626 |
+
var $selection = $remove.parent();
|
1627 |
+
|
1628 |
+
var data = $selection.data('data');
|
1629 |
+
|
1630 |
+
self.trigger('unselect', {
|
1631 |
+
originalEvent: evt,
|
1632 |
+
data: data
|
1633 |
+
});
|
1634 |
+
}
|
1635 |
+
);
|
1636 |
+
};
|
1637 |
+
|
1638 |
+
MultipleSelection.prototype.clear = function () {
|
1639 |
+
this.$selection.find('.select2-selection__rendered').empty();
|
1640 |
+
};
|
1641 |
+
|
1642 |
+
MultipleSelection.prototype.display = function (data, container) {
|
1643 |
+
var template = this.options.get('templateSelection');
|
1644 |
+
var escapeMarkup = this.options.get('escapeMarkup');
|
1645 |
+
|
1646 |
+
return escapeMarkup(template(data, container));
|
1647 |
+
};
|
1648 |
+
|
1649 |
+
MultipleSelection.prototype.selectionContainer = function () {
|
1650 |
+
var $container = $(
|
1651 |
+
'<li class="select2-selection__choice">' +
|
1652 |
+
'<span class="select2-selection__choice__remove" role="presentation">' +
|
1653 |
+
'×' +
|
1654 |
+
'</span>' +
|
1655 |
+
'</li>'
|
1656 |
+
);
|
1657 |
+
|
1658 |
+
return $container;
|
1659 |
+
};
|
1660 |
+
|
1661 |
+
MultipleSelection.prototype.update = function (data) {
|
1662 |
+
this.clear();
|
1663 |
+
|
1664 |
+
if (data.length === 0) {
|
1665 |
+
return;
|
1666 |
+
}
|
1667 |
+
|
1668 |
+
var $selections = [];
|
1669 |
+
|
1670 |
+
for (var d = 0; d < data.length; d++) {
|
1671 |
+
var selection = data[d];
|
1672 |
+
|
1673 |
+
var $selection = this.selectionContainer();
|
1674 |
+
var formatted = this.display(selection, $selection);
|
1675 |
+
|
1676 |
+
$selection.append(formatted);
|
1677 |
+
$selection.prop('title', selection.title || selection.text);
|
1678 |
+
|
1679 |
+
$selection.data('data', selection);
|
1680 |
+
|
1681 |
+
$selections.push($selection);
|
1682 |
+
}
|
1683 |
+
|
1684 |
+
var $rendered = this.$selection.find('.select2-selection__rendered');
|
1685 |
+
|
1686 |
+
Utils.appendMany($rendered, $selections);
|
1687 |
+
};
|
1688 |
+
|
1689 |
+
return MultipleSelection;
|
1690 |
+
});
|
1691 |
+
|
1692 |
+
S2.define('select2/selection/placeholder',[
|
1693 |
+
'../utils'
|
1694 |
+
], function (Utils) {
|
1695 |
+
function Placeholder (decorated, $element, options) {
|
1696 |
+
this.placeholder = this.normalizePlaceholder(options.get('placeholder'));
|
1697 |
+
|
1698 |
+
decorated.call(this, $element, options);
|
1699 |
+
}
|
1700 |
+
|
1701 |
+
Placeholder.prototype.normalizePlaceholder = function (_, placeholder) {
|
1702 |
+
if (typeof placeholder === 'string') {
|
1703 |
+
placeholder = {
|
1704 |
+
id: '',
|
1705 |
+
text: placeholder
|
1706 |
+
};
|
1707 |
+
}
|
1708 |
+
|
1709 |
+
return placeholder;
|
1710 |
+
};
|
1711 |
+
|
1712 |
+
Placeholder.prototype.createPlaceholder = function (decorated, placeholder) {
|
1713 |
+
var $placeholder = this.selectionContainer();
|
1714 |
+
|
1715 |
+
$placeholder.html(this.display(placeholder));
|
1716 |
+
$placeholder.addClass('select2-selection__placeholder')
|
1717 |
+
.removeClass('select2-selection__choice');
|
1718 |
+
|
1719 |
+
return $placeholder;
|
1720 |
+
};
|
1721 |
+
|
1722 |
+
Placeholder.prototype.update = function (decorated, data) {
|
1723 |
+
var singlePlaceholder = (
|
1724 |
+
data.length == 1 && data[0].id != this.placeholder.id
|
1725 |
+
);
|
1726 |
+
var multipleSelections = data.length > 1;
|
1727 |
+
|
1728 |
+
if (multipleSelections || singlePlaceholder) {
|
1729 |
+
return decorated.call(this, data);
|
1730 |
+
}
|
1731 |
+
|
1732 |
+
this.clear();
|
1733 |
+
|
1734 |
+
var $placeholder = this.createPlaceholder(this.placeholder);
|
1735 |
+
|
1736 |
+
this.$selection.find('.select2-selection__rendered').append($placeholder);
|
1737 |
+
};
|
1738 |
+
|
1739 |
+
return Placeholder;
|
1740 |
+
});
|
1741 |
+
|
1742 |
+
S2.define('select2/selection/allowClear',[
|
1743 |
+
'jquery',
|
1744 |
+
'../keys'
|
1745 |
+
], function ($, KEYS) {
|
1746 |
+
function AllowClear () { }
|
1747 |
+
|
1748 |
+
AllowClear.prototype.bind = function (decorated, container, $container) {
|
1749 |
+
var self = this;
|
1750 |
+
|
1751 |
+
decorated.call(this, container, $container);
|
1752 |
+
|
1753 |
+
if (this.placeholder == null) {
|
1754 |
+
if (this.options.get('debug') && window.console && console.error) {
|
1755 |
+
console.error(
|
1756 |
+
'Select2: The `allowClear` option should be used in combination ' +
|
1757 |
+
'with the `placeholder` option.'
|
1758 |
+
);
|
1759 |
+
}
|
1760 |
+
}
|
1761 |
+
|
1762 |
+
this.$selection.on('mousedown', '.select2-selection__clear',
|
1763 |
+
function (evt) {
|
1764 |
+
self._handleClear(evt);
|
1765 |
+
});
|
1766 |
+
|
1767 |
+
container.on('keypress', function (evt) {
|
1768 |
+
self._handleKeyboardClear(evt, container);
|
1769 |
+
});
|
1770 |
+
};
|
1771 |
+
|
1772 |
+
AllowClear.prototype._handleClear = function (_, evt) {
|
1773 |
+
// Ignore the event if it is disabled
|
1774 |
+
if (this.options.get('disabled')) {
|
1775 |
+
return;
|
1776 |
+
}
|
1777 |
+
|
1778 |
+
var $clear = this.$selection.find('.select2-selection__clear');
|
1779 |
+
|
1780 |
+
// Ignore the event if nothing has been selected
|
1781 |
+
if ($clear.length === 0) {
|
1782 |
+
return;
|
1783 |
+
}
|
1784 |
+
|
1785 |
+
evt.stopPropagation();
|
1786 |
+
|
1787 |
+
var data = $clear.data('data');
|
1788 |
+
|
1789 |
+
for (var d = 0; d < data.length; d++) {
|
1790 |
+
var unselectData = {
|
1791 |
+
data: data[d]
|
1792 |
+
};
|
1793 |
+
|
1794 |
+
// Trigger the `unselect` event, so people can prevent it from being
|
1795 |
+
// cleared.
|
1796 |
+
this.trigger('unselect', unselectData);
|
1797 |
+
|
1798 |
+
// If the event was prevented, don't clear it out.
|
1799 |
+
if (unselectData.prevented) {
|
1800 |
+
return;
|
1801 |
+
}
|
1802 |
+
}
|
1803 |
+
|
1804 |
+
this.$element.val(this.placeholder.id).trigger('change');
|
1805 |
+
|
1806 |
+
this.trigger('toggle', {});
|
1807 |
+
};
|
1808 |
+
|
1809 |
+
AllowClear.prototype._handleKeyboardClear = function (_, evt, container) {
|
1810 |
+
if (container.isOpen()) {
|
1811 |
+
return;
|
1812 |
+
}
|
1813 |
+
|
1814 |
+
if (evt.which == KEYS.DELETE || evt.which == KEYS.BACKSPACE) {
|
1815 |
+
this._handleClear(evt);
|
1816 |
+
}
|
1817 |
+
};
|
1818 |
+
|
1819 |
+
AllowClear.prototype.update = function (decorated, data) {
|
1820 |
+
decorated.call(this, data);
|
1821 |
+
|
1822 |
+
if (this.$selection.find('.select2-selection__placeholder').length > 0 ||
|
1823 |
+
data.length === 0) {
|
1824 |
+
return;
|
1825 |
+
}
|
1826 |
+
|
1827 |
+
var $remove = $(
|
1828 |
+
'<span class="select2-selection__clear">' +
|
1829 |
+
'×' +
|
1830 |
+
'</span>'
|
1831 |
+
);
|
1832 |
+
$remove.data('data', data);
|
1833 |
+
|
1834 |
+
this.$selection.find('.select2-selection__rendered').prepend($remove);
|
1835 |
+
};
|
1836 |
+
|
1837 |
+
return AllowClear;
|
1838 |
+
});
|
1839 |
+
|
1840 |
+
S2.define('select2/selection/search',[
|
1841 |
+
'jquery',
|
1842 |
+
'../utils',
|
1843 |
+
'../keys'
|
1844 |
+
], function ($, Utils, KEYS) {
|
1845 |
+
function Search (decorated, $element, options) {
|
1846 |
+
decorated.call(this, $element, options);
|
1847 |
+
}
|
1848 |
+
|
1849 |
+
Search.prototype.render = function (decorated) {
|
1850 |
+
var $search = $(
|
1851 |
+
'<li class="select2-search select2-search--inline">' +
|
1852 |
+
'<input class="select2-search__field" type="search" tabindex="-1"' +
|
1853 |
+
' autocomplete="off" autocorrect="off" autocapitalize="off"' +
|
1854 |
+
' spellcheck="false" role="textbox" aria-autocomplete="list" />' +
|
1855 |
+
'</li>'
|
1856 |
+
);
|
1857 |
+
|
1858 |
+
this.$searchContainer = $search;
|
1859 |
+
this.$search = $search.find('input');
|
1860 |
+
|
1861 |
+
var $rendered = decorated.call(this);
|
1862 |
+
|
1863 |
+
this._transferTabIndex();
|
1864 |
+
|
1865 |
+
return $rendered;
|
1866 |
+
};
|
1867 |
+
|
1868 |
+
Search.prototype.bind = function (decorated, container, $container) {
|
1869 |
+
var self = this;
|
1870 |
+
|
1871 |
+
decorated.call(this, container, $container);
|
1872 |
+
|
1873 |
+
container.on('open', function () {
|
1874 |
+
self.$search.trigger('focus');
|
1875 |
+
});
|
1876 |
+
|
1877 |
+
container.on('close', function () {
|
1878 |
+
self.$search.val('');
|
1879 |
+
self.$search.removeAttr('aria-activedescendant');
|
1880 |
+
//self.$search.trigger('focus');
|
1881 |
+
});
|
1882 |
+
|
1883 |
+
container.on('enable', function () {
|
1884 |
+
self.$search.prop('disabled', false);
|
1885 |
+
|
1886 |
+
self._transferTabIndex();
|
1887 |
+
});
|
1888 |
+
|
1889 |
+
container.on('disable', function () {
|
1890 |
+
self.$search.prop('disabled', true);
|
1891 |
+
});
|
1892 |
+
|
1893 |
+
container.on('focus', function (evt) {
|
1894 |
+
self.$search.trigger('focus');
|
1895 |
+
});
|
1896 |
+
|
1897 |
+
container.on('results:focus', function (params) {
|
1898 |
+
self.$search.attr('aria-activedescendant', params.id);
|
1899 |
+
});
|
1900 |
+
|
1901 |
+
this.$selection.on('focusin', '.select2-search--inline', function (evt) {
|
1902 |
+
self.trigger('focus', evt);
|
1903 |
+
});
|
1904 |
+
|
1905 |
+
this.$selection.on('focusout', '.select2-search--inline', function (evt) {
|
1906 |
+
self._handleBlur(evt);
|
1907 |
+
});
|
1908 |
+
|
1909 |
+
this.$selection.on('keydown', '.select2-search--inline', function (evt) {
|
1910 |
+
evt.stopPropagation();
|
1911 |
+
|
1912 |
+
self.trigger('keypress', evt);
|
1913 |
+
|
1914 |
+
self._keyUpPrevented = evt.isDefaultPrevented();
|
1915 |
+
|
1916 |
+
var key = evt.which;
|
1917 |
+
|
1918 |
+
if (key === KEYS.BACKSPACE && self.$search.val() === '') {
|
1919 |
+
var $previousChoice = self.$searchContainer
|
1920 |
+
.prev('.select2-selection__choice');
|
1921 |
+
|
1922 |
+
if ($previousChoice.length > 0) {
|
1923 |
+
var item = $previousChoice.data('data');
|
1924 |
+
|
1925 |
+
self.searchRemoveChoice(item);
|
1926 |
+
|
1927 |
+
evt.preventDefault();
|
1928 |
+
}
|
1929 |
+
}
|
1930 |
+
});
|
1931 |
+
|
1932 |
+
// Try to detect the IE version should the `documentMode` property that
|
1933 |
+
// is stored on the document. This is only implemented in IE and is
|
1934 |
+
// slightly cleaner than doing a user agent check.
|
1935 |
+
// This property is not available in Edge, but Edge also doesn't have
|
1936 |
+
// this bug.
|
1937 |
+
var msie = document.documentMode;
|
1938 |
+
var disableInputEvents = msie && msie <= 11;
|
1939 |
+
|
1940 |
+
// Workaround for browsers which do not support the `input` event
|
1941 |
+
// This will prevent double-triggering of events for browsers which support
|
1942 |
+
// both the `keyup` and `input` events.
|
1943 |
+
this.$selection.on(
|
1944 |
+
'input.searchcheck',
|
1945 |
+
'.select2-search--inline',
|
1946 |
+
function (evt) {
|
1947 |
+
// IE will trigger the `input` event when a placeholder is used on a
|
1948 |
+
// search box. To get around this issue, we are forced to ignore all
|
1949 |
+
// `input` events in IE and keep using `keyup`.
|
1950 |
+
if (disableInputEvents) {
|
1951 |
+
self.$selection.off('input.search input.searchcheck');
|
1952 |
+
return;
|
1953 |
+
}
|
1954 |
+
|
1955 |
+
// Unbind the duplicated `keyup` event
|
1956 |
+
self.$selection.off('keyup.search');
|
1957 |
+
}
|
1958 |
+
);
|
1959 |
+
|
1960 |
+
this.$selection.on(
|
1961 |
+
'keyup.search input.search',
|
1962 |
+
'.select2-search--inline',
|
1963 |
+
function (evt) {
|
1964 |
+
// IE will trigger the `input` event when a placeholder is used on a
|
1965 |
+
// search box. To get around this issue, we are forced to ignore all
|
1966 |
+
// `input` events in IE and keep using `keyup`.
|
1967 |
+
if (disableInputEvents && evt.type === 'input') {
|
1968 |
+
self.$selection.off('input.search input.searchcheck');
|
1969 |
+
return;
|
1970 |
+
}
|
1971 |
+
|
1972 |
+
var key = evt.which;
|
1973 |
+
|
1974 |
+
// We can freely ignore events from modifier keys
|
1975 |
+
if (key == KEYS.SHIFT || key == KEYS.CTRL || key == KEYS.ALT) {
|
1976 |
+
return;
|
1977 |
+
}
|
1978 |
+
|
1979 |
+
// Tabbing will be handled during the `keydown` phase
|
1980 |
+
if (key == KEYS.TAB) {
|
1981 |
+
return;
|
1982 |
+
}
|
1983 |
+
|
1984 |
+
self.handleSearch(evt);
|
1985 |
+
}
|
1986 |
+
);
|
1987 |
+
};
|
1988 |
+
|
1989 |
+
/**
|
1990 |
+
* This method will transfer the tabindex attribute from the rendered
|
1991 |
+
* selection to the search box. This allows for the search box to be used as
|
1992 |
+
* the primary focus instead of the selection container.
|
1993 |
+
*
|
1994 |
+
* @private
|
1995 |
+
*/
|
1996 |
+
Search.prototype._transferTabIndex = function (decorated) {
|
1997 |
+
this.$search.attr('tabindex', this.$selection.attr('tabindex'));
|
1998 |
+
this.$selection.attr('tabindex', '-1');
|
1999 |
+
};
|
2000 |
+
|
2001 |
+
Search.prototype.createPlaceholder = function (decorated, placeholder) {
|
2002 |
+
this.$search.attr('placeholder', placeholder.text);
|
2003 |
+
};
|
2004 |
+
|
2005 |
+
Search.prototype.update = function (decorated, data) {
|
2006 |
+
var searchHadFocus = this.$search[0] == document.activeElement;
|
2007 |
+
|
2008 |
+
this.$search.attr('placeholder', '');
|
2009 |
+
|
2010 |
+
decorated.call(this, data);
|
2011 |
+
|
2012 |
+
this.$selection.find('.select2-selection__rendered')
|
2013 |
+
.append(this.$searchContainer);
|
2014 |
+
|
2015 |
+
this.resizeSearch();
|
2016 |
+
if (searchHadFocus) {
|
2017 |
+
this.$search.focus();
|
2018 |
+
}
|
2019 |
+
};
|
2020 |
+
|
2021 |
+
Search.prototype.handleSearch = function () {
|
2022 |
+
this.resizeSearch();
|
2023 |
+
|
2024 |
+
if (!this._keyUpPrevented) {
|
2025 |
+
var input = this.$search.val();
|
2026 |
+
|
2027 |
+
this.trigger('query', {
|
2028 |
+
term: input
|
2029 |
+
});
|
2030 |
+
}
|
2031 |
+
|
2032 |
+
this._keyUpPrevented = false;
|
2033 |
+
};
|
2034 |
+
|
2035 |
+
Search.prototype.searchRemoveChoice = function (decorated, item) {
|
2036 |
+
this.trigger('unselect', {
|
2037 |
+
data: item
|
2038 |
+
});
|
2039 |
+
|
2040 |
+
this.$search.val(item.text);
|
2041 |
+
this.handleSearch();
|
2042 |
+
};
|
2043 |
+
|
2044 |
+
Search.prototype.resizeSearch = function () {
|
2045 |
+
this.$search.css('width', '25px');
|
2046 |
+
|
2047 |
+
var width = '';
|
2048 |
+
|
2049 |
+
if (this.$search.attr('placeholder') !== '') {
|
2050 |
+
width = this.$selection.find('.select2-selection__rendered').innerWidth();
|
2051 |
+
} else {
|
2052 |
+
var minimumWidth = this.$search.val().length + 1;
|
2053 |
+
|
2054 |
+
width = (minimumWidth * 0.75) + 'em';
|
2055 |
+
}
|
2056 |
+
|
2057 |
+
this.$search.css('width', width);
|
2058 |
+
};
|
2059 |
+
|
2060 |
+
return Search;
|
2061 |
+
});
|
2062 |
+
|
2063 |
+
S2.define('select2/selection/eventRelay',[
|
2064 |
+
'jquery'
|
2065 |
+
], function ($) {
|
2066 |
+
function EventRelay () { }
|
2067 |
+
|
2068 |
+
EventRelay.prototype.bind = function (decorated, container, $container) {
|
2069 |
+
var self = this;
|
2070 |
+
var relayEvents = [
|
2071 |
+
'open', 'opening',
|
2072 |
+
'close', 'closing',
|
2073 |
+
'select', 'selecting',
|
2074 |
+
'unselect', 'unselecting'
|
2075 |
+
];
|
2076 |
+
|
2077 |
+
var preventableEvents = ['opening', 'closing', 'selecting', 'unselecting'];
|
2078 |
+
|
2079 |
+
decorated.call(this, container, $container);
|
2080 |
+
|
2081 |
+
container.on('*', function (name, params) {
|
2082 |
+
// Ignore events that should not be relayed
|
2083 |
+
if ($.inArray(name, relayEvents) === -1) {
|
2084 |
+
return;
|
2085 |
+
}
|
2086 |
+
|
2087 |
+
// The parameters should always be an object
|
2088 |
+
params = params || {};
|
2089 |
+
|
2090 |
+
// Generate the jQuery event for the Select2 event
|
2091 |
+
var evt = $.Event('select2:' + name, {
|
2092 |
+
params: params
|
2093 |
+
});
|
2094 |
+
|
2095 |
+
self.$element.trigger(evt);
|
2096 |
+
|
2097 |
+
// Only handle preventable events if it was one
|
2098 |
+
if ($.inArray(name, preventableEvents) === -1) {
|
2099 |
+
return;
|
2100 |
+
}
|
2101 |
+
|
2102 |
+
params.prevented = evt.isDefaultPrevented();
|
2103 |
+
});
|
2104 |
+
};
|
2105 |
+
|
2106 |
+
return EventRelay;
|
2107 |
+
});
|
2108 |
+
|
2109 |
+
S2.define('select2/translation',[
|
2110 |
+
'jquery',
|
2111 |
+
'require'
|
2112 |
+
], function ($, require) {
|
2113 |
+
function Translation (dict) {
|
2114 |
+
this.dict = dict || {};
|
2115 |
+
}
|
2116 |
+
|
2117 |
+
Translation.prototype.all = function () {
|
2118 |
+
return this.dict;
|
2119 |
+
};
|
2120 |
+
|
2121 |
+
Translation.prototype.get = function (key) {
|
2122 |
+
return this.dict[key];
|
2123 |
+
};
|
2124 |
+
|
2125 |
+
Translation.prototype.extend = function (translation) {
|
2126 |
+
this.dict = $.extend({}, translation.all(), this.dict);
|
2127 |
+
};
|
2128 |
+
|
2129 |
+
// Static functions
|
2130 |
+
|
2131 |
+
Translation._cache = {};
|
2132 |
+
|
2133 |
+
Translation.loadPath = function (path) {
|
2134 |
+
if (!(path in Translation._cache)) {
|
2135 |
+
var translations = require(path);
|
2136 |
+
|
2137 |
+
Translation._cache[path] = translations;
|
2138 |
+
}
|
2139 |
+
|
2140 |
+
return new Translation(Translation._cache[path]);
|
2141 |
+
};
|
2142 |
+
|
2143 |
+
return Translation;
|
2144 |
+
});
|
2145 |
+
|
2146 |
+
S2.define('select2/diacritics',[
|
2147 |
+
|
2148 |
+
], function () {
|
2149 |
+
var diacritics = {
|
2150 |
+
'\u24B6': 'A',
|
2151 |
+
'\uFF21': 'A',
|
2152 |
+
'\u00C0': 'A',
|
2153 |
+
'\u00C1': 'A',
|
2154 |
+
'\u00C2': 'A',
|
2155 |
+
'\u1EA6': 'A',
|
2156 |
+
'\u1EA4': 'A',
|
2157 |
+
'\u1EAA': 'A',
|
2158 |
+
'\u1EA8': 'A',
|
2159 |
+
'\u00C3': 'A',
|
2160 |
+
'\u0100': 'A',
|
2161 |
+
'\u0102': 'A',
|
2162 |
+
'\u1EB0': 'A',
|
2163 |
+
'\u1EAE': 'A',
|
2164 |
+
'\u1EB4': 'A',
|
2165 |
+
'\u1EB2': 'A',
|
2166 |
+
'\u0226': 'A',
|
2167 |
+
'\u01E0': 'A',
|
2168 |
+
'\u00C4': 'A',
|
2169 |
+
'\u01DE': 'A',
|
2170 |
+
'\u1EA2': 'A',
|
2171 |
+
'\u00C5': 'A',
|
2172 |
+
'\u01FA': 'A',
|
2173 |
+
'\u01CD': 'A',
|
2174 |
+
'\u0200': 'A',
|
2175 |
+
'\u0202': 'A',
|
2176 |
+
'\u1EA0': 'A',
|
2177 |
+
'\u1EAC': 'A',
|
2178 |
+
'\u1EB6': 'A',
|
2179 |
+
'\u1E00': 'A',
|
2180 |
+
'\u0104': 'A',
|
2181 |
+
'\u023A': 'A',
|
2182 |
+
'\u2C6F': 'A',
|
2183 |
+
'\uA732': 'AA',
|
2184 |
+
'\u00C6': 'AE',
|
2185 |
+
'\u01FC': 'AE',
|
2186 |
+
'\u01E2': 'AE',
|
2187 |
+
'\uA734': 'AO',
|
2188 |
+
'\uA736': 'AU',
|
2189 |
+
'\uA738': 'AV',
|
2190 |
+
'\uA73A': 'AV',
|
2191 |
+
'\uA73C': 'AY',
|
2192 |
+
'\u24B7': 'B',
|
2193 |
+
'\uFF22': 'B',
|
2194 |
+
'\u1E02': 'B',
|
2195 |
+
'\u1E04': 'B',
|
2196 |
+
'\u1E06': 'B',
|
2197 |
+
'\u0243': 'B',
|
2198 |
+
'\u0182': 'B',
|
2199 |
+
'\u0181': 'B',
|
2200 |
+
'\u24B8': 'C',
|
2201 |
+
'\uFF23': 'C',
|
2202 |
+
'\u0106': 'C',
|
2203 |
+
'\u0108': 'C',
|
2204 |
+
'\u010A': 'C',
|
2205 |
+
'\u010C': 'C',
|
2206 |
+
'\u00C7': 'C',
|
2207 |
+
'\u1E08': 'C',
|
2208 |
+
'\u0187': 'C',
|
2209 |
+
'\u023B': 'C',
|
2210 |
+
'\uA73E': 'C',
|
2211 |
+
'\u24B9': 'D',
|
2212 |
+
'\uFF24': 'D',
|
2213 |
+
'\u1E0A': 'D',
|
2214 |
+
'\u010E': 'D',
|
2215 |
+
'\u1E0C': 'D',
|
2216 |
+
'\u1E10': 'D',
|
2217 |
+
'\u1E12': 'D',
|
2218 |
+
'\u1E0E': 'D',
|
2219 |
+
'\u0110': 'D',
|
2220 |
+
'\u018B': 'D',
|
2221 |
+
'\u018A': 'D',
|
2222 |
+
'\u0189': 'D',
|
2223 |
+
'\uA779': 'D',
|
2224 |
+
'\u01F1': 'DZ',
|
2225 |
+
'\u01C4': 'DZ',
|
2226 |
+
'\u01F2': 'Dz',
|
2227 |
+
'\u01C5': 'Dz',
|
2228 |
+
'\u24BA': 'E',
|
2229 |
+
'\uFF25': 'E',
|
2230 |
+
'\u00C8': 'E',
|
2231 |
+
'\u00C9': 'E',
|
2232 |
+
'\u00CA': 'E',
|
2233 |
+
'\u1EC0': 'E',
|
2234 |
+
'\u1EBE': 'E',
|
2235 |
+
'\u1EC4': 'E',
|
2236 |
+
'\u1EC2': 'E',
|
2237 |
+
'\u1EBC': 'E',
|
2238 |
+
'\u0112': 'E',
|
2239 |
+
'\u1E14': 'E',
|
2240 |
+
'\u1E16': 'E',
|
2241 |
+
'\u0114': 'E',
|
2242 |
+
'\u0116': 'E',
|
2243 |
+
'\u00CB': 'E',
|
2244 |
+
'\u1EBA': 'E',
|
2245 |
+
'\u011A': 'E',
|
2246 |
+
'\u0204': 'E',
|
2247 |
+
'\u0206': 'E',
|
2248 |
+
'\u1EB8': 'E',
|
2249 |
+
'\u1EC6': 'E',
|
2250 |
+
'\u0228': 'E',
|
2251 |
+
'\u1E1C': 'E',
|
2252 |
+
'\u0118': 'E',
|
2253 |
+
'\u1E18': 'E',
|
2254 |
+
'\u1E1A': 'E',
|
2255 |
+
'\u0190': 'E',
|
2256 |
+
'\u018E': 'E',
|
2257 |
+
'\u24BB': 'F',
|
2258 |
+
'\uFF26': 'F',
|
2259 |
+
'\u1E1E': 'F',
|
2260 |
+
'\u0191': 'F',
|
2261 |
+
'\uA77B': 'F',
|
2262 |
+
'\u24BC': 'G',
|
2263 |
+
'\uFF27': 'G',
|
2264 |
+
'\u01F4': 'G',
|
2265 |
+
'\u011C': 'G',
|
2266 |
+
'\u1E20': 'G',
|
2267 |
+
'\u011E': 'G',
|
2268 |
+
'\u0120': 'G',
|
2269 |
+
'\u01E6': 'G',
|
2270 |
+
'\u0122': 'G',
|
2271 |
+
'\u01E4': 'G',
|
2272 |
+
'\u0193': 'G',
|
2273 |
+
'\uA7A0': 'G',
|
2274 |
+
'\uA77D': 'G',
|
2275 |
+
'\uA77E': 'G',
|
2276 |
+
'\u24BD': 'H',
|
2277 |
+
'\uFF28': 'H',
|
2278 |
+
'\u0124': 'H',
|
2279 |
+
'\u1E22': 'H',
|
2280 |
+
'\u1E26': 'H',
|
2281 |
+
'\u021E': 'H',
|
2282 |
+
'\u1E24': 'H',
|
2283 |
+
'\u1E28': 'H',
|
2284 |
+
'\u1E2A': 'H',
|
2285 |
+
'\u0126': 'H',
|
2286 |
+
'\u2C67': 'H',
|
2287 |
+
'\u2C75': 'H',
|
2288 |
+
'\uA78D': 'H',
|
2289 |
+
'\u24BE': 'I',
|
2290 |
+
'\uFF29': 'I',
|
2291 |
+
'\u00CC': 'I',
|
2292 |
+
'\u00CD': 'I',
|
2293 |
+
'\u00CE': 'I',
|
2294 |
+
'\u0128': 'I',
|
2295 |
+
'\u012A': 'I',
|
2296 |
+
'\u012C': 'I',
|
2297 |
+
'\u0130': 'I',
|
2298 |
+
'\u00CF': 'I',
|
2299 |
+
'\u1E2E': 'I',
|
2300 |
+
'\u1EC8': 'I',
|
2301 |
+
'\u01CF': 'I',
|
2302 |
+
'\u0208': 'I',
|
2303 |
+
'\u020A': 'I',
|
2304 |
+
'\u1ECA': 'I',
|
2305 |
+
'\u012E': 'I',
|
2306 |
+
'\u1E2C': 'I',
|
2307 |
+
'\u0197': 'I',
|
2308 |
+
'\u24BF': 'J',
|
2309 |
+
'\uFF2A': 'J',
|
2310 |
+
'\u0134': 'J',
|
2311 |
+
'\u0248': 'J',
|
2312 |
+
'\u24C0': 'K',
|
2313 |
+
'\uFF2B': 'K',
|
2314 |
+
'\u1E30': 'K',
|
2315 |
+
'\u01E8': 'K',
|
2316 |
+
'\u1E32': 'K',
|
2317 |
+
'\u0136': 'K',
|
2318 |
+
'\u1E34': 'K',
|
2319 |
+
'\u0198': 'K',
|
2320 |
+
'\u2C69': 'K',
|
2321 |
+
'\uA740': 'K',
|
2322 |
+
'\uA742': 'K',
|
2323 |
+
'\uA744': 'K',
|
2324 |
+
'\uA7A2': 'K',
|
2325 |
+
'\u24C1': 'L',
|
2326 |
+
'\uFF2C': 'L',
|
2327 |
+
'\u013F': 'L',
|
2328 |
+
'\u0139': 'L',
|
2329 |
+
'\u013D': 'L',
|
2330 |
+
'\u1E36': 'L',
|
2331 |
+
'\u1E38': 'L',
|
2332 |
+
'\u013B': 'L',
|
2333 |
+
'\u1E3C': 'L',
|
2334 |
+
'\u1E3A': 'L',
|
2335 |
+
'\u0141': 'L',
|
2336 |
+
'\u023D': 'L',
|
2337 |
+
'\u2C62': 'L',
|
2338 |
+
'\u2C60': 'L',
|
2339 |
+
'\uA748': 'L',
|
2340 |
+
'\uA746': 'L',
|
2341 |
+
'\uA780': 'L',
|
2342 |
+
'\u01C7': 'LJ',
|
2343 |
+
'\u01C8': 'Lj',
|
2344 |
+
'\u24C2': 'M',
|
2345 |
+
'\uFF2D': 'M',
|
2346 |
+
'\u1E3E': 'M',
|
2347 |
+
'\u1E40': 'M',
|
2348 |
+
'\u1E42': 'M',
|
2349 |
+
'\u2C6E': 'M',
|
2350 |
+
'\u019C': 'M',
|
2351 |
+
'\u24C3': 'N',
|
2352 |
+
'\uFF2E': 'N',
|
2353 |
+
'\u01F8': 'N',
|
2354 |
+
'\u0143': 'N',
|
2355 |
+
'\u00D1': 'N',
|
2356 |
+
'\u1E44': 'N',
|
2357 |
+
'\u0147': 'N',
|
2358 |
+
'\u1E46': 'N',
|
2359 |
+
'\u0145': 'N',
|
2360 |
+
'\u1E4A': 'N',
|
2361 |
+
'\u1E48': 'N',
|
2362 |
+
'\u0220': 'N',
|
2363 |
+
'\u019D': 'N',
|
2364 |
+
'\uA790': 'N',
|
2365 |
+
'\uA7A4': 'N',
|
2366 |
+
'\u01CA': 'NJ',
|
2367 |
+
'\u01CB': 'Nj',
|
2368 |
+
'\u24C4': 'O',
|
2369 |
+
'\uFF2F': 'O',
|
2370 |
+
'\u00D2': 'O',
|
2371 |
+
'\u00D3': 'O',
|
2372 |
+
'\u00D4': 'O',
|
2373 |
+
'\u1ED2': 'O',
|
2374 |
+
'\u1ED0': 'O',
|
2375 |
+
'\u1ED6': 'O',
|
2376 |
+
'\u1ED4': 'O',
|
2377 |
+
'\u00D5': 'O',
|
2378 |
+
'\u1E4C': 'O',
|
2379 |
+
'\u022C': 'O',
|
2380 |
+
'\u1E4E': 'O',
|
2381 |
+
'\u014C': 'O',
|
2382 |
+
'\u1E50': 'O',
|
2383 |
+
'\u1E52': 'O',
|
2384 |
+
'\u014E': 'O',
|
2385 |
+
'\u022E': 'O',
|
2386 |
+
'\u0230': 'O',
|
2387 |
+
'\u00D6': 'O',
|
2388 |
+
'\u022A': 'O',
|
2389 |
+
'\u1ECE': 'O',
|
2390 |
+
'\u0150': 'O',
|
2391 |
+
'\u01D1': 'O',
|
2392 |
+
'\u020C': 'O',
|
2393 |
+
'\u020E': 'O',
|
2394 |
+
'\u01A0': 'O',
|
2395 |
+
'\u1EDC': 'O',
|
2396 |
+
'\u1EDA': 'O',
|
2397 |
+
'\u1EE0': 'O',
|
2398 |
+
'\u1EDE': 'O',
|
2399 |
+
'\u1EE2': 'O',
|
2400 |
+
'\u1ECC': 'O',
|
2401 |
+
'\u1ED8': 'O',
|
2402 |
+
'\u01EA': 'O',
|
2403 |
+
'\u01EC': 'O',
|
2404 |
+
'\u00D8': 'O',
|
2405 |
+
'\u01FE': 'O',
|
2406 |
+
'\u0186': 'O',
|
2407 |
+
'\u019F': 'O',
|
2408 |
+
'\uA74A': 'O',
|
2409 |
+
'\uA74C': 'O',
|
2410 |
+
'\u01A2': 'OI',
|
2411 |
+
'\uA74E': 'OO',
|
2412 |
+
'\u0222': 'OU',
|
2413 |
+
'\u24C5': 'P',
|
2414 |
+
'\uFF30': 'P',
|
2415 |
+
'\u1E54': 'P',
|
2416 |
+
'\u1E56': 'P',
|
2417 |
+
'\u01A4': 'P',
|
2418 |
+
'\u2C63': 'P',
|
2419 |
+
'\uA750': 'P',
|
2420 |
+
'\uA752': 'P',
|
2421 |
+
'\uA754': 'P',
|
2422 |
+
'\u24C6': 'Q',
|
2423 |
+
'\uFF31': 'Q',
|
2424 |
+
'\uA756': 'Q',
|
2425 |
+
'\uA758': 'Q',
|
2426 |
+
'\u024A': 'Q',
|
2427 |
+
'\u24C7': 'R',
|
2428 |
+
'\uFF32': 'R',
|
2429 |
+
'\u0154': 'R',
|
2430 |
+
'\u1E58': 'R',
|
2431 |
+
'\u0158': 'R',
|
2432 |
+
'\u0210': 'R',
|
2433 |
+
'\u0212': 'R',
|
2434 |
+
'\u1E5A': 'R',
|
2435 |
+
'\u1E5C': 'R',
|
2436 |
+
'\u0156': 'R',
|
2437 |
+
'\u1E5E': 'R',
|
2438 |
+
'\u024C': 'R',
|
2439 |
+
'\u2C64': 'R',
|
2440 |
+
'\uA75A': 'R',
|
2441 |
+
'\uA7A6': 'R',
|
2442 |
+
'\uA782': 'R',
|
2443 |
+
'\u24C8': 'S',
|
2444 |
+
'\uFF33': 'S',
|
2445 |
+
'\u1E9E': 'S',
|
2446 |
+
'\u015A': 'S',
|
2447 |
+
'\u1E64': 'S',
|
2448 |
+
'\u015C': 'S',
|
2449 |
+
'\u1E60': 'S',
|
2450 |
+
'\u0160': 'S',
|
2451 |
+
'\u1E66': 'S',
|
2452 |
+
'\u1E62': 'S',
|
2453 |
+
'\u1E68': 'S',
|
2454 |
+
'\u0218': 'S',
|
2455 |
+
'\u015E': 'S',
|
2456 |
+
'\u2C7E': 'S',
|
2457 |
+
'\uA7A8': 'S',
|
2458 |
+
'\uA784': 'S',
|
2459 |
+
'\u24C9': 'T',
|
2460 |
+
'\uFF34': 'T',
|
2461 |
+
'\u1E6A': 'T',
|
2462 |
+
'\u0164': 'T',
|
2463 |
+
'\u1E6C': 'T',
|
2464 |
+
'\u021A': 'T',
|
2465 |
+
'\u0162': 'T',
|
2466 |
+
'\u1E70': 'T',
|
2467 |
+
'\u1E6E': 'T',
|
2468 |
+
'\u0166': 'T',
|
2469 |
+
'\u01AC': 'T',
|
2470 |
+
'\u01AE': 'T',
|
2471 |
+
'\u023E': 'T',
|
2472 |
+
'\uA786': 'T',
|
2473 |
+
'\uA728': 'TZ',
|
2474 |
+
'\u24CA': 'U',
|
2475 |
+
'\uFF35': 'U',
|
2476 |
+
'\u00D9': 'U',
|
2477 |
+
'\u00DA': 'U',
|
2478 |
+
'\u00DB': 'U',
|
2479 |
+
'\u0168': 'U',
|
2480 |
+
'\u1E78': 'U',
|
2481 |
+
'\u016A': 'U',
|
2482 |
+
'\u1E7A': 'U',
|
2483 |
+
'\u016C': 'U',
|
2484 |
+
'\u00DC': 'U',
|
2485 |
+
'\u01DB': 'U',
|
2486 |
+
'\u01D7': 'U',
|
2487 |
+
'\u01D5': 'U',
|
2488 |
+
'\u01D9': 'U',
|
2489 |
+
'\u1EE6': 'U',
|
2490 |
+
'\u016E': 'U',
|
2491 |
+
'\u0170': 'U',
|
2492 |
+
'\u01D3': 'U',
|
2493 |
+
'\u0214': 'U',
|
2494 |
+
'\u0216': 'U',
|
2495 |
+
'\u01AF': 'U',
|
2496 |
+
'\u1EEA': 'U',
|
2497 |
+
'\u1EE8': 'U',
|
2498 |
+
'\u1EEE': 'U',
|
2499 |
+
'\u1EEC': 'U',
|
2500 |
+
'\u1EF0': 'U',
|
2501 |
+
'\u1EE4': 'U',
|
2502 |
+
'\u1E72': 'U',
|
2503 |
+
'\u0172': 'U',
|
2504 |
+
'\u1E76': 'U',
|
2505 |
+
'\u1E74': 'U',
|
2506 |
+
'\u0244': 'U',
|
2507 |
+
'\u24CB': 'V',
|
2508 |
+
'\uFF36': 'V',
|
2509 |
+
'\u1E7C': 'V',
|
2510 |
+
'\u1E7E': 'V',
|
2511 |
+
'\u01B2': 'V',
|
2512 |
+
'\uA75E': 'V',
|
2513 |
+
'\u0245': 'V',
|
2514 |
+
'\uA760': 'VY',
|
2515 |
+
'\u24CC': 'W',
|
2516 |
+
'\uFF37': 'W',
|
2517 |
+
'\u1E80': 'W',
|
2518 |
+
'\u1E82': 'W',
|
2519 |
+
'\u0174': 'W',
|
2520 |
+
'\u1E86': 'W',
|
2521 |
+
'\u1E84': 'W',
|
2522 |
+
'\u1E88': 'W',
|
2523 |
+
'\u2C72': 'W',
|
2524 |
+
'\u24CD': 'X',
|
2525 |
+
'\uFF38': 'X',
|
2526 |
+
'\u1E8A': 'X',
|
2527 |
+
'\u1E8C': 'X',
|
2528 |
+
'\u24CE': 'Y',
|
2529 |
+
'\uFF39': 'Y',
|
2530 |
+
'\u1EF2': 'Y',
|
2531 |
+
'\u00DD': 'Y',
|
2532 |
+
'\u0176': 'Y',
|
2533 |
+
'\u1EF8': 'Y',
|
2534 |
+
'\u0232': 'Y',
|
2535 |
+
'\u1E8E': 'Y',
|
2536 |
+
'\u0178': 'Y',
|
2537 |
+
'\u1EF6': 'Y',
|
2538 |
+
'\u1EF4': 'Y',
|
2539 |
+
'\u01B3': 'Y',
|
2540 |
+
'\u024E': 'Y',
|
2541 |
+
'\u1EFE': 'Y',
|
2542 |
+
'\u24CF': 'Z',
|
2543 |
+
'\uFF3A': 'Z',
|
2544 |
+
'\u0179': 'Z',
|
2545 |
+
'\u1E90': 'Z',
|
2546 |
+
'\u017B': 'Z',
|
2547 |
+
'\u017D': 'Z',
|
2548 |
+
'\u1E92': 'Z',
|
2549 |
+
'\u1E94': 'Z',
|
2550 |
+
'\u01B5': 'Z',
|
2551 |
+
'\u0224': 'Z',
|
2552 |
+
'\u2C7F': 'Z',
|
2553 |
+
'\u2C6B': 'Z',
|
2554 |
+
'\uA762': 'Z',
|
2555 |
+
'\u24D0': 'a',
|
2556 |
+
'\uFF41': 'a',
|
2557 |
+
'\u1E9A': 'a',
|
2558 |
+
'\u00E0': 'a',
|
2559 |
+
'\u00E1': 'a',
|
2560 |
+
'\u00E2': 'a',
|
2561 |
+
'\u1EA7': 'a',
|
2562 |
+
'\u1EA5': 'a',
|
2563 |
+
'\u1EAB': 'a',
|
2564 |
+
'\u1EA9': 'a',
|
2565 |
+
'\u00E3': 'a',
|
2566 |
+
'\u0101': 'a',
|
2567 |
+
'\u0103': 'a',
|
2568 |
+
'\u1EB1': 'a',
|
2569 |
+
'\u1EAF': 'a',
|
2570 |
+
'\u1EB5': 'a',
|
2571 |
+
'\u1EB3': 'a',
|
2572 |
+
'\u0227': 'a',
|
2573 |
+
'\u01E1': 'a',
|
2574 |
+
'\u00E4': 'a',
|
2575 |
+
'\u01DF': 'a',
|
2576 |
+
'\u1EA3': 'a',
|
2577 |
+
'\u00E5': 'a',
|
2578 |
+
'\u01FB': 'a',
|
2579 |
+
'\u01CE': 'a',
|
2580 |
+
'\u0201': 'a',
|
2581 |
+
'\u0203': 'a',
|
2582 |
+
'\u1EA1': 'a',
|
2583 |
+
'\u1EAD': 'a',
|
2584 |
+
'\u1EB7': 'a',
|
2585 |
+
'\u1E01': 'a',
|
2586 |
+
'\u0105': 'a',
|
2587 |
+
'\u2C65': 'a',
|
2588 |
+
'\u0250': 'a',
|
2589 |
+
'\uA733': 'aa',
|
2590 |
+
'\u00E6': 'ae',
|
2591 |
+
'\u01FD': 'ae',
|
2592 |
+
'\u01E3': 'ae',
|
2593 |
+
'\uA735': 'ao',
|
2594 |
+
'\uA737': 'au',
|
2595 |
+
'\uA739': 'av',
|
2596 |
+
'\uA73B': 'av',
|
2597 |
+
'\uA73D': 'ay',
|
2598 |
+
'\u24D1': 'b',
|
2599 |
+
'\uFF42': 'b',
|
2600 |
+
'\u1E03': 'b',
|
2601 |
+
'\u1E05': 'b',
|
2602 |
+
'\u1E07': 'b',
|
2603 |
+
'\u0180': 'b',
|
2604 |
+
'\u0183': 'b',
|
2605 |
+
'\u0253': 'b',
|
2606 |
+
'\u24D2': 'c',
|
2607 |
+
'\uFF43': 'c',
|
2608 |
+
'\u0107': 'c',
|
2609 |
+
'\u0109': 'c',
|
2610 |
+
'\u010B': 'c',
|
2611 |
+
'\u010D': 'c',
|
2612 |
+
'\u00E7': 'c',
|
2613 |
+
'\u1E09': 'c',
|
2614 |
+
'\u0188': 'c',
|
2615 |
+
'\u023C': 'c',
|
2616 |
+
'\uA73F': 'c',
|
2617 |
+
'\u2184': 'c',
|
2618 |
+
'\u24D3': 'd',
|
2619 |
+
'\uFF44': 'd',
|
2620 |
+
'\u1E0B': 'd',
|
2621 |
+
'\u010F': 'd',
|
2622 |
+
'\u1E0D': 'd',
|
2623 |
+
'\u1E11': 'd',
|
2624 |
+
'\u1E13': 'd',
|
2625 |
+
'\u1E0F': 'd',
|
2626 |
+
'\u0111': 'd',
|
2627 |
+
'\u018C': 'd',
|
2628 |
+
'\u0256': 'd',
|
2629 |
+
'\u0257': 'd',
|
2630 |
+
'\uA77A': 'd',
|
2631 |
+
'\u01F3': 'dz',
|
2632 |
+
'\u01C6': 'dz',
|
2633 |
+
'\u24D4': 'e',
|
2634 |
+
'\uFF45': 'e',
|
2635 |
+
'\u00E8': 'e',
|
2636 |
+
'\u00E9': 'e',
|
2637 |
+
'\u00EA': 'e',
|
2638 |
+
'\u1EC1': 'e',
|
2639 |
+
'\u1EBF': 'e',
|
2640 |
+
'\u1EC5': 'e',
|
2641 |
+
'\u1EC3': 'e',
|
2642 |
+
'\u1EBD': 'e',
|
2643 |
+
'\u0113': 'e',
|
2644 |
+
'\u1E15': 'e',
|
2645 |
+
'\u1E17': 'e',
|
2646 |
+
'\u0115': 'e',
|
2647 |
+
'\u0117': 'e',
|
2648 |
+
'\u00EB': 'e',
|
2649 |
+
'\u1EBB': 'e',
|
2650 |
+
'\u011B': 'e',
|
2651 |
+
'\u0205': 'e',
|
2652 |
+
'\u0207': 'e',
|
2653 |
+
'\u1EB9': 'e',
|
2654 |
+
'\u1EC7': 'e',
|
2655 |
+
'\u0229': 'e',
|
2656 |
+
'\u1E1D': 'e',
|
2657 |
+
'\u0119': 'e',
|
2658 |
+
'\u1E19': 'e',
|
2659 |
+
'\u1E1B': 'e',
|
2660 |
+
'\u0247': 'e',
|
2661 |
+
'\u025B': 'e',
|
2662 |
+
'\u01DD': 'e',
|
2663 |
+
'\u24D5': 'f',
|
2664 |
+
'\uFF46': 'f',
|
2665 |
+
'\u1E1F': 'f',
|
2666 |
+
'\u0192': 'f',
|
2667 |
+
'\uA77C': 'f',
|
2668 |
+
'\u24D6': 'g',
|
2669 |
+
'\uFF47': 'g',
|
2670 |
+
'\u01F5': 'g',
|
2671 |
+
'\u011D': 'g',
|
2672 |
+
'\u1E21': 'g',
|
2673 |
+
'\u011F': 'g',
|
2674 |
+
'\u0121': 'g',
|
2675 |
+
'\u01E7': 'g',
|
2676 |
+
'\u0123': 'g',
|
2677 |
+
'\u01E5': 'g',
|
2678 |
+
'\u0260': 'g',
|
2679 |
+
'\uA7A1': 'g',
|
2680 |
+
'\u1D79': 'g',
|
2681 |
+
'\uA77F': 'g',
|
2682 |
+
'\u24D7': 'h',
|
2683 |
+
'\uFF48': 'h',
|
2684 |
+
'\u0125': 'h',
|
2685 |
+
'\u1E23': 'h',
|
2686 |
+
'\u1E27': 'h',
|
2687 |
+
'\u021F': 'h',
|
2688 |
+
'\u1E25': 'h',
|
2689 |
+
'\u1E29': 'h',
|
2690 |
+
'\u1E2B': 'h',
|
2691 |
+
'\u1E96': 'h',
|
2692 |
+
'\u0127': 'h',
|
2693 |
+
'\u2C68': 'h',
|
2694 |
+
'\u2C76': 'h',
|
2695 |
+
'\u0265': 'h',
|
2696 |
+
'\u0195': 'hv',
|
2697 |
+
'\u24D8': 'i',
|
2698 |
+
'\uFF49': 'i',
|
2699 |
+
'\u00EC': 'i',
|
2700 |
+
'\u00ED': 'i',
|
2701 |
+
'\u00EE': 'i',
|
2702 |
+
'\u0129': 'i',
|
2703 |
+
'\u012B': 'i',
|
2704 |
+
'\u012D': 'i',
|
2705 |
+
'\u00EF': 'i',
|
2706 |
+
'\u1E2F': 'i',
|
2707 |
+
'\u1EC9': 'i',
|
2708 |
+
'\u01D0': 'i',
|
2709 |
+
'\u0209': 'i',
|
2710 |
+
'\u020B': 'i',
|
2711 |
+
'\u1ECB': 'i',
|
2712 |
+
'\u012F': 'i',
|
2713 |
+
'\u1E2D': 'i',
|
2714 |
+
'\u0268': 'i',
|
2715 |
+
'\u0131': 'i',
|
2716 |
+
'\u24D9': 'j',
|
2717 |
+
'\uFF4A': 'j',
|
2718 |
+
'\u0135': 'j',
|
2719 |
+
'\u01F0': 'j',
|
2720 |
+
'\u0249': 'j',
|
2721 |
+
'\u24DA': 'k',
|
2722 |
+
'\uFF4B': 'k',
|
2723 |
+
'\u1E31': 'k',
|
2724 |
+
'\u01E9': 'k',
|
2725 |
+
'\u1E33': 'k',
|
2726 |
+
'\u0137': 'k',
|
2727 |
+
'\u1E35': 'k',
|
2728 |
+
'\u0199': 'k',
|
2729 |
+
'\u2C6A': 'k',
|
2730 |
+
'\uA741': 'k',
|
2731 |
+
'\uA743': 'k',
|
2732 |
+
'\uA745': 'k',
|
2733 |
+
'\uA7A3': 'k',
|
2734 |
+
'\u24DB': 'l',
|
2735 |
+
'\uFF4C': 'l',
|
2736 |
+
'\u0140': 'l',
|
2737 |
+
'\u013A': 'l',
|
2738 |
+
'\u013E': 'l',
|
2739 |
+
'\u1E37': 'l',
|
2740 |
+
'\u1E39': 'l',
|
2741 |
+
'\u013C': 'l',
|
2742 |
+
'\u1E3D': 'l',
|
2743 |
+
'\u1E3B': 'l',
|
2744 |
+
'\u017F': 'l',
|
2745 |
+
'\u0142': 'l',
|
2746 |
+
'\u019A': 'l',
|
2747 |
+
'\u026B': 'l',
|
2748 |
+
'\u2C61': 'l',
|
2749 |
+
'\uA749': 'l',
|
2750 |
+
'\uA781': 'l',
|
2751 |
+
'\uA747': 'l',
|
2752 |
+
'\u01C9': 'lj',
|
2753 |
+
'\u24DC': 'm',
|
2754 |
+
'\uFF4D': 'm',
|
2755 |
+
'\u1E3F': 'm',
|
2756 |
+
'\u1E41': 'm',
|
2757 |
+
'\u1E43': 'm',
|
2758 |
+
'\u0271': 'm',
|
2759 |
+
'\u026F': 'm',
|
2760 |
+
'\u24DD': 'n',
|
2761 |
+
'\uFF4E': 'n',
|
2762 |
+
'\u01F9': 'n',
|
2763 |
+
'\u0144': 'n',
|
2764 |
+
'\u00F1': 'n',
|
2765 |
+
'\u1E45': 'n',
|
2766 |
+
'\u0148': 'n',
|
2767 |
+
'\u1E47': 'n',
|
2768 |
+
'\u0146': 'n',
|
2769 |
+
'\u1E4B': 'n',
|
2770 |
+
'\u1E49': 'n',
|
2771 |
+
'\u019E': 'n',
|
2772 |
+
'\u0272': 'n',
|
2773 |
+
'\u0149': 'n',
|
2774 |
+
'\uA791': 'n',
|
2775 |
+
'\uA7A5': 'n',
|
2776 |
+
'\u01CC': 'nj',
|
2777 |
+
'\u24DE': 'o',
|
2778 |
+
'\uFF4F': 'o',
|
2779 |
+
'\u00F2': 'o',
|
2780 |
+
'\u00F3': 'o',
|
2781 |
+
'\u00F4': 'o',
|
2782 |
+
'\u1ED3': 'o',
|
2783 |
+
'\u1ED1': 'o',
|
2784 |
+
'\u1ED7': 'o',
|
2785 |
+
'\u1ED5': 'o',
|
2786 |
+
'\u00F5': 'o',
|
2787 |
+
'\u1E4D': 'o',
|
2788 |
+
'\u022D': 'o',
|
2789 |
+
'\u1E4F': 'o',
|
2790 |
+
'\u014D': 'o',
|
2791 |
+
'\u1E51': 'o',
|
2792 |
+
'\u1E53': 'o',
|
2793 |
+
'\u014F': 'o',
|
2794 |
+
'\u022F': 'o',
|
2795 |
+
'\u0231': 'o',
|
2796 |
+
'\u00F6': 'o',
|
2797 |
+
'\u022B': 'o',
|
2798 |
+
'\u1ECF': 'o',
|
2799 |
+
'\u0151': 'o',
|
2800 |
+
'\u01D2': 'o',
|
2801 |
+
'\u020D': 'o',
|
2802 |
+
'\u020F': 'o',
|
2803 |
+
'\u01A1': 'o',
|
2804 |
+
'\u1EDD': 'o',
|
2805 |
+
'\u1EDB': 'o',
|
2806 |
+
'\u1EE1': 'o',
|
2807 |
+
'\u1EDF': 'o',
|
2808 |
+
'\u1EE3': 'o',
|
2809 |
+
'\u1ECD': 'o',
|
2810 |
+
'\u1ED9': 'o',
|
2811 |
+
'\u01EB': 'o',
|
2812 |
+
'\u01ED': 'o',
|
2813 |
+
'\u00F8': 'o',
|
2814 |
+
'\u01FF': 'o',
|
2815 |
+
'\u0254': 'o',
|
2816 |
+
'\uA74B': 'o',
|
2817 |
+
'\uA74D': 'o',
|
2818 |
+
'\u0275': 'o',
|
2819 |
+
'\u01A3': 'oi',
|
2820 |
+
'\u0223': 'ou',
|
2821 |
+
'\uA74F': 'oo',
|
2822 |
+
'\u24DF': 'p',
|
2823 |
+
'\uFF50': 'p',
|
2824 |
+
'\u1E55': 'p',
|
2825 |
+
'\u1E57': 'p',
|
2826 |
+
'\u01A5': 'p',
|
2827 |
+
'\u1D7D': 'p',
|
2828 |
+
'\uA751': 'p',
|
2829 |
+
'\uA753': 'p',
|
2830 |
+
'\uA755': 'p',
|
2831 |
+
'\u24E0': 'q',
|
2832 |
+
'\uFF51': 'q',
|
2833 |
+
'\u024B': 'q',
|
2834 |
+
'\uA757': 'q',
|
2835 |
+
'\uA759': 'q',
|
2836 |
+
'\u24E1': 'r',
|
2837 |
+
'\uFF52': 'r',
|
2838 |
+
'\u0155': 'r',
|
2839 |
+
'\u1E59': 'r',
|
2840 |
+
'\u0159': 'r',
|
2841 |
+
'\u0211': 'r',
|
2842 |
+
'\u0213': 'r',
|
2843 |
+
'\u1E5B': 'r',
|
2844 |
+
'\u1E5D': 'r',
|
2845 |
+
'\u0157': 'r',
|
2846 |
+
'\u1E5F': 'r',
|
2847 |
+
'\u024D': 'r',
|
2848 |
+
'\u027D': 'r',
|
2849 |
+
'\uA75B': 'r',
|
2850 |
+
'\uA7A7': 'r',
|
2851 |
+
'\uA783': 'r',
|
2852 |
+
'\u24E2': 's',
|
2853 |
+
'\uFF53': 's',
|
2854 |
+
'\u00DF': 's',
|
2855 |
+
'\u015B': 's',
|
2856 |
+
'\u1E65': 's',
|
2857 |
+
'\u015D': 's',
|
2858 |
+
'\u1E61': 's',
|
2859 |
+
'\u0161': 's',
|
2860 |
+
'\u1E67': 's',
|
2861 |
+
'\u1E63': 's',
|
2862 |
+
'\u1E69': 's',
|
2863 |
+
'\u0219': 's',
|
2864 |
+
'\u015F': 's',
|
2865 |
+
'\u023F': 's',
|
2866 |
+
'\uA7A9': 's',
|
2867 |
+
'\uA785': 's',
|
2868 |
+
'\u1E9B': 's',
|
2869 |
+
'\u24E3': 't',
|
2870 |
+
'\uFF54': 't',
|
2871 |
+
'\u1E6B': 't',
|
2872 |
+
'\u1E97': 't',
|
2873 |
+
'\u0165': 't',
|
2874 |
+
'\u1E6D': 't',
|
2875 |
+
'\u021B': 't',
|
2876 |
+
'\u0163': 't',
|
2877 |
+
'\u1E71': 't',
|
2878 |
+
'\u1E6F': 't',
|
2879 |
+
'\u0167': 't',
|
2880 |
+
'\u01AD': 't',
|
2881 |
+
'\u0288': 't',
|
2882 |
+
'\u2C66': 't',
|
2883 |
+
'\uA787': 't',
|
2884 |
+
'\uA729': 'tz',
|
2885 |
+
'\u24E4': 'u',
|
2886 |
+
'\uFF55': 'u',
|
2887 |
+
'\u00F9': 'u',
|
2888 |
+
'\u00FA': 'u',
|
2889 |
+
'\u00FB': 'u',
|
2890 |
+
'\u0169': 'u',
|
2891 |
+
'\u1E79': 'u',
|
2892 |
+
'\u016B': 'u',
|
2893 |
+
'\u1E7B': 'u',
|
2894 |
+
'\u016D': 'u',
|
2895 |
+
'\u00FC': 'u',
|
2896 |
+
'\u01DC': 'u',
|
2897 |
+
'\u01D8': 'u',
|
2898 |
+
'\u01D6': 'u',
|
2899 |
+
'\u01DA': 'u',
|
2900 |
+
'\u1EE7': 'u',
|
2901 |
+
'\u016F': 'u',
|
2902 |
+
'\u0171': 'u',
|
2903 |
+
'\u01D4': 'u',
|
2904 |
+
'\u0215': 'u',
|
2905 |
+
'\u0217': 'u',
|
2906 |
+
'\u01B0': 'u',
|
2907 |
+
'\u1EEB': 'u',
|
2908 |
+
'\u1EE9': 'u',
|
2909 |
+
'\u1EEF': 'u',
|
2910 |
+
'\u1EED': 'u',
|
2911 |
+
'\u1EF1': 'u',
|
2912 |
+
'\u1EE5': 'u',
|
2913 |
+
'\u1E73': 'u',
|
2914 |
+
'\u0173': 'u',
|
2915 |
+
'\u1E77': 'u',
|
2916 |
+
'\u1E75': 'u',
|
2917 |
+
'\u0289': 'u',
|
2918 |
+
'\u24E5': 'v',
|
2919 |
+
'\uFF56': 'v',
|
2920 |
+
'\u1E7D': 'v',
|
2921 |
+
'\u1E7F': 'v',
|
2922 |
+
'\u028B': 'v',
|
2923 |
+
'\uA75F': 'v',
|
2924 |
+
'\u028C': 'v',
|
2925 |
+
'\uA761': 'vy',
|
2926 |
+
'\u24E6': 'w',
|
2927 |
+
'\uFF57': 'w',
|
2928 |
+
'\u1E81': 'w',
|
2929 |
+
'\u1E83': 'w',
|
2930 |
+
'\u0175': 'w',
|
2931 |
+
'\u1E87': 'w',
|
2932 |
+
'\u1E85': 'w',
|
2933 |
+
'\u1E98': 'w',
|
2934 |
+
'\u1E89': 'w',
|
2935 |
+
'\u2C73': 'w',
|
2936 |
+
'\u24E7': 'x',
|
2937 |
+
'\uFF58': 'x',
|
2938 |
+
'\u1E8B': 'x',
|
2939 |
+
'\u1E8D': 'x',
|
2940 |
+
'\u24E8': 'y',
|
2941 |
+
'\uFF59': 'y',
|
2942 |
+
'\u1EF3': 'y',
|
2943 |
+
'\u00FD': 'y',
|
2944 |
+
'\u0177': 'y',
|
2945 |
+
'\u1EF9': 'y',
|
2946 |
+
'\u0233': 'y',
|
2947 |
+
'\u1E8F': 'y',
|
2948 |
+
'\u00FF': 'y',
|
2949 |
+
'\u1EF7': 'y',
|
2950 |
+
'\u1E99': 'y',
|
2951 |
+
'\u1EF5': 'y',
|
2952 |
+
'\u01B4': 'y',
|
2953 |
+
'\u024F': 'y',
|
2954 |
+
'\u1EFF': 'y',
|
2955 |
+
'\u24E9': 'z',
|
2956 |
+
'\uFF5A': 'z',
|
2957 |
+
'\u017A': 'z',
|
2958 |
+
'\u1E91': 'z',
|
2959 |
+
'\u017C': 'z',
|
2960 |
+
'\u017E': 'z',
|
2961 |
+
'\u1E93': 'z',
|
2962 |
+
'\u1E95': 'z',
|
2963 |
+
'\u01B6': 'z',
|
2964 |
+
'\u0225': 'z',
|
2965 |
+
'\u0240': 'z',
|
2966 |
+
'\u2C6C': 'z',
|
2967 |
+
'\uA763': 'z',
|
2968 |
+
'\u0386': '\u0391',
|
2969 |
+
'\u0388': '\u0395',
|
2970 |
+
'\u0389': '\u0397',
|
2971 |
+
'\u038A': '\u0399',
|
2972 |
+
'\u03AA': '\u0399',
|
2973 |
+
'\u038C': '\u039F',
|
2974 |
+
'\u038E': '\u03A5',
|
2975 |
+
'\u03AB': '\u03A5',
|
2976 |
+
'\u038F': '\u03A9',
|
2977 |
+
'\u03AC': '\u03B1',
|
2978 |
+
'\u03AD': '\u03B5',
|
2979 |
+
'\u03AE': '\u03B7',
|
2980 |
+
'\u03AF': '\u03B9',
|
2981 |
+
'\u03CA': '\u03B9',
|
2982 |
+
'\u0390': '\u03B9',
|
2983 |
+
'\u03CC': '\u03BF',
|
2984 |
+
'\u03CD': '\u03C5',
|
2985 |
+
'\u03CB': '\u03C5',
|
2986 |
+
'\u03B0': '\u03C5',
|
2987 |
+
'\u03C9': '\u03C9',
|
2988 |
+
'\u03C2': '\u03C3'
|
2989 |
+
};
|
2990 |
+
|
2991 |
+
return diacritics;
|
2992 |
+
});
|
2993 |
+
|
2994 |
+
S2.define('select2/data/base',[
|
2995 |
+
'../utils'
|
2996 |
+
], function (Utils) {
|
2997 |
+
function BaseAdapter ($element, options) {
|
2998 |
+
BaseAdapter.__super__.constructor.call(this);
|
2999 |
+
}
|
3000 |
+
|
3001 |
+
Utils.Extend(BaseAdapter, Utils.Observable);
|
3002 |
+
|
3003 |
+
BaseAdapter.prototype.current = function (callback) {
|
3004 |
+
throw new Error('The `current` method must be defined in child classes.');
|
3005 |
+
};
|
3006 |
+
|
3007 |
+
BaseAdapter.prototype.query = function (params, callback) {
|
3008 |
+
throw new Error('The `query` method must be defined in child classes.');
|
3009 |
+
};
|
3010 |
+
|
3011 |
+
BaseAdapter.prototype.bind = function (container, $container) {
|
3012 |
+
// Can be implemented in subclasses
|
3013 |
+
};
|
3014 |
+
|
3015 |
+
BaseAdapter.prototype.destroy = function () {
|
3016 |
+
// Can be implemented in subclasses
|
3017 |
+
};
|
3018 |
+
|
3019 |
+
BaseAdapter.prototype.generateResultId = function (container, data) {
|
3020 |
+
var id = container.id + '-result-';
|
3021 |
+
|
3022 |
+
id += Utils.generateChars(4);
|
3023 |
+
|
3024 |
+
if (data.id != null) {
|
3025 |
+
id += '-' + data.id.toString();
|
3026 |
+
} else {
|
3027 |
+
id += '-' + Utils.generateChars(4);
|
3028 |
+
}
|
3029 |
+
return id;
|
3030 |
+
};
|
3031 |
+
|
3032 |
+
return BaseAdapter;
|
3033 |
+
});
|
3034 |
+
|
3035 |
+
S2.define('select2/data/select',[
|
3036 |
+
'./base',
|
3037 |
+
'../utils',
|
3038 |
+
'jquery'
|
3039 |
+
], function (BaseAdapter, Utils, $) {
|
3040 |
+
function SelectAdapter ($element, options) {
|
3041 |
+
this.$element = $element;
|
3042 |
+
this.options = options;
|
3043 |
+
|
3044 |
+
SelectAdapter.__super__.constructor.call(this);
|
3045 |
+
}
|
3046 |
+
|
3047 |
+
Utils.Extend(SelectAdapter, BaseAdapter);
|
3048 |
+
|
3049 |
+
SelectAdapter.prototype.current = function (callback) {
|
3050 |
+
var data = [];
|
3051 |
+
var self = this;
|
3052 |
+
|
3053 |
+
this.$element.find(':selected').each(function () {
|
3054 |
+
var $option = $(this);
|
3055 |
+
|
3056 |
+
var option = self.item($option);
|
3057 |
+
|
3058 |
+
data.push(option);
|
3059 |
+
});
|
3060 |
+
|
3061 |
+
callback(data);
|
3062 |
+
};
|
3063 |
+
|
3064 |
+
SelectAdapter.prototype.select = function (data) {
|
3065 |
+
var self = this;
|
3066 |
+
|
3067 |
+
data.selected = true;
|
3068 |
+
|
3069 |
+
// If data.element is a DOM node, use it instead
|
3070 |
+
if ($(data.element).is('option')) {
|
3071 |
+
data.element.selected = true;
|
3072 |
+
|
3073 |
+
this.$element.trigger('change');
|
3074 |
+
|
3075 |
+
return;
|
3076 |
+
}
|
3077 |
+
|
3078 |
+
if (this.$element.prop('multiple')) {
|
3079 |
+
this.current(function (currentData) {
|
3080 |
+
var val = [];
|
3081 |
+
|
3082 |
+
data = [data];
|
3083 |
+
data.push.apply(data, currentData);
|
3084 |
+
|
3085 |
+
for (var d = 0; d < data.length; d++) {
|
3086 |
+
var id = data[d].id;
|
3087 |
+
|
3088 |
+
if ($.inArray(id, val) === -1) {
|
3089 |
+
val.push(id);
|
3090 |
+
}
|
3091 |
+
}
|
3092 |
+
|
3093 |
+
self.$element.val(val);
|
3094 |
+
self.$element.trigger('change');
|
3095 |
+
});
|
3096 |
+
} else {
|
3097 |
+
var val = data.id;
|
3098 |
+
|
3099 |
+
this.$element.val(val);
|
3100 |
+
this.$element.trigger('change');
|
3101 |
+
}
|
3102 |
+
};
|
3103 |
+
|
3104 |
+
SelectAdapter.prototype.unselect = function (data) {
|
3105 |
+
var self = this;
|
3106 |
+
|
3107 |
+
if (!this.$element.prop('multiple')) {
|
3108 |
+
return;
|
3109 |
+
}
|
3110 |
+
|
3111 |
+
data.selected = false;
|
3112 |
+
|
3113 |
+
if ($(data.element).is('option')) {
|
3114 |
+
data.element.selected = false;
|
3115 |
+
|
3116 |
+
this.$element.trigger('change');
|
3117 |
+
|
3118 |
+
return;
|
3119 |
+
}
|
3120 |
+
|
3121 |
+
this.current(function (currentData) {
|
3122 |
+
var val = [];
|
3123 |
+
|
3124 |
+
for (var d = 0; d < currentData.length; d++) {
|
3125 |
+
var id = currentData[d].id;
|
3126 |
+
|
3127 |
+
if (id !== data.id && $.inArray(id, val) === -1) {
|
3128 |
+
val.push(id);
|
3129 |
+
}
|
3130 |
+
}
|
3131 |
+
|
3132 |
+
self.$element.val(val);
|
3133 |
+
|
3134 |
+
self.$element.trigger('change');
|
3135 |
+
});
|
3136 |
+
};
|
3137 |
+
|
3138 |
+
SelectAdapter.prototype.bind = function (container, $container) {
|
3139 |
+
var self = this;
|
3140 |
+
|
3141 |
+
this.container = container;
|
3142 |
+
|
3143 |
+
container.on('select', function (params) {
|
3144 |
+
self.select(params.data);
|
3145 |
+
});
|
3146 |
+
|
3147 |
+
container.on('unselect', function (params) {
|
3148 |
+
self.unselect(params.data);
|
3149 |
+
});
|
3150 |
+
};
|
3151 |
+
|
3152 |
+
SelectAdapter.prototype.destroy = function () {
|
3153 |
+
// Remove anything added to child elements
|
3154 |
+
this.$element.find('*').each(function () {
|
3155 |
+
// Remove any custom data set by Select2
|
3156 |
+
$.removeData(this, 'data');
|
3157 |
+
});
|
3158 |
+
};
|
3159 |
+
|
3160 |
+
SelectAdapter.prototype.query = function (params, callback) {
|
3161 |
+
var data = [];
|
3162 |
+
var self = this;
|
3163 |
+
|
3164 |
+
var $options = this.$element.children();
|
3165 |
+
|
3166 |
+
$options.each(function () {
|
3167 |
+
var $option = $(this);
|
3168 |
+
|
3169 |
+
if (!$option.is('option') && !$option.is('optgroup')) {
|
3170 |
+
return;
|
3171 |
+
}
|
3172 |
+
|
3173 |
+
var option = self.item($option);
|
3174 |
+
|
3175 |
+
var matches = self.matches(params, option);
|
3176 |
+
|
3177 |
+
if (matches !== null) {
|
3178 |
+
data.push(matches);
|
3179 |
+
}
|
3180 |
+
});
|
3181 |
+
|
3182 |
+
callback({
|
3183 |
+
results: data
|
3184 |
+
});
|
3185 |
+
};
|
3186 |
+
|
3187 |
+
SelectAdapter.prototype.addOptions = function ($options) {
|
3188 |
+
Utils.appendMany(this.$element, $options);
|
3189 |
+
};
|
3190 |
+
|
3191 |
+
SelectAdapter.prototype.option = function (data) {
|
3192 |
+
var option;
|
3193 |
+
|
3194 |
+
if (data.children) {
|
3195 |
+
option = document.createElement('optgroup');
|
3196 |
+
option.label = data.text;
|
3197 |
+
} else {
|
3198 |
+
option = document.createElement('option');
|
3199 |
+
|
3200 |
+
if (option.textContent !== undefined) {
|
3201 |
+
option.textContent = data.text;
|
3202 |
+
} else {
|
3203 |
+
option.innerText = data.text;
|
3204 |
+
}
|
3205 |
+
}
|
3206 |
+
|
3207 |
+
if (data.id) {
|
3208 |
+
option.value = data.id;
|
3209 |
+
}
|
3210 |
+
|
3211 |
+
if (data.disabled) {
|
3212 |
+
option.disabled = true;
|
3213 |
+
}
|
3214 |
+
|
3215 |
+
if (data.selected) {
|
3216 |
+
option.selected = true;
|
3217 |
+
}
|
3218 |
+
|
3219 |
+
if (data.title) {
|
3220 |
+
option.title = data.title;
|
3221 |
+
}
|
3222 |
+
|
3223 |
+
var $option = $(option);
|
3224 |
+
|
3225 |
+
var normalizedData = this._normalizeItem(data);
|
3226 |
+
normalizedData.element = option;
|
3227 |
+
|
3228 |
+
// Override the option's data with the combined data
|
3229 |
+
$.data(option, 'data', normalizedData);
|
3230 |
+
|
3231 |
+
return $option;
|
3232 |
+
};
|
3233 |
+
|
3234 |
+
SelectAdapter.prototype.item = function ($option) {
|
3235 |
+
var data = {};
|
3236 |
+
|
3237 |
+
data = $.data($option[0], 'data');
|
3238 |
+
|
3239 |
+
if (data != null) {
|
3240 |
+
return data;
|
3241 |
+
}
|
3242 |
+
|
3243 |
+
if ($option.is('option')) {
|
3244 |
+
data = {
|
3245 |
+
id: $option.val(),
|
3246 |
+
text: $option.text(),
|
3247 |
+
disabled: $option.prop('disabled'),
|
3248 |
+
selected: $option.prop('selected'),
|
3249 |
+
title: $option.prop('title')
|
3250 |
+
};
|
3251 |
+
} else if ($option.is('optgroup')) {
|
3252 |
+
data = {
|
3253 |
+
text: $option.prop('label'),
|
3254 |
+
children: [],
|
3255 |
+
title: $option.prop('title')
|
3256 |
+
};
|
3257 |
+
|
3258 |
+
var $children = $option.children('option');
|
3259 |
+
var children = [];
|
3260 |
+
|
3261 |
+
for (var c = 0; c < $children.length; c++) {
|
3262 |
+
var $child = $($children[c]);
|
3263 |
+
|
3264 |
+
var child = this.item($child);
|
3265 |
+
|
3266 |
+
children.push(child);
|
3267 |
+
}
|
3268 |
+
|
3269 |
+
data.children = children;
|
3270 |
+
}
|
3271 |
+
|
3272 |
+
data = this._normalizeItem(data);
|
3273 |
+
data.element = $option[0];
|
3274 |
+
|
3275 |
+
$.data($option[0], 'data', data);
|
3276 |
+
|
3277 |
+
return data;
|
3278 |
+
};
|
3279 |
+
|
3280 |
+
SelectAdapter.prototype._normalizeItem = function (item) {
|
3281 |
+
if (!$.isPlainObject(item)) {
|
3282 |
+
item = {
|
3283 |
+
id: item,
|
3284 |
+
text: item
|
3285 |
+
};
|
3286 |
+
}
|
3287 |
+
|
3288 |
+
item = $.extend({}, {
|
3289 |
+
text: ''
|
3290 |
+
}, item);
|
3291 |
+
|
3292 |
+
var defaults = {
|
3293 |
+
selected: false,
|
3294 |
+
disabled: false
|
3295 |
+
};
|
3296 |
+
|
3297 |
+
if (item.id != null) {
|
3298 |
+
item.id = item.id.toString();
|
3299 |
+
}
|
3300 |
+
|
3301 |
+
if (item.text != null) {
|
3302 |
+
item.text = item.text.toString();
|
3303 |
+
}
|
3304 |
+
|
3305 |
+
if (item._resultId == null && item.id && this.container != null) {
|
3306 |
+
item._resultId = this.generateResultId(this.container, item);
|
3307 |
+
}
|
3308 |
+
|
3309 |
+
return $.extend({}, defaults, item);
|
3310 |
+
};
|
3311 |
+
|
3312 |
+
SelectAdapter.prototype.matches = function (params, data) {
|
3313 |
+
var matcher = this.options.get('matcher');
|
3314 |
+
|
3315 |
+
return matcher(params, data);
|
3316 |
+
};
|
3317 |
+
|
3318 |
+
return SelectAdapter;
|
3319 |
+
});
|
3320 |
+
|
3321 |
+
S2.define('select2/data/array',[
|
3322 |
+
'./select',
|
3323 |
+
'../utils',
|
3324 |
+
'jquery'
|
3325 |
+
], function (SelectAdapter, Utils, $) {
|
3326 |
+
function ArrayAdapter ($element, options) {
|
3327 |
+
var data = options.get('data') || [];
|
3328 |
+
|
3329 |
+
ArrayAdapter.__super__.constructor.call(this, $element, options);
|
3330 |
+
|
3331 |
+
this.addOptions(this.convertToOptions(data));
|
3332 |
+
}
|
3333 |
+
|
3334 |
+
Utils.Extend(ArrayAdapter, SelectAdapter);
|
3335 |
+
|
3336 |
+
ArrayAdapter.prototype.select = function (data) {
|
3337 |
+
var $option = this.$element.find('option').filter(function (i, elm) {
|
3338 |
+
return elm.value == data.id.toString();
|
3339 |
+
});
|
3340 |
+
|
3341 |
+
if ($option.length === 0) {
|
3342 |
+
$option = this.option(data);
|
3343 |
+
|
3344 |
+
this.addOptions($option);
|
3345 |
+
}
|
3346 |
+
|
3347 |
+
ArrayAdapter.__super__.select.call(this, data);
|
3348 |
+
};
|
3349 |
+
|
3350 |
+
ArrayAdapter.prototype.convertToOptions = function (data) {
|
3351 |
+
var self = this;
|
3352 |
+
|
3353 |
+
var $existing = this.$element.find('option');
|
3354 |
+
var existingIds = $existing.map(function () {
|
3355 |
+
return self.item($(this)).id;
|
3356 |
+
}).get();
|
3357 |
+
|
3358 |
+
var $options = [];
|
3359 |
+
|
3360 |
+
// Filter out all items except for the one passed in the argument
|
3361 |
+
function onlyItem (item) {
|
3362 |
+
return function () {
|
3363 |
+
return $(this).val() == item.id;
|
3364 |
+
};
|
3365 |
+
}
|
3366 |
+
|
3367 |
+
for (var d = 0; d < data.length; d++) {
|
3368 |
+
var item = this._normalizeItem(data[d]);
|
3369 |
+
|
3370 |
+
// Skip items which were pre-loaded, only merge the data
|
3371 |
+
if ($.inArray(item.id, existingIds) >= 0) {
|
3372 |
+
var $existingOption = $existing.filter(onlyItem(item));
|
3373 |
+
|
3374 |
+
var existingData = this.item($existingOption);
|
3375 |
+
var newData = $.extend(true, {}, item, existingData);
|
3376 |
+
|
3377 |
+
var $newOption = this.option(newData);
|
3378 |
+
|
3379 |
+
$existingOption.replaceWith($newOption);
|
3380 |
+
|
3381 |
+
continue;
|
3382 |
+
}
|
3383 |
+
|
3384 |
+
var $option = this.option(item);
|
3385 |
+
|
3386 |
+
if (item.children) {
|
3387 |
+
var $children = this.convertToOptions(item.children);
|
3388 |
+
|
3389 |
+
Utils.appendMany($option, $children);
|
3390 |
+
}
|
3391 |
+
|
3392 |
+
$options.push($option);
|
3393 |
+
}
|
3394 |
+
|
3395 |
+
return $options;
|
3396 |
+
};
|
3397 |
+
|
3398 |
+
return ArrayAdapter;
|
3399 |
+
});
|
3400 |
+
|
3401 |
+
S2.define('select2/data/ajax',[
|
3402 |
+
'./array',
|
3403 |
+
'../utils',
|
3404 |
+
'jquery'
|
3405 |
+
], function (ArrayAdapter, Utils, $) {
|
3406 |
+
function AjaxAdapter ($element, options) {
|
3407 |
+
this.ajaxOptions = this._applyDefaults(options.get('ajax'));
|
3408 |
+
|
3409 |
+
if (this.ajaxOptions.processResults != null) {
|
3410 |
+
this.processResults = this.ajaxOptions.processResults;
|
3411 |
+
}
|
3412 |
+
|
3413 |
+
AjaxAdapter.__super__.constructor.call(this, $element, options);
|
3414 |
+
}
|
3415 |
+
|
3416 |
+
Utils.Extend(AjaxAdapter, ArrayAdapter);
|
3417 |
+
|
3418 |
+
AjaxAdapter.prototype._applyDefaults = function (options) {
|
3419 |
+
var defaults = {
|
3420 |
+
data: function (params) {
|
3421 |
+
return $.extend({}, params, {
|
3422 |
+
q: params.term
|
3423 |
+
});
|
3424 |
+
},
|
3425 |
+
transport: function (params, success, failure) {
|
3426 |
+
var $request = $.ajax(params);
|
3427 |
+
|
3428 |
+
$request.then(success);
|
3429 |
+
$request.fail(failure);
|
3430 |
+
|
3431 |
+
return $request;
|
3432 |
+
}
|
3433 |
+
};
|
3434 |
+
|
3435 |
+
return $.extend({}, defaults, options, true);
|
3436 |
+
};
|
3437 |
+
|
3438 |
+
AjaxAdapter.prototype.processResults = function (results) {
|
3439 |
+
return results;
|
3440 |
+
};
|
3441 |
+
|
3442 |
+
AjaxAdapter.prototype.query = function (params, callback) {
|
3443 |
+
var matches = [];
|
3444 |
+
var self = this;
|
3445 |
+
|
3446 |
+
if (this._request != null) {
|
3447 |
+
// JSONP requests cannot always be aborted
|
3448 |
+
if ($.isFunction(this._request.abort)) {
|
3449 |
+
this._request.abort();
|
3450 |
+
}
|
3451 |
+
|
3452 |
+
this._request = null;
|
3453 |
+
}
|
3454 |
+
|
3455 |
+
var options = $.extend({
|
3456 |
+
type: 'GET'
|
3457 |
+
}, this.ajaxOptions);
|
3458 |
+
|
3459 |
+
if (typeof options.url === 'function') {
|
3460 |
+
options.url = options.url.call(this.$element, params);
|
3461 |
+
}
|
3462 |
+
|
3463 |
+
if (typeof options.data === 'function') {
|
3464 |
+
options.data = options.data.call(this.$element, params);
|
3465 |
+
}
|
3466 |
+
|
3467 |
+
function request () {
|
3468 |
+
var $request = options.transport(options, function (data) {
|
3469 |
+
var results = self.processResults(data, params);
|
3470 |
+
|
3471 |
+
if (self.options.get('debug') && window.console && console.error) {
|
3472 |
+
// Check to make sure that the response included a `results` key.
|
3473 |
+
if (!results || !results.results || !$.isArray(results.results)) {
|
3474 |
+
console.error(
|
3475 |
+
'Select2: The AJAX results did not return an array in the ' +
|
3476 |
+
'`results` key of the response.'
|
3477 |
+
);
|
3478 |
+
}
|
3479 |
+
}
|
3480 |
+
|
3481 |
+
callback(results);
|
3482 |
+
}, function () {
|
3483 |
+
// Attempt to detect if a request was aborted
|
3484 |
+
// Only works if the transport exposes a status property
|
3485 |
+
if ($request.status && $request.status === '0') {
|
3486 |
+
return;
|
3487 |
+
}
|
3488 |
+
|
3489 |
+
self.trigger('results:message', {
|
3490 |
+
message: 'errorLoading'
|
3491 |
+
});
|
3492 |
+
});
|
3493 |
+
|
3494 |
+
self._request = $request;
|
3495 |
+
}
|
3496 |
+
|
3497 |
+
if (this.ajaxOptions.delay && params.term != null) {
|
3498 |
+
if (this._queryTimeout) {
|
3499 |
+
window.clearTimeout(this._queryTimeout);
|
3500 |
+
}
|
3501 |
+
|
3502 |
+
this._queryTimeout = window.setTimeout(request, this.ajaxOptions.delay);
|
3503 |
+
} else {
|
3504 |
+
request();
|
3505 |
+
}
|
3506 |
+
};
|
3507 |
+
|
3508 |
+
return AjaxAdapter;
|
3509 |
+
});
|
3510 |
+
|
3511 |
+
S2.define('select2/data/tags',[
|
3512 |
+
'jquery'
|
3513 |
+
], function ($) {
|
3514 |
+
function Tags (decorated, $element, options) {
|
3515 |
+
var tags = options.get('tags');
|
3516 |
+
|
3517 |
+
var createTag = options.get('createTag');
|
3518 |
+
|
3519 |
+
if (createTag !== undefined) {
|
3520 |
+
this.createTag = createTag;
|
3521 |
+
}
|
3522 |
+
|
3523 |
+
var insertTag = options.get('insertTag');
|
3524 |
+
|
3525 |
+
if (insertTag !== undefined) {
|
3526 |
+
this.insertTag = insertTag;
|
3527 |
+
}
|
3528 |
+
|
3529 |
+
decorated.call(this, $element, options);
|
3530 |
+
|
3531 |
+
if ($.isArray(tags)) {
|
3532 |
+
for (var t = 0; t < tags.length; t++) {
|
3533 |
+
var tag = tags[t];
|
3534 |
+
var item = this._normalizeItem(tag);
|
3535 |
+
|
3536 |
+
var $option = this.option(item);
|
3537 |
+
|
3538 |
+
this.$element.append($option);
|
3539 |
+
}
|
3540 |
+
}
|
3541 |
+
}
|
3542 |
+
|
3543 |
+
Tags.prototype.query = function (decorated, params, callback) {
|
3544 |
+
var self = this;
|
3545 |
+
|
3546 |
+
this._removeOldTags();
|
3547 |
+
|
3548 |
+
if (params.term == null || params.page != null) {
|
3549 |
+
decorated.call(this, params, callback);
|
3550 |
+
return;
|
3551 |
+
}
|
3552 |
+
|
3553 |
+
function wrapper (obj, child) {
|
3554 |
+
var data = obj.results;
|
3555 |
+
|
3556 |
+
for (var i = 0; i < data.length; i++) {
|
3557 |
+
var option = data[i];
|
3558 |
+
|
3559 |
+
var checkChildren = (
|
3560 |
+
option.children != null &&
|
3561 |
+
!wrapper({
|
3562 |
+
results: option.children
|
3563 |
+
}, true)
|
3564 |
+
);
|
3565 |
+
|
3566 |
+
var checkText = option.text === params.term;
|
3567 |
+
|
3568 |
+
if (checkText || checkChildren) {
|
3569 |
+
if (child) {
|
3570 |
+
return false;
|
3571 |
+
}
|
3572 |
+
|
3573 |
+
obj.data = data;
|
3574 |
+
callback(obj);
|
3575 |
+
|
3576 |
+
return;
|
3577 |
+
}
|
3578 |
+
}
|
3579 |
+
|
3580 |
+
if (child) {
|
3581 |
+
return true;
|
3582 |
+
}
|
3583 |
+
|
3584 |
+
var tag = self.createTag(params);
|
3585 |
+
|
3586 |
+
if (tag != null) {
|
3587 |
+
var $option = self.option(tag);
|
3588 |
+
$option.attr('data-select2-tag', true);
|
3589 |
+
|
3590 |
+
self.addOptions([$option]);
|
3591 |
+
|
3592 |
+
self.insertTag(data, tag);
|
3593 |
+
}
|
3594 |
+
|
3595 |
+
obj.results = data;
|
3596 |
+
|
3597 |
+
callback(obj);
|
3598 |
+
}
|
3599 |
+
|
3600 |
+
decorated.call(this, params, wrapper);
|
3601 |
+
};
|
3602 |
+
|
3603 |
+
Tags.prototype.createTag = function (decorated, params) {
|
3604 |
+
var term = $.trim(params.term);
|
3605 |
+
|
3606 |
+
if (term === '') {
|
3607 |
+
return null;
|
3608 |
+
}
|
3609 |
+
|
3610 |
+
return {
|
3611 |
+
id: term,
|
3612 |
+
text: term
|
3613 |
+
};
|
3614 |
+
};
|
3615 |
+
|
3616 |
+
Tags.prototype.insertTag = function (_, data, tag) {
|
3617 |
+
data.unshift(tag);
|
3618 |
+
};
|
3619 |
+
|
3620 |
+
Tags.prototype._removeOldTags = function (_) {
|
3621 |
+
var tag = this._lastTag;
|
3622 |
+
|
3623 |
+
var $options = this.$element.find('option[data-select2-tag]');
|
3624 |
+
|
3625 |
+
$options.each(function () {
|
3626 |
+
if (this.selected) {
|
3627 |
+
return;
|
3628 |
+
}
|
3629 |
+
|
3630 |
+
$(this).remove();
|
3631 |
+
});
|
3632 |
+
};
|
3633 |
+
|
3634 |
+
return Tags;
|
3635 |
+
});
|
3636 |
+
|
3637 |
+
S2.define('select2/data/tokenizer',[
|
3638 |
+
'jquery'
|
3639 |
+
], function ($) {
|
3640 |
+
function Tokenizer (decorated, $element, options) {
|
3641 |
+
var tokenizer = options.get('tokenizer');
|
3642 |
+
|
3643 |
+
if (tokenizer !== undefined) {
|
3644 |
+
this.tokenizer = tokenizer;
|
3645 |
+
}
|
3646 |
+
|
3647 |
+
decorated.call(this, $element, options);
|
3648 |
+
}
|
3649 |
+
|
3650 |
+
Tokenizer.prototype.bind = function (decorated, container, $container) {
|
3651 |
+
decorated.call(this, container, $container);
|
3652 |
+
|
3653 |
+
this.$search = container.dropdown.$search || container.selection.$search ||
|
3654 |
+
$container.find('.select2-search__field');
|
3655 |
+
};
|
3656 |
+
|
3657 |
+
Tokenizer.prototype.query = function (decorated, params, callback) {
|
3658 |
+
var self = this;
|
3659 |
+
|
3660 |
+
function createAndSelect (data) {
|
3661 |
+
// Normalize the data object so we can use it for checks
|
3662 |
+
var item = self._normalizeItem(data);
|
3663 |
+
|
3664 |
+
// Check if the data object already exists as a tag
|
3665 |
+
// Select it if it doesn't
|
3666 |
+
var $existingOptions = self.$element.find('option').filter(function () {
|
3667 |
+
return $(this).val() === item.id;
|
3668 |
+
});
|
3669 |
+
|
3670 |
+
// If an existing option wasn't found for it, create the option
|
3671 |
+
if (!$existingOptions.length) {
|
3672 |
+
var $option = self.option(item);
|
3673 |
+
$option.attr('data-select2-tag', true);
|
3674 |
+
|
3675 |
+
self._removeOldTags();
|
3676 |
+
self.addOptions([$option]);
|
3677 |
+
}
|
3678 |
+
|
3679 |
+
// Select the item, now that we know there is an option for it
|
3680 |
+
select(item);
|
3681 |
+
}
|
3682 |
+
|
3683 |
+
function select (data) {
|
3684 |
+
self.trigger('select', {
|
3685 |
+
data: data
|
3686 |
+
});
|
3687 |
+
}
|
3688 |
+
|
3689 |
+
params.term = params.term || '';
|
3690 |
+
|
3691 |
+
var tokenData = this.tokenizer(params, this.options, createAndSelect);
|
3692 |
+
|
3693 |
+
if (tokenData.term !== params.term) {
|
3694 |
+
// Replace the search term if we have the search box
|
3695 |
+
if (this.$search.length) {
|
3696 |
+
this.$search.val(tokenData.term);
|
3697 |
+
this.$search.focus();
|
3698 |
+
}
|
3699 |
+
|
3700 |
+
params.term = tokenData.term;
|
3701 |
+
}
|
3702 |
+
|
3703 |
+
decorated.call(this, params, callback);
|
3704 |
+
};
|
3705 |
+
|
3706 |
+
Tokenizer.prototype.tokenizer = function (_, params, options, callback) {
|
3707 |
+
var separators = options.get('tokenSeparators') || [];
|
3708 |
+
var term = params.term;
|
3709 |
+
var i = 0;
|
3710 |
+
|
3711 |
+
var createTag = this.createTag || function (params) {
|
3712 |
+
return {
|
3713 |
+
id: params.term,
|
3714 |
+
text: params.term
|
3715 |
+
};
|
3716 |
+
};
|
3717 |
+
|
3718 |
+
while (i < term.length) {
|
3719 |
+
var termChar = term[i];
|
3720 |
+
|
3721 |
+
if ($.inArray(termChar, separators) === -1) {
|
3722 |
+
i++;
|
3723 |
+
|
3724 |
+
continue;
|
3725 |
+
}
|
3726 |
+
|
3727 |
+
var part = term.substr(0, i);
|
3728 |
+
var partParams = $.extend({}, params, {
|
3729 |
+
term: part
|
3730 |
+
});
|
3731 |
+
|
3732 |
+
var data = createTag(partParams);
|
3733 |
+
|
3734 |
+
if (data == null) {
|
3735 |
+
i++;
|
3736 |
+
continue;
|
3737 |
+
}
|
3738 |
+
|
3739 |
+
callback(data);
|
3740 |
+
|
3741 |
+
// Reset the term to not include the tokenized portion
|
3742 |
+
term = term.substr(i + 1) || '';
|
3743 |
+
i = 0;
|
3744 |
+
}
|
3745 |
+
|
3746 |
+
return {
|
3747 |
+
term: term
|
3748 |
+
};
|
3749 |
+
};
|
3750 |
+
|
3751 |
+
return Tokenizer;
|
3752 |
+
});
|
3753 |
+
|
3754 |
+
S2.define('select2/data/minimumInputLength',[
|
3755 |
+
|
3756 |
+
], function () {
|
3757 |
+
function MinimumInputLength (decorated, $e, options) {
|
3758 |
+
this.minimumInputLength = options.get('minimumInputLength');
|
3759 |
+
|
3760 |
+
decorated.call(this, $e, options);
|
3761 |
+
}
|
3762 |
+
|
3763 |
+
MinimumInputLength.prototype.query = function (decorated, params, callback) {
|
3764 |
+
params.term = params.term || '';
|
3765 |
+
|
3766 |
+
if (params.term.length < this.minimumInputLength) {
|
3767 |
+
this.trigger('results:message', {
|
3768 |
+
message: 'inputTooShort',
|
3769 |
+
args: {
|
3770 |
+
minimum: this.minimumInputLength,
|
3771 |
+
input: params.term,
|
3772 |
+
params: params
|
3773 |
+
}
|
3774 |
+
});
|
3775 |
+
|
3776 |
+
return;
|
3777 |
+
}
|
3778 |
+
|
3779 |
+
decorated.call(this, params, callback);
|
3780 |
+
};
|
3781 |
+
|
3782 |
+
return MinimumInputLength;
|
3783 |
+
});
|
3784 |
+
|
3785 |
+
S2.define('select2/data/maximumInputLength',[
|
3786 |
+
|
3787 |
+
], function () {
|
3788 |
+
function MaximumInputLength (decorated, $e, options) {
|
3789 |
+
this.maximumInputLength = options.get('maximumInputLength');
|
3790 |
+
|
3791 |
+
decorated.call(this, $e, options);
|
3792 |
+
}
|
3793 |
+
|
3794 |
+
MaximumInputLength.prototype.query = function (decorated, params, callback) {
|
3795 |
+
params.term = params.term || '';
|
3796 |
+
|
3797 |
+
if (this.maximumInputLength > 0 &&
|
3798 |
+
params.term.length > this.maximumInputLength) {
|
3799 |
+
this.trigger('results:message', {
|
3800 |
+
message: 'inputTooLong',
|
3801 |
+
args: {
|
3802 |
+
maximum: this.maximumInputLength,
|
3803 |
+
input: params.term,
|
3804 |
+
params: params
|
3805 |
+
}
|
3806 |
+
});
|
3807 |
+
|
3808 |
+
return;
|
3809 |
+
}
|
3810 |
+
|
3811 |
+
decorated.call(this, params, callback);
|
3812 |
+
};
|
3813 |
+
|
3814 |
+
return MaximumInputLength;
|
3815 |
+
});
|
3816 |
+
|
3817 |
+
S2.define('select2/data/maximumSelectionLength',[
|
3818 |
+
|
3819 |
+
], function (){
|
3820 |
+
function MaximumSelectionLength (decorated, $e, options) {
|
3821 |
+
this.maximumSelectionLength = options.get('maximumSelectionLength');
|
3822 |
+
|
3823 |
+
decorated.call(this, $e, options);
|
3824 |
+
}
|
3825 |
+
|
3826 |
+
MaximumSelectionLength.prototype.query =
|
3827 |
+
function (decorated, params, callback) {
|
3828 |
+
var self = this;
|
3829 |
+
|
3830 |
+
this.current(function (currentData) {
|
3831 |
+
var count = currentData != null ? currentData.length : 0;
|
3832 |
+
if (self.maximumSelectionLength > 0 &&
|
3833 |
+
count >= self.maximumSelectionLength) {
|
3834 |
+
self.trigger('results:message', {
|
3835 |
+
message: 'maximumSelected',
|
3836 |
+
args: {
|
3837 |
+
maximum: self.maximumSelectionLength
|
3838 |
+
}
|
3839 |
+
});
|
3840 |
+
return;
|
3841 |
+
}
|
3842 |
+
decorated.call(self, params, callback);
|
3843 |
+
});
|
3844 |
+
};
|
3845 |
+
|
3846 |
+
return MaximumSelectionLength;
|
3847 |
+
});
|
3848 |
+
|
3849 |
+
S2.define('select2/dropdown',[
|
3850 |
+
'jquery',
|
3851 |
+
'./utils'
|
3852 |
+
], function ($, Utils) {
|
3853 |
+
function Dropdown ($element, options) {
|
3854 |
+
this.$element = $element;
|
3855 |
+
this.options = options;
|
3856 |
+
|
3857 |
+
Dropdown.__super__.constructor.call(this);
|
3858 |
+
}
|
3859 |
+
|
3860 |
+
Utils.Extend(Dropdown, Utils.Observable);
|
3861 |
+
|
3862 |
+
Dropdown.prototype.render = function () {
|
3863 |
+
var $dropdown = $(
|
3864 |
+
'<span class="select2-dropdown">' +
|
3865 |
+
'<span class="select2-results"></span>' +
|
3866 |
+
'</span>'
|
3867 |
+
);
|
3868 |
+
|
3869 |
+
$dropdown.attr('dir', this.options.get('dir'));
|
3870 |
+
|
3871 |
+
this.$dropdown = $dropdown;
|
3872 |
+
|
3873 |
+
return $dropdown;
|
3874 |
+
};
|
3875 |
+
|
3876 |
+
Dropdown.prototype.bind = function () {
|
3877 |
+
// Should be implemented in subclasses
|
3878 |
+
};
|
3879 |
+
|
3880 |
+
Dropdown.prototype.position = function ($dropdown, $container) {
|
3881 |
+
// Should be implmented in subclasses
|
3882 |
+
};
|
3883 |
+
|
3884 |
+
Dropdown.prototype.destroy = function () {
|
3885 |
+
// Remove the dropdown from the DOM
|
3886 |
+
this.$dropdown.remove();
|
3887 |
+
};
|
3888 |
+
|
3889 |
+
return Dropdown;
|
3890 |
+
});
|
3891 |
+
|
3892 |
+
S2.define('select2/dropdown/search',[
|
3893 |
+
'jquery',
|
3894 |
+
'../utils'
|
3895 |
+
], function ($, Utils) {
|
3896 |
+
function Search () { }
|
3897 |
+
|
3898 |
+
Search.prototype.render = function (decorated) {
|
3899 |
+
var $rendered = decorated.call(this);
|
3900 |
+
|
3901 |
+
var $search = $(
|
3902 |
+
'<span class="select2-search select2-search--dropdown">' +
|
3903 |
+
'<input class="select2-search__field" type="search" tabindex="-1"' +
|
3904 |
+
' autocomplete="off" autocorrect="off" autocapitalize="off"' +
|
3905 |
+
' spellcheck="false" role="textbox" />' +
|
3906 |
+
'</span>'
|
3907 |
+
);
|
3908 |
+
|
3909 |
+
this.$searchContainer = $search;
|
3910 |
+
this.$search = $search.find('input');
|
3911 |
+
|
3912 |
+
$rendered.prepend($search);
|
3913 |
+
|
3914 |
+
return $rendered;
|
3915 |
+
};
|
3916 |
+
|
3917 |
+
Search.prototype.bind = function (decorated, container, $container) {
|
3918 |
+
var self = this;
|
3919 |
+
|
3920 |
+
decorated.call(this, container, $container);
|
3921 |
+
|
3922 |
+
this.$search.on('keydown', function (evt) {
|
3923 |
+
self.trigger('keypress', evt);
|
3924 |
+
|
3925 |
+
self._keyUpPrevented = evt.isDefaultPrevented();
|
3926 |
+
});
|
3927 |
+
|
3928 |
+
// Workaround for browsers which do not support the `input` event
|
3929 |
+
// This will prevent double-triggering of events for browsers which support
|
3930 |
+
// both the `keyup` and `input` events.
|
3931 |
+
this.$search.on('input', function (evt) {
|
3932 |
+
// Unbind the duplicated `keyup` event
|
3933 |
+
$(this).off('keyup');
|
3934 |
+
});
|
3935 |
+
|
3936 |
+
this.$search.on('keyup input', function (evt) {
|
3937 |
+
self.handleSearch(evt);
|
3938 |
+
});
|
3939 |
+
|
3940 |
+
container.on('open', function () {
|
3941 |
+
self.$search.attr('tabindex', 0);
|
3942 |
+
|
3943 |
+
self.$search.focus();
|
3944 |
+
|
3945 |
+
window.setTimeout(function () {
|
3946 |
+
self.$search.focus();
|
3947 |
+
}, 0);
|
3948 |
+
});
|
3949 |
+
|
3950 |
+
container.on('close', function () {
|
3951 |
+
self.$search.attr('tabindex', -1);
|
3952 |
+
|
3953 |
+
self.$search.val('');
|
3954 |
+
});
|
3955 |
+
|
3956 |
+
container.on('focus', function () {
|
3957 |
+
if (container.isOpen()) {
|
3958 |
+
self.$search.focus();
|
3959 |
+
}
|
3960 |
+
});
|
3961 |
+
|
3962 |
+
container.on('results:all', function (params) {
|
3963 |
+
if (params.query.term == null || params.query.term === '') {
|
3964 |
+
var showSearch = self.showSearch(params);
|
3965 |
+
|
3966 |
+
if (showSearch) {
|
3967 |
+
self.$searchContainer.removeClass('select2-search--hide');
|
3968 |
+
} else {
|
3969 |
+
self.$searchContainer.addClass('select2-search--hide');
|
3970 |
+
}
|
3971 |
+
}
|
3972 |
+
});
|
3973 |
+
};
|
3974 |
+
|
3975 |
+
Search.prototype.handleSearch = function (evt) {
|
3976 |
+
if (!this._keyUpPrevented) {
|
3977 |
+
var input = this.$search.val();
|
3978 |
+
|
3979 |
+
this.trigger('query', {
|
3980 |
+
term: input
|
3981 |
+
});
|
3982 |
+
}
|
3983 |
+
|
3984 |
+
this._keyUpPrevented = false;
|
3985 |
+
};
|
3986 |
+
|
3987 |
+
Search.prototype.showSearch = function (_, params) {
|
3988 |
+
return true;
|
3989 |
+
};
|
3990 |
+
|
3991 |
+
return Search;
|
3992 |
+
});
|
3993 |
+
|
3994 |
+
S2.define('select2/dropdown/hidePlaceholder',[
|
3995 |
+
|
3996 |
+
], function () {
|
3997 |
+
function HidePlaceholder (decorated, $element, options, dataAdapter) {
|
3998 |
+
this.placeholder = this.normalizePlaceholder(options.get('placeholder'));
|
3999 |
+
|
4000 |
+
decorated.call(this, $element, options, dataAdapter);
|
4001 |
+
}
|
4002 |
+
|
4003 |
+
HidePlaceholder.prototype.append = function (decorated, data) {
|
4004 |
+
data.results = this.removePlaceholder(data.results);
|
4005 |
+
|
4006 |
+
decorated.call(this, data);
|
4007 |
+
};
|
4008 |
+
|
4009 |
+
HidePlaceholder.prototype.normalizePlaceholder = function (_, placeholder) {
|
4010 |
+
if (typeof placeholder === 'string') {
|
4011 |
+
placeholder = {
|
4012 |
+
id: '',
|
4013 |
+
text: placeholder
|
4014 |
+
};
|
4015 |
+
}
|
4016 |
+
|
4017 |
+
return placeholder;
|
4018 |
+
};
|
4019 |
+
|
4020 |
+
HidePlaceholder.prototype.removePlaceholder = function (_, data) {
|
4021 |
+
var modifiedData = data.slice(0);
|
4022 |
+
|
4023 |
+
for (var d = data.length - 1; d >= 0; d--) {
|
4024 |
+
var item = data[d];
|
4025 |
+
|
4026 |
+
if (this.placeholder.id === item.id) {
|
4027 |
+
modifiedData.splice(d, 1);
|
4028 |
+
}
|
4029 |
+
}
|
4030 |
+
|
4031 |
+
return modifiedData;
|
4032 |
+
};
|
4033 |
+
|
4034 |
+
return HidePlaceholder;
|
4035 |
+
});
|
4036 |
+
|
4037 |
+
S2.define('select2/dropdown/infiniteScroll',[
|
4038 |
+
'jquery'
|
4039 |
+
], function ($) {
|
4040 |
+
function InfiniteScroll (decorated, $element, options, dataAdapter) {
|
4041 |
+
this.lastParams = {};
|
4042 |
+
|
4043 |
+
decorated.call(this, $element, options, dataAdapter);
|
4044 |
+
|
4045 |
+
this.$loadingMore = this.createLoadingMore();
|
4046 |
+
this.loading = false;
|
4047 |
+
}
|
4048 |
+
|
4049 |
+
InfiniteScroll.prototype.append = function (decorated, data) {
|
4050 |
+
this.$loadingMore.remove();
|
4051 |
+
this.loading = false;
|
4052 |
+
|
4053 |
+
decorated.call(this, data);
|
4054 |
+
|
4055 |
+
if (this.showLoadingMore(data)) {
|
4056 |
+
this.$results.append(this.$loadingMore);
|
4057 |
+
}
|
4058 |
+
};
|
4059 |
+
|
4060 |
+
InfiniteScroll.prototype.bind = function (decorated, container, $container) {
|
4061 |
+
var self = this;
|
4062 |
+
|
4063 |
+
decorated.call(this, container, $container);
|
4064 |
+
|
4065 |
+
container.on('query', function (params) {
|
4066 |
+
self.lastParams = params;
|
4067 |
+
self.loading = true;
|
4068 |
+
});
|
4069 |
+
|
4070 |
+
container.on('query:append', function (params) {
|
4071 |
+
self.lastParams = params;
|
4072 |
+
self.loading = true;
|
4073 |
+
});
|
4074 |
+
|
4075 |
+
this.$results.on('scroll', function () {
|
4076 |
+
var isLoadMoreVisible = $.contains(
|
4077 |
+
document.documentElement,
|
4078 |
+
self.$loadingMore[0]
|
4079 |
+
);
|
4080 |
+
|
4081 |
+
if (self.loading || !isLoadMoreVisible) {
|
4082 |
+
return;
|
4083 |
+
}
|
4084 |
+
|
4085 |
+
var currentOffset = self.$results.offset().top +
|
4086 |
+
self.$results.outerHeight(false);
|
4087 |
+
var loadingMoreOffset = self.$loadingMore.offset().top +
|
4088 |
+
self.$loadingMore.outerHeight(false);
|
4089 |
+
|
4090 |
+
if (currentOffset + 50 >= loadingMoreOffset) {
|
4091 |
+
self.loadMore();
|
4092 |
+
}
|
4093 |
+
});
|
4094 |
+
};
|
4095 |
+
|
4096 |
+
InfiniteScroll.prototype.loadMore = function () {
|
4097 |
+
this.loading = true;
|
4098 |
+
|
4099 |
+
var params = $.extend({}, {page: 1}, this.lastParams);
|
4100 |
+
|
4101 |
+
params.page++;
|
4102 |
+
|
4103 |
+
this.trigger('query:append', params);
|
4104 |
+
};
|
4105 |
+
|
4106 |
+
InfiniteScroll.prototype.showLoadingMore = function (_, data) {
|
4107 |
+
return data.pagination && data.pagination.more;
|
4108 |
+
};
|
4109 |
+
|
4110 |
+
InfiniteScroll.prototype.createLoadingMore = function () {
|
4111 |
+
var $option = $(
|
4112 |
+
'<li ' +
|
4113 |
+
'class="select2-results__option select2-results__option--load-more"' +
|
4114 |
+
'role="treeitem" aria-disabled="true"></li>'
|
4115 |
+
);
|
4116 |
+
|
4117 |
+
var message = this.options.get('translations').get('loadingMore');
|
4118 |
+
|
4119 |
+
$option.html(message(this.lastParams));
|
4120 |
+
|
4121 |
+
return $option;
|
4122 |
+
};
|
4123 |
+
|
4124 |
+
return InfiniteScroll;
|
4125 |
+
});
|
4126 |
+
|
4127 |
+
S2.define('select2/dropdown/attachBody',[
|
4128 |
+
'jquery',
|
4129 |
+
'../utils'
|
4130 |
+
], function ($, Utils) {
|
4131 |
+
function AttachBody (decorated, $element, options) {
|
4132 |
+
this.$dropdownParent = options.get('dropdownParent') || $(document.body);
|
4133 |
+
|
4134 |
+
decorated.call(this, $element, options);
|
4135 |
+
}
|
4136 |
+
|
4137 |
+
AttachBody.prototype.bind = function (decorated, container, $container) {
|
4138 |
+
var self = this;
|
4139 |
+
|
4140 |
+
var setupResultsEvents = false;
|
4141 |
+
|
4142 |
+
decorated.call(this, container, $container);
|
4143 |
+
|
4144 |
+
container.on('open', function () {
|
4145 |
+
self._showDropdown();
|
4146 |
+
self._attachPositioningHandler(container);
|
4147 |
+
|
4148 |
+
if (!setupResultsEvents) {
|
4149 |
+
setupResultsEvents = true;
|
4150 |
+
|
4151 |
+
container.on('results:all', function () {
|
4152 |
+
self._positionDropdown();
|
4153 |
+
self._resizeDropdown();
|
4154 |
+
});
|
4155 |
+
|
4156 |
+
container.on('results:append', function () {
|
4157 |
+
self._positionDropdown();
|
4158 |
+
self._resizeDropdown();
|
4159 |
+
});
|
4160 |
+
}
|
4161 |
+
});
|
4162 |
+
|
4163 |
+
container.on('close', function () {
|
4164 |
+
self._hideDropdown();
|
4165 |
+
self._detachPositioningHandler(container);
|
4166 |
+
});
|
4167 |
+
|
4168 |
+
this.$dropdownContainer.on('mousedown', function (evt) {
|
4169 |
+
evt.stopPropagation();
|
4170 |
+
});
|
4171 |
+
};
|
4172 |
+
|
4173 |
+
AttachBody.prototype.destroy = function (decorated) {
|
4174 |
+
decorated.call(this);
|
4175 |
+
|
4176 |
+
this.$dropdownContainer.remove();
|
4177 |
+
};
|
4178 |
+
|
4179 |
+
AttachBody.prototype.position = function (decorated, $dropdown, $container) {
|
4180 |
+
// Clone all of the container classes
|
4181 |
+
$dropdown.attr('class', $container.attr('class'));
|
4182 |
+
|
4183 |
+
$dropdown.removeClass('select2');
|
4184 |
+
$dropdown.addClass('select2-container--open');
|
4185 |
+
|
4186 |
+
$dropdown.css({
|
4187 |
+
position: 'absolute',
|
4188 |
+
top: -999999
|
4189 |
+
});
|
4190 |
+
|
4191 |
+
this.$container = $container;
|
4192 |
+
};
|
4193 |
+
|
4194 |
+
AttachBody.prototype.render = function (decorated) {
|
4195 |
+
var $container = $('<span></span>');
|
4196 |
+
|
4197 |
+
var $dropdown = decorated.call(this);
|
4198 |
+
$container.append($dropdown);
|
4199 |
+
|
4200 |
+
this.$dropdownContainer = $container;
|
4201 |
+
|
4202 |
+
return $container;
|
4203 |
+
};
|
4204 |
+
|
4205 |
+
AttachBody.prototype._hideDropdown = function (decorated) {
|
4206 |
+
this.$dropdownContainer.detach();
|
4207 |
+
};
|
4208 |
+
|
4209 |
+
AttachBody.prototype._attachPositioningHandler =
|
4210 |
+
function (decorated, container) {
|
4211 |
+
var self = this;
|
4212 |
+
|
4213 |
+
var scrollEvent = 'scroll.select2.' + container.id;
|
4214 |
+
var resizeEvent = 'resize.select2.' + container.id;
|
4215 |
+
var orientationEvent = 'orientationchange.select2.' + container.id;
|
4216 |
+
|
4217 |
+
var $watchers = this.$container.parents().filter(Utils.hasScroll);
|
4218 |
+
$watchers.each(function () {
|
4219 |
+
$(this).data('select2-scroll-position', {
|
4220 |
+
x: $(this).scrollLeft(),
|
4221 |
+
y: $(this).scrollTop()
|
4222 |
+
});
|
4223 |
+
});
|
4224 |
+
|
4225 |
+
$watchers.on(scrollEvent, function (ev) {
|
4226 |
+
var position = $(this).data('select2-scroll-position');
|
4227 |
+
$(this).scrollTop(position.y);
|
4228 |
+
});
|
4229 |
+
|
4230 |
+
$(window).on(scrollEvent + ' ' + resizeEvent + ' ' + orientationEvent,
|
4231 |
+
function (e) {
|
4232 |
+
self._positionDropdown();
|
4233 |
+
self._resizeDropdown();
|
4234 |
+
});
|
4235 |
+
};
|
4236 |
+
|
4237 |
+
AttachBody.prototype._detachPositioningHandler =
|
4238 |
+
function (decorated, container) {
|
4239 |
+
var scrollEvent = 'scroll.select2.' + container.id;
|
4240 |
+
var resizeEvent = 'resize.select2.' + container.id;
|
4241 |
+
var orientationEvent = 'orientationchange.select2.' + container.id;
|
4242 |
+
|
4243 |
+
var $watchers = this.$container.parents().filter(Utils.hasScroll);
|
4244 |
+
$watchers.off(scrollEvent);
|
4245 |
+
|
4246 |
+
$(window).off(scrollEvent + ' ' + resizeEvent + ' ' + orientationEvent);
|
4247 |
+
};
|
4248 |
+
|
4249 |
+
AttachBody.prototype._positionDropdown = function () {
|
4250 |
+
var $window = $(window);
|
4251 |
+
|
4252 |
+
var isCurrentlyAbove = this.$dropdown.hasClass('select2-dropdown--above');
|
4253 |
+
var isCurrentlyBelow = this.$dropdown.hasClass('select2-dropdown--below');
|
4254 |
+
|
4255 |
+
var newDirection = null;
|
4256 |
+
|
4257 |
+
var offset = this.$container.offset();
|
4258 |
+
|
4259 |
+
offset.bottom = offset.top + this.$container.outerHeight(false);
|
4260 |
+
|
4261 |
+
var container = {
|
4262 |
+
height: this.$container.outerHeight(false)
|
4263 |
+
};
|
4264 |
+
|
4265 |
+
container.top = offset.top;
|
4266 |
+
container.bottom = offset.top + container.height;
|
4267 |
+
|
4268 |
+
var dropdown = {
|
4269 |
+
height: this.$dropdown.outerHeight(false)
|
4270 |
+
};
|
4271 |
+
|
4272 |
+
var viewport = {
|
4273 |
+
top: $window.scrollTop(),
|
4274 |
+
bottom: $window.scrollTop() + $window.height()
|
4275 |
+
};
|
4276 |
+
|
4277 |
+
var enoughRoomAbove = viewport.top < (offset.top - dropdown.height);
|
4278 |
+
var enoughRoomBelow = viewport.bottom > (offset.bottom + dropdown.height);
|
4279 |
+
|
4280 |
+
var css = {
|
4281 |
+
left: offset.left,
|
4282 |
+
top: container.bottom
|
4283 |
+
};
|
4284 |
+
|
4285 |
+
// Determine what the parent element is to use for calciulating the offset
|
4286 |
+
var $offsetParent = this.$dropdownParent;
|
4287 |
+
|
4288 |
+
// For statically positoned elements, we need to get the element
|
4289 |
+
// that is determining the offset
|
4290 |
+
if ($offsetParent.css('position') === 'static') {
|
4291 |
+
$offsetParent = $offsetParent.offsetParent();
|
4292 |
+
}
|
4293 |
+
|
4294 |
+
var parentOffset = $offsetParent.offset();
|
4295 |
+
|
4296 |
+
css.top -= parentOffset.top;
|
4297 |
+
css.left -= parentOffset.left;
|
4298 |
+
|
4299 |
+
if (!isCurrentlyAbove && !isCurrentlyBelow) {
|
4300 |
+
newDirection = 'below';
|
4301 |
+
}
|
4302 |
+
|
4303 |
+
if (!enoughRoomBelow && enoughRoomAbove && !isCurrentlyAbove) {
|
4304 |
+
newDirection = 'above';
|
4305 |
+
} else if (!enoughRoomAbove && enoughRoomBelow && isCurrentlyAbove) {
|
4306 |
+
newDirection = 'below';
|
4307 |
+
}
|
4308 |
+
|
4309 |
+
if (newDirection == 'above' ||
|
4310 |
+
(isCurrentlyAbove && newDirection !== 'below')) {
|
4311 |
+
css.top = container.top - parentOffset.top - dropdown.height;
|
4312 |
+
}
|
4313 |
+
|
4314 |
+
if (newDirection != null) {
|
4315 |
+
this.$dropdown
|
4316 |
+
.removeClass('select2-dropdown--below select2-dropdown--above')
|
4317 |
+
.addClass('select2-dropdown--' + newDirection);
|
4318 |
+
this.$container
|
4319 |
+
.removeClass('select2-container--below select2-container--above')
|
4320 |
+
.addClass('select2-container--' + newDirection);
|
4321 |
+
}
|
4322 |
+
|
4323 |
+
this.$dropdownContainer.css(css);
|
4324 |
+
};
|
4325 |
+
|
4326 |
+
AttachBody.prototype._resizeDropdown = function () {
|
4327 |
+
var css = {
|
4328 |
+
width: this.$container.outerWidth(false) + 'px'
|
4329 |
+
};
|
4330 |
+
|
4331 |
+
if (this.options.get('dropdownAutoWidth')) {
|
4332 |
+
css.minWidth = css.width;
|
4333 |
+
css.position = 'relative';
|
4334 |
+
css.width = 'auto';
|
4335 |
+
}
|
4336 |
+
|
4337 |
+
this.$dropdown.css(css);
|
4338 |
+
};
|
4339 |
+
|
4340 |
+
AttachBody.prototype._showDropdown = function (decorated) {
|
4341 |
+
this.$dropdownContainer.appendTo(this.$dropdownParent);
|
4342 |
+
|
4343 |
+
this._positionDropdown();
|
4344 |
+
this._resizeDropdown();
|
4345 |
+
};
|
4346 |
+
|
4347 |
+
return AttachBody;
|
4348 |
+
});
|
4349 |
+
|
4350 |
+
S2.define('select2/dropdown/minimumResultsForSearch',[
|
4351 |
+
|
4352 |
+
], function () {
|
4353 |
+
function countResults (data) {
|
4354 |
+
var count = 0;
|
4355 |
+
|
4356 |
+
for (var d = 0; d < data.length; d++) {
|
4357 |
+
var item = data[d];
|
4358 |
+
|
4359 |
+
if (item.children) {
|
4360 |
+
count += countResults(item.children);
|
4361 |
+
} else {
|
4362 |
+
count++;
|
4363 |
+
}
|
4364 |
+
}
|
4365 |
+
|
4366 |
+
return count;
|
4367 |
+
}
|
4368 |
+
|
4369 |
+
function MinimumResultsForSearch (decorated, $element, options, dataAdapter) {
|
4370 |
+
this.minimumResultsForSearch = options.get('minimumResultsForSearch');
|
4371 |
+
|
4372 |
+
if (this.minimumResultsForSearch < 0) {
|
4373 |
+
this.minimumResultsForSearch = Infinity;
|
4374 |
+
}
|
4375 |
+
|
4376 |
+
decorated.call(this, $element, options, dataAdapter);
|
4377 |
+
}
|
4378 |
+
|
4379 |
+
MinimumResultsForSearch.prototype.showSearch = function (decorated, params) {
|
4380 |
+
if (countResults(params.data.results) < this.minimumResultsForSearch) {
|
4381 |
+
return false;
|
4382 |
+
}
|
4383 |
+
|
4384 |
+
return decorated.call(this, params);
|
4385 |
+
};
|
4386 |
+
|
4387 |
+
return MinimumResultsForSearch;
|
4388 |
+
});
|
4389 |
+
|
4390 |
+
S2.define('select2/dropdown/selectOnClose',[
|
4391 |
+
|
4392 |
+
], function () {
|
4393 |
+
function SelectOnClose () { }
|
4394 |
+
|
4395 |
+
SelectOnClose.prototype.bind = function (decorated, container, $container) {
|
4396 |
+
var self = this;
|
4397 |
+
|
4398 |
+
decorated.call(this, container, $container);
|
4399 |
+
|
4400 |
+
container.on('close', function (params) {
|
4401 |
+
self._handleSelectOnClose(params);
|
4402 |
+
});
|
4403 |
+
};
|
4404 |
+
|
4405 |
+
SelectOnClose.prototype._handleSelectOnClose = function (_, params) {
|
4406 |
+
if (params && params.originalSelect2Event != null) {
|
4407 |
+
var event = params.originalSelect2Event;
|
4408 |
+
|
4409 |
+
// Don't select an item if the close event was triggered from a select or
|
4410 |
+
// unselect event
|
4411 |
+
if (event._type === 'select' || event._type === 'unselect') {
|
4412 |
+
return;
|
4413 |
+
}
|
4414 |
+
}
|
4415 |
+
|
4416 |
+
var $highlightedResults = this.getHighlightedResults();
|
4417 |
+
|
4418 |
+
// Only select highlighted results
|
4419 |
+
if ($highlightedResults.length < 1) {
|
4420 |
+
return;
|
4421 |
+
}
|
4422 |
+
|
4423 |
+
var data = $highlightedResults.data('data');
|
4424 |
+
|
4425 |
+
// Don't re-select already selected resulte
|
4426 |
+
if (
|
4427 |
+
(data.element != null && data.element.selected) ||
|
4428 |
+
(data.element == null && data.selected)
|
4429 |
+
) {
|
4430 |
+
return;
|
4431 |
+
}
|
4432 |
+
|
4433 |
+
this.trigger('select', {
|
4434 |
+
data: data
|
4435 |
+
});
|
4436 |
+
};
|
4437 |
+
|
4438 |
+
return SelectOnClose;
|
4439 |
+
});
|
4440 |
+
|
4441 |
+
S2.define('select2/dropdown/closeOnSelect',[
|
4442 |
+
|
4443 |
+
], function () {
|
4444 |
+
function CloseOnSelect () { }
|
4445 |
+
|
4446 |
+
CloseOnSelect.prototype.bind = function (decorated, container, $container) {
|
4447 |
+
var self = this;
|
4448 |
+
|
4449 |
+
decorated.call(this, container, $container);
|
4450 |
+
|
4451 |
+
container.on('select', function (evt) {
|
4452 |
+
self._selectTriggered(evt);
|
4453 |
+
});
|
4454 |
+
|
4455 |
+
container.on('unselect', function (evt) {
|
4456 |
+
self._selectTriggered(evt);
|
4457 |
+
});
|
4458 |
+
};
|
4459 |
+
|
4460 |
+
CloseOnSelect.prototype._selectTriggered = function (_, evt) {
|
4461 |
+
var originalEvent = evt.originalEvent;
|
4462 |
+
|
4463 |
+
// Don't close if the control key is being held
|
4464 |
+
if (originalEvent && originalEvent.ctrlKey) {
|
4465 |
+
return;
|
4466 |
+
}
|
4467 |
+
|
4468 |
+
this.trigger('close', {
|
4469 |
+
originalEvent: originalEvent,
|
4470 |
+
originalSelect2Event: evt
|
4471 |
+
});
|
4472 |
+
};
|
4473 |
+
|
4474 |
+
return CloseOnSelect;
|
4475 |
+
});
|
4476 |
+
|
4477 |
+
S2.define('select2/i18n/en',[],function () {
|
4478 |
+
// English
|
4479 |
+
return {
|
4480 |
+
errorLoading: function () {
|
4481 |
+
return 'The results could not be loaded.';
|
4482 |
+
},
|
4483 |
+
inputTooLong: function (args) {
|
4484 |
+
var overChars = args.input.length - args.maximum;
|
4485 |
+
|
4486 |
+
var message = 'Please delete ' + overChars + ' character';
|
4487 |
+
|
4488 |
+
if (overChars != 1) {
|
4489 |
+
message += 's';
|
4490 |
+
}
|
4491 |
+
|
4492 |
+
return message;
|
4493 |
+
},
|
4494 |
+
inputTooShort: function (args) {
|
4495 |
+
var remainingChars = args.minimum - args.input.length;
|
4496 |
+
|
4497 |
+
var message = 'Please enter ' + remainingChars + ' or more characters';
|
4498 |
+
|
4499 |
+
return message;
|
4500 |
+
},
|
4501 |
+
loadingMore: function () {
|
4502 |
+
return 'Loading more results…';
|
4503 |
+
},
|
4504 |
+
maximumSelected: function (args) {
|
4505 |
+
var message = 'You can only select ' + args.maximum + ' item';
|
4506 |
+
|
4507 |
+
if (args.maximum != 1) {
|
4508 |
+
message += 's';
|
4509 |
+
}
|
4510 |
+
|
4511 |
+
return message;
|
4512 |
+
},
|
4513 |
+
noResults: function () {
|
4514 |
+
return 'No results found';
|
4515 |
+
},
|
4516 |
+
searching: function () {
|
4517 |
+
return 'Searching…';
|
4518 |
+
}
|
4519 |
+
};
|
4520 |
+
});
|
4521 |
+
|
4522 |
+
S2.define('select2/defaults',[
|
4523 |
+
'jquery',
|
4524 |
+
'require',
|
4525 |
+
|
4526 |
+
'./results',
|
4527 |
+
|
4528 |
+
'./selection/single',
|
4529 |
+
'./selection/multiple',
|
4530 |
+
'./selection/placeholder',
|
4531 |
+
'./selection/allowClear',
|
4532 |
+
'./selection/search',
|
4533 |
+
'./selection/eventRelay',
|
4534 |
+
|
4535 |
+
'./utils',
|
4536 |
+
'./translation',
|
4537 |
+
'./diacritics',
|
4538 |
+
|
4539 |
+
'./data/select',
|
4540 |
+
'./data/array',
|
4541 |
+
'./data/ajax',
|
4542 |
+
'./data/tags',
|
4543 |
+
'./data/tokenizer',
|
4544 |
+
'./data/minimumInputLength',
|
4545 |
+
'./data/maximumInputLength',
|
4546 |
+
'./data/maximumSelectionLength',
|
4547 |
+
|
4548 |
+
'./dropdown',
|
4549 |
+
'./dropdown/search',
|
4550 |
+
'./dropdown/hidePlaceholder',
|
4551 |
+
'./dropdown/infiniteScroll',
|
4552 |
+
'./dropdown/attachBody',
|
4553 |
+
'./dropdown/minimumResultsForSearch',
|
4554 |
+
'./dropdown/selectOnClose',
|
4555 |
+
'./dropdown/closeOnSelect',
|
4556 |
+
|
4557 |
+
'./i18n/en'
|
4558 |
+
], function ($, require,
|
4559 |
+
|
4560 |
+
ResultsList,
|
4561 |
+
|
4562 |
+
SingleSelection, MultipleSelection, Placeholder, AllowClear,
|
4563 |
+
SelectionSearch, EventRelay,
|
4564 |
+
|
4565 |
+
Utils, Translation, DIACRITICS,
|
4566 |
+
|
4567 |
+
SelectData, ArrayData, AjaxData, Tags, Tokenizer,
|
4568 |
+
MinimumInputLength, MaximumInputLength, MaximumSelectionLength,
|
4569 |
+
|
4570 |
+
Dropdown, DropdownSearch, HidePlaceholder, InfiniteScroll,
|
4571 |
+
AttachBody, MinimumResultsForSearch, SelectOnClose, CloseOnSelect,
|
4572 |
+
|
4573 |
+
EnglishTranslation) {
|
4574 |
+
function Defaults () {
|
4575 |
+
this.reset();
|
4576 |
+
}
|
4577 |
+
|
4578 |
+
Defaults.prototype.apply = function (options) {
|
4579 |
+
options = $.extend(true, {}, this.defaults, options);
|
4580 |
+
|
4581 |
+
if (options.dataAdapter == null) {
|
4582 |
+
if (options.ajax != null) {
|
4583 |
+
options.dataAdapter = AjaxData;
|
4584 |
+
} else if (options.data != null) {
|
4585 |
+
options.dataAdapter = ArrayData;
|
4586 |
+
} else {
|
4587 |
+
options.dataAdapter = SelectData;
|
4588 |
+
}
|
4589 |
+
|
4590 |
+
if (options.minimumInputLength > 0) {
|
4591 |
+
options.dataAdapter = Utils.Decorate(
|
4592 |
+
options.dataAdapter,
|
4593 |
+
MinimumInputLength
|
4594 |
+
);
|
4595 |
+
}
|
4596 |
+
|
4597 |
+
if (options.maximumInputLength > 0) {
|
4598 |
+
options.dataAdapter = Utils.Decorate(
|
4599 |
+
options.dataAdapter,
|
4600 |
+
MaximumInputLength
|
4601 |
+
);
|
4602 |
+
}
|
4603 |
+
|
4604 |
+
if (options.maximumSelectionLength > 0) {
|
4605 |
+
options.dataAdapter = Utils.Decorate(
|
4606 |
+
options.dataAdapter,
|
4607 |
+
MaximumSelectionLength
|
4608 |
+
);
|
4609 |
+
}
|
4610 |
+
|
4611 |
+
if (options.tags) {
|
4612 |
+
options.dataAdapter = Utils.Decorate(options.dataAdapter, Tags);
|
4613 |
+
}
|
4614 |
+
|
4615 |
+
if (options.tokenSeparators != null || options.tokenizer != null) {
|
4616 |
+
options.dataAdapter = Utils.Decorate(
|
4617 |
+
options.dataAdapter,
|
4618 |
+
Tokenizer
|
4619 |
+
);
|
4620 |
+
}
|
4621 |
+
|
4622 |
+
if (options.query != null) {
|
4623 |
+
var Query = require(options.amdBase + 'compat/query');
|
4624 |
+
|
4625 |
+
options.dataAdapter = Utils.Decorate(
|
4626 |
+
options.dataAdapter,
|
4627 |
+
Query
|
4628 |
+
);
|
4629 |
+
}
|
4630 |
+
|
4631 |
+
if (options.initSelection != null) {
|
4632 |
+
var InitSelection = require(options.amdBase + 'compat/initSelection');
|
4633 |
+
|
4634 |
+
options.dataAdapter = Utils.Decorate(
|
4635 |
+
options.dataAdapter,
|
4636 |
+
InitSelection
|
4637 |
+
);
|
4638 |
+
}
|
4639 |
+
}
|
4640 |
+
|
4641 |
+
if (options.resultsAdapter == null) {
|
4642 |
+
options.resultsAdapter = ResultsList;
|
4643 |
+
|
4644 |
+
if (options.ajax != null) {
|
4645 |
+
options.resultsAdapter = Utils.Decorate(
|
4646 |
+
options.resultsAdapter,
|
4647 |
+
InfiniteScroll
|
4648 |
+
);
|
4649 |
+
}
|
4650 |
+
|
4651 |
+
if (options.placeholder != null) {
|
4652 |
+
options.resultsAdapter = Utils.Decorate(
|
4653 |
+
options.resultsAdapter,
|
4654 |
+
HidePlaceholder
|
4655 |
+
);
|
4656 |
+
}
|
4657 |
+
|
4658 |
+
if (options.selectOnClose) {
|
4659 |
+
options.resultsAdapter = Utils.Decorate(
|
4660 |
+
options.resultsAdapter,
|
4661 |
+
SelectOnClose
|
4662 |
+
);
|
4663 |
+
}
|
4664 |
+
}
|
4665 |
+
|
4666 |
+
if (options.dropdownAdapter == null) {
|
4667 |
+
if (options.multiple) {
|
4668 |
+
options.dropdownAdapter = Dropdown;
|
4669 |
+
} else {
|
4670 |
+
var SearchableDropdown = Utils.Decorate(Dropdown, DropdownSearch);
|
4671 |
+
|
4672 |
+
options.dropdownAdapter = SearchableDropdown;
|
4673 |
+
}
|
4674 |
+
|
4675 |
+
if (options.minimumResultsForSearch !== 0) {
|
4676 |
+
options.dropdownAdapter = Utils.Decorate(
|
4677 |
+
options.dropdownAdapter,
|
4678 |
+
MinimumResultsForSearch
|
4679 |
+
);
|
4680 |
+
}
|
4681 |
+
|
4682 |
+
if (options.closeOnSelect) {
|
4683 |
+
options.dropdownAdapter = Utils.Decorate(
|
4684 |
+
options.dropdownAdapter,
|
4685 |
+
CloseOnSelect
|
4686 |
+
);
|
4687 |
+
}
|
4688 |
+
|
4689 |
+
if (
|
4690 |
+
options.dropdownCssClass != null ||
|
4691 |
+
options.dropdownCss != null ||
|
4692 |
+
options.adaptDropdownCssClass != null
|
4693 |
+
) {
|
4694 |
+
var DropdownCSS = require(options.amdBase + 'compat/dropdownCss');
|
4695 |
+
|
4696 |
+
options.dropdownAdapter = Utils.Decorate(
|
4697 |
+
options.dropdownAdapter,
|
4698 |
+
DropdownCSS
|
4699 |
+
);
|
4700 |
+
}
|
4701 |
+
|
4702 |
+
options.dropdownAdapter = Utils.Decorate(
|
4703 |
+
options.dropdownAdapter,
|
4704 |
+
AttachBody
|
4705 |
+
);
|
4706 |
+
}
|
4707 |
+
|
4708 |
+
if (options.selectionAdapter == null) {
|
4709 |
+
if (options.multiple) {
|
4710 |
+
options.selectionAdapter = MultipleSelection;
|
4711 |
+
} else {
|
4712 |
+
options.selectionAdapter = SingleSelection;
|
4713 |
+
}
|
4714 |
+
|
4715 |
+
// Add the placeholder mixin if a placeholder was specified
|
4716 |
+
if (options.placeholder != null) {
|
4717 |
+
options.selectionAdapter = Utils.Decorate(
|
4718 |
+
options.selectionAdapter,
|
4719 |
+
Placeholder
|
4720 |
+
);
|
4721 |
+
}
|
4722 |
+
|
4723 |
+
if (options.allowClear) {
|
4724 |
+
options.selectionAdapter = Utils.Decorate(
|
4725 |
+
options.selectionAdapter,
|
4726 |
+
AllowClear
|
4727 |
+
);
|
4728 |
+
}
|
4729 |
+
|
4730 |
+
if (options.multiple) {
|
4731 |
+
options.selectionAdapter = Utils.Decorate(
|
4732 |
+
options.selectionAdapter,
|
4733 |
+
SelectionSearch
|
4734 |
+
);
|
4735 |
+
}
|
4736 |
+
|
4737 |
+
if (
|
4738 |
+
options.containerCssClass != null ||
|
4739 |
+
options.containerCss != null ||
|
4740 |
+
options.adaptContainerCssClass != null
|
4741 |
+
) {
|
4742 |
+
var ContainerCSS = require(options.amdBase + 'compat/containerCss');
|
4743 |
+
|
4744 |
+
options.selectionAdapter = Utils.Decorate(
|
4745 |
+
options.selectionAdapter,
|
4746 |
+
ContainerCSS
|
4747 |
+
);
|
4748 |
+
}
|
4749 |
+
|
4750 |
+
options.selectionAdapter = Utils.Decorate(
|
4751 |
+
options.selectionAdapter,
|
4752 |
+
EventRelay
|
4753 |
+
);
|
4754 |
+
}
|
4755 |
+
|
4756 |
+
if (typeof options.language === 'string') {
|
4757 |
+
// Check if the language is specified with a region
|
4758 |
+
if (options.language.indexOf('-') > 0) {
|
4759 |
+
// Extract the region information if it is included
|
4760 |
+
var languageParts = options.language.split('-');
|
4761 |
+
var baseLanguage = languageParts[0];
|
4762 |
+
|
4763 |
+
options.language = [options.language, baseLanguage];
|
4764 |
+
} else {
|
4765 |
+
options.language = [options.language];
|
4766 |
+
}
|
4767 |
+
}
|
4768 |
+
|
4769 |
+
if ($.isArray(options.language)) {
|
4770 |
+
var languages = new Translation();
|
4771 |
+
options.language.push('en');
|
4772 |
+
|
4773 |
+
var languageNames = options.language;
|
4774 |
+
|
4775 |
+
for (var l = 0; l < languageNames.length; l++) {
|
4776 |
+
var name = languageNames[l];
|
4777 |
+
var language = {};
|
4778 |
+
|
4779 |
+
try {
|
4780 |
+
// Try to load it with the original name
|
4781 |
+
language = Translation.loadPath(name);
|
4782 |
+
} catch (e) {
|
4783 |
+
try {
|
4784 |
+
// If we couldn't load it, check if it wasn't the full path
|
4785 |
+
name = this.defaults.amdLanguageBase + name;
|
4786 |
+
language = Translation.loadPath(name);
|
4787 |
+
} catch (ex) {
|
4788 |
+
// The translation could not be loaded at all. Sometimes this is
|
4789 |
+
// because of a configuration problem, other times this can be
|
4790 |
+
// because of how Select2 helps load all possible translation files.
|
4791 |
+
if (options.debug && window.console && console.warn) {
|
4792 |
+
console.warn(
|
4793 |
+
'Select2: The language file for "' + name + '" could not be ' +
|
4794 |
+
'automatically loaded. A fallback will be used instead.'
|
4795 |
+
);
|
4796 |
+
}
|
4797 |
+
|
4798 |
+
continue;
|
4799 |
+
}
|
4800 |
+
}
|
4801 |
+
|
4802 |
+
languages.extend(language);
|
4803 |
+
}
|
4804 |
+
|
4805 |
+
options.translations = languages;
|
4806 |
+
} else {
|
4807 |
+
var baseTranslation = Translation.loadPath(
|
4808 |
+
this.defaults.amdLanguageBase + 'en'
|
4809 |
+
);
|
4810 |
+
var customTranslation = new Translation(options.language);
|
4811 |
+
|
4812 |
+
customTranslation.extend(baseTranslation);
|
4813 |
+
|
4814 |
+
options.translations = customTranslation;
|
4815 |
+
}
|
4816 |
+
|
4817 |
+
return options;
|
4818 |
+
};
|
4819 |
+
|
4820 |
+
Defaults.prototype.reset = function () {
|
4821 |
+
function stripDiacritics (text) {
|
4822 |
+
// Used 'uni range + named function' from http://jsperf.com/diacritics/18
|
4823 |
+
function match(a) {
|
4824 |
+
return DIACRITICS[a] || a;
|
4825 |
+
}
|
4826 |
+
|
4827 |
+
return text.replace(/[^\u0000-\u007E]/g, match);
|
4828 |
+
}
|
4829 |
+
|
4830 |
+
function matcher (params, data) {
|
4831 |
+
// Always return the object if there is nothing to compare
|
4832 |
+
if ($.trim(params.term) === '') {
|
4833 |
+
return data;
|
4834 |
+
}
|
4835 |
+
|
4836 |
+
// Do a recursive check for options with children
|
4837 |
+
if (data.children && data.children.length > 0) {
|
4838 |
+
// Clone the data object if there are children
|
4839 |
+
// This is required as we modify the object to remove any non-matches
|
4840 |
+
var match = $.extend(true, {}, data);
|
4841 |
+
|
4842 |
+
// Check each child of the option
|
4843 |
+
for (var c = data.children.length - 1; c >= 0; c--) {
|
4844 |
+
var child = data.children[c];
|
4845 |
+
|
4846 |
+
var matches = matcher(params, child);
|
4847 |
+
|
4848 |
+
// If there wasn't a match, remove the object in the array
|
4849 |
+
if (matches == null) {
|
4850 |
+
match.children.splice(c, 1);
|
4851 |
+
}
|
4852 |
+
}
|
4853 |
+
|
4854 |
+
// If any children matched, return the new object
|
4855 |
+
if (match.children.length > 0) {
|
4856 |
+
return match;
|
4857 |
+
}
|
4858 |
+
|
4859 |
+
// If there were no matching children, check just the plain object
|
4860 |
+
return matcher(params, match);
|
4861 |
+
}
|
4862 |
+
|
4863 |
+
var original = stripDiacritics(data.text).toUpperCase();
|
4864 |
+
var term = stripDiacritics(params.term).toUpperCase();
|
4865 |
+
|
4866 |
+
// Check if the text contains the term
|
4867 |
+
if (original.indexOf(term) > -1) {
|
4868 |
+
return data;
|
4869 |
+
}
|
4870 |
+
|
4871 |
+
// If it doesn't contain the term, don't return anything
|
4872 |
+
return null;
|
4873 |
+
}
|
4874 |
+
|
4875 |
+
this.defaults = {
|
4876 |
+
amdBase: './',
|
4877 |
+
amdLanguageBase: './i18n/',
|
4878 |
+
closeOnSelect: true,
|
4879 |
+
debug: false,
|
4880 |
+
dropdownAutoWidth: false,
|
4881 |
+
escapeMarkup: Utils.escapeMarkup,
|
4882 |
+
language: EnglishTranslation,
|
4883 |
+
matcher: matcher,
|
4884 |
+
minimumInputLength: 0,
|
4885 |
+
maximumInputLength: 0,
|
4886 |
+
maximumSelectionLength: 0,
|
4887 |
+
minimumResultsForSearch: 0,
|
4888 |
+
selectOnClose: false,
|
4889 |
+
sorter: function (data) {
|
4890 |
+
return data;
|
4891 |
+
},
|
4892 |
+
templateResult: function (result) {
|
4893 |
+
return result.text;
|
4894 |
+
},
|
4895 |
+
templateSelection: function (selection) {
|
4896 |
+
return selection.text;
|
4897 |
+
},
|
4898 |
+
theme: 'default',
|
4899 |
+
width: 'resolve'
|
4900 |
+
};
|
4901 |
+
};
|
4902 |
+
|
4903 |
+
Defaults.prototype.set = function (key, value) {
|
4904 |
+
var camelKey = $.camelCase(key);
|
4905 |
+
|
4906 |
+
var data = {};
|
4907 |
+
data[camelKey] = value;
|
4908 |
+
|
4909 |
+
var convertedData = Utils._convertData(data);
|
4910 |
+
|
4911 |
+
$.extend(this.defaults, convertedData);
|
4912 |
+
};
|
4913 |
+
|
4914 |
+
var defaults = new Defaults();
|
4915 |
+
|
4916 |
+
return defaults;
|
4917 |
+
});
|
4918 |
+
|
4919 |
+
S2.define('select2/options',[
|
4920 |
+
'require',
|
4921 |
+
'jquery',
|
4922 |
+
'./defaults',
|
4923 |
+
'./utils'
|
4924 |
+
], function (require, $, Defaults, Utils) {
|
4925 |
+
function Options (options, $element) {
|
4926 |
+
this.options = options;
|
4927 |
+
|
4928 |
+
if ($element != null) {
|
4929 |
+
this.fromElement($element);
|
4930 |
+
}
|
4931 |
+
|
4932 |
+
this.options = Defaults.apply(this.options);
|
4933 |
+
|
4934 |
+
if ($element && $element.is('input')) {
|
4935 |
+
var InputCompat = require(this.get('amdBase') + 'compat/inputData');
|
4936 |
+
|
4937 |
+
this.options.dataAdapter = Utils.Decorate(
|
4938 |
+
this.options.dataAdapter,
|
4939 |
+
InputCompat
|
4940 |
+
);
|
4941 |
+
}
|
4942 |
+
}
|
4943 |
+
|
4944 |
+
Options.prototype.fromElement = function ($e) {
|
4945 |
+
var excludedData = ['select2'];
|
4946 |
+
|
4947 |
+
if (this.options.multiple == null) {
|
4948 |
+
this.options.multiple = $e.prop('multiple');
|
4949 |
+
}
|
4950 |
+
|
4951 |
+
if (this.options.disabled == null) {
|
4952 |
+
this.options.disabled = $e.prop('disabled');
|
4953 |
+
}
|
4954 |
+
|
4955 |
+
if (this.options.language == null) {
|
4956 |
+
if ($e.prop('lang')) {
|
4957 |
+
this.options.language = $e.prop('lang').toLowerCase();
|
4958 |
+
} else if ($e.closest('[lang]').prop('lang')) {
|
4959 |
+
this.options.language = $e.closest('[lang]').prop('lang');
|
4960 |
+
}
|
4961 |
+
}
|
4962 |
+
|
4963 |
+
if (this.options.dir == null) {
|
4964 |
+
if ($e.prop('dir')) {
|
4965 |
+
this.options.dir = $e.prop('dir');
|
4966 |
+
} else if ($e.closest('[dir]').prop('dir')) {
|
4967 |
+
this.options.dir = $e.closest('[dir]').prop('dir');
|
4968 |
+
} else {
|
4969 |
+
this.options.dir = 'ltr';
|
4970 |
+
}
|
4971 |
+
}
|
4972 |
+
|
4973 |
+
$e.prop('disabled', this.options.disabled);
|
4974 |
+
$e.prop('multiple', this.options.multiple);
|
4975 |
+
|
4976 |
+
if ($e.data('select2Tags')) {
|
4977 |
+
if (this.options.debug && window.console && console.warn) {
|
4978 |
+
console.warn(
|
4979 |
+
'Select2: The `data-select2-tags` attribute has been changed to ' +
|
4980 |
+
'use the `data-data` and `data-tags="true"` attributes and will be ' +
|
4981 |
+
'removed in future versions of Select2.'
|
4982 |
+
);
|
4983 |
+
}
|
4984 |
+
|
4985 |
+
$e.data('data', $e.data('select2Tags'));
|
4986 |
+
$e.data('tags', true);
|
4987 |
+
}
|
4988 |
+
|
4989 |
+
if ($e.data('ajaxUrl')) {
|
4990 |
+
if (this.options.debug && window.console && console.warn) {
|
4991 |
+
console.warn(
|
4992 |
+
'Select2: The `data-ajax-url` attribute has been changed to ' +
|
4993 |
+
'`data-ajax--url` and support for the old attribute will be removed' +
|
4994 |
+
' in future versions of Select2.'
|
4995 |
+
);
|
4996 |
+
}
|
4997 |
+
|
4998 |
+
$e.attr('ajax--url', $e.data('ajaxUrl'));
|
4999 |
+
$e.data('ajax--url', $e.data('ajaxUrl'));
|
5000 |
+
}
|
5001 |
+
|
5002 |
+
var dataset = {};
|
5003 |
+
|
5004 |
+
// Prefer the element's `dataset` attribute if it exists
|
5005 |
+
// jQuery 1.x does not correctly handle data attributes with multiple dashes
|
5006 |
+
if ($.fn.jquery && $.fn.jquery.substr(0, 2) == '1.' && $e[0].dataset) {
|
5007 |
+
dataset = $.extend(true, {}, $e[0].dataset, $e.data());
|
5008 |
+
} else {
|
5009 |
+
dataset = $e.data();
|
5010 |
+
}
|
5011 |
+
|
5012 |
+
var data = $.extend(true, {}, dataset);
|
5013 |
+
|
5014 |
+
data = Utils._convertData(data);
|
5015 |
+
|
5016 |
+
for (var key in data) {
|
5017 |
+
if ($.inArray(key, excludedData) > -1) {
|
5018 |
+
continue;
|
5019 |
+
}
|
5020 |
+
|
5021 |
+
if ($.isPlainObject(this.options[key])) {
|
5022 |
+
$.extend(this.options[key], data[key]);
|
5023 |
+
} else {
|
5024 |
+
this.options[key] = data[key];
|
5025 |
+
}
|
5026 |
+
}
|
5027 |
+
|
5028 |
+
return this;
|
5029 |
+
};
|
5030 |
+
|
5031 |
+
Options.prototype.get = function (key) {
|
5032 |
+
return this.options[key];
|
5033 |
+
};
|
5034 |
+
|
5035 |
+
Options.prototype.set = function (key, val) {
|
5036 |
+
this.options[key] = val;
|
5037 |
+
};
|
5038 |
+
|
5039 |
+
return Options;
|
5040 |
+
});
|
5041 |
+
|
5042 |
+
S2.define('select2/core',[
|
5043 |
+
'jquery',
|
5044 |
+
'./options',
|
5045 |
+
'./utils',
|
5046 |
+
'./keys'
|
5047 |
+
], function ($, Options, Utils, KEYS) {
|
5048 |
+
var Select2 = function ($element, options) {
|
5049 |
+
if ($element.data('select2') != null) {
|
5050 |
+
$element.data('select2').destroy();
|
5051 |
+
}
|
5052 |
+
|
5053 |
+
this.$element = $element;
|
5054 |
+
|
5055 |
+
this.id = this._generateId($element);
|
5056 |
+
|
5057 |
+
options = options || {};
|
5058 |
+
|
5059 |
+
this.options = new Options(options, $element);
|
5060 |
+
|
5061 |
+
Select2.__super__.constructor.call(this);
|
5062 |
+
|
5063 |
+
// Set up the tabindex
|
5064 |
+
|
5065 |
+
var tabindex = $element.attr('tabindex') || 0;
|
5066 |
+
$element.data('old-tabindex', tabindex);
|
5067 |
+
$element.attr('tabindex', '-1');
|
5068 |
+
|
5069 |
+
// Set up containers and adapters
|
5070 |
+
|
5071 |
+
var DataAdapter = this.options.get('dataAdapter');
|
5072 |
+
this.dataAdapter = new DataAdapter($element, this.options);
|
5073 |
+
|
5074 |
+
var $container = this.render();
|
5075 |
+
|
5076 |
+
this._placeContainer($container);
|
5077 |
+
|
5078 |
+
var SelectionAdapter = this.options.get('selectionAdapter');
|
5079 |
+
this.selection = new SelectionAdapter($element, this.options);
|
5080 |
+
this.$selection = this.selection.render();
|
5081 |
+
|
5082 |
+
this.selection.position(this.$selection, $container);
|
5083 |
+
|
5084 |
+
var DropdownAdapter = this.options.get('dropdownAdapter');
|
5085 |
+
this.dropdown = new DropdownAdapter($element, this.options);
|
5086 |
+
this.$dropdown = this.dropdown.render();
|
5087 |
+
|
5088 |
+
this.dropdown.position(this.$dropdown, $container);
|
5089 |
+
|
5090 |
+
var ResultsAdapter = this.options.get('resultsAdapter');
|
5091 |
+
this.results = new ResultsAdapter($element, this.options, this.dataAdapter);
|
5092 |
+
this.$results = this.results.render();
|
5093 |
+
|
5094 |
+
this.results.position(this.$results, this.$dropdown);
|
5095 |
+
|
5096 |
+
// Bind events
|
5097 |
+
|
5098 |
+
var self = this;
|
5099 |
+
|
5100 |
+
// Bind the container to all of the adapters
|
5101 |
+
this._bindAdapters();
|
5102 |
+
|
5103 |
+
// Register any DOM event handlers
|
5104 |
+
this._registerDomEvents();
|
5105 |
+
|
5106 |
+
// Register any internal event handlers
|
5107 |
+
this._registerDataEvents();
|
5108 |
+
this._registerSelectionEvents();
|
5109 |
+
this._registerDropdownEvents();
|
5110 |
+
this._registerResultsEvents();
|
5111 |
+
this._registerEvents();
|
5112 |
+
|
5113 |
+
// Set the initial state
|
5114 |
+
this.dataAdapter.current(function (initialData) {
|
5115 |
+
self.trigger('selection:update', {
|
5116 |
+
data: initialData
|
5117 |
+
});
|
5118 |
+
});
|
5119 |
+
|
5120 |
+
// Hide the original select
|
5121 |
+
$element.addClass('select2-hidden-accessible');
|
5122 |
+
$element.attr('aria-hidden', 'true');
|
5123 |
+
|
5124 |
+
// Synchronize any monitored attributes
|
5125 |
+
this._syncAttributes();
|
5126 |
+
|
5127 |
+
$element.data('select2', this);
|
5128 |
+
};
|
5129 |
+
|
5130 |
+
Utils.Extend(Select2, Utils.Observable);
|
5131 |
+
|
5132 |
+
Select2.prototype._generateId = function ($element) {
|
5133 |
+
var id = '';
|
5134 |
+
|
5135 |
+
if ($element.attr('id') != null) {
|
5136 |
+
id = $element.attr('id');
|
5137 |
+
} else if ($element.attr('name') != null) {
|
5138 |
+
id = $element.attr('name') + '-' + Utils.generateChars(2);
|
5139 |
+
} else {
|
5140 |
+
id = Utils.generateChars(4);
|
5141 |
+
}
|
5142 |
+
|
5143 |
+
id = id.replace(/(:|\.|\[|\]|,)/g, '');
|
5144 |
+
id = 'select2-' + id;
|
5145 |
+
|
5146 |
+
return id;
|
5147 |
+
};
|
5148 |
+
|
5149 |
+
Select2.prototype._placeContainer = function ($container) {
|
5150 |
+
$container.insertAfter(this.$element);
|
5151 |
+
|
5152 |
+
var width = this._resolveWidth(this.$element, this.options.get('width'));
|
5153 |
+
|
5154 |
+
if (width != null) {
|
5155 |
+
$container.css('width', width);
|
5156 |
+
}
|
5157 |
+
};
|
5158 |
+
|
5159 |
+
Select2.prototype._resolveWidth = function ($element, method) {
|
5160 |
+
var WIDTH = /^width:(([-+]?([0-9]*\.)?[0-9]+)(px|em|ex|%|in|cm|mm|pt|pc))/i;
|
5161 |
+
|
5162 |
+
if (method == 'resolve') {
|
5163 |
+
var styleWidth = this._resolveWidth($element, 'style');
|
5164 |
+
|
5165 |
+
if (styleWidth != null) {
|
5166 |
+
return styleWidth;
|
5167 |
+
}
|
5168 |
+
|
5169 |
+
return this._resolveWidth($element, 'element');
|
5170 |
+
}
|
5171 |
+
|
5172 |
+
if (method == 'element') {
|
5173 |
+
var elementWidth = $element.outerWidth(false);
|
5174 |
+
|
5175 |
+
if (elementWidth <= 0) {
|
5176 |
+
return 'auto';
|
5177 |
+
}
|
5178 |
+
|
5179 |
+
return elementWidth + 'px';
|
5180 |
+
}
|
5181 |
+
|
5182 |
+
if (method == 'style') {
|
5183 |
+
var style = $element.attr('style');
|
5184 |
+
|
5185 |
+
if (typeof(style) !== 'string') {
|
5186 |
+
return null;
|
5187 |
+
}
|
5188 |
+
|
5189 |
+
var attrs = style.split(';');
|
5190 |
+
|
5191 |
+
for (var i = 0, l = attrs.length; i < l; i = i + 1) {
|
5192 |
+
var attr = attrs[i].replace(/\s/g, '');
|
5193 |
+
var matches = attr.match(WIDTH);
|
5194 |
+
|
5195 |
+
if (matches !== null && matches.length >= 1) {
|
5196 |
+
return matches[1];
|
5197 |
+
}
|
5198 |
+
}
|
5199 |
+
|
5200 |
+
return null;
|
5201 |
+
}
|
5202 |
+
|
5203 |
+
return method;
|
5204 |
+
};
|
5205 |
+
|
5206 |
+
Select2.prototype._bindAdapters = function () {
|
5207 |
+
this.dataAdapter.bind(this, this.$container);
|
5208 |
+
this.selection.bind(this, this.$container);
|
5209 |
+
|
5210 |
+
this.dropdown.bind(this, this.$container);
|
5211 |
+
this.results.bind(this, this.$container);
|
5212 |
+
};
|
5213 |
+
|
5214 |
+
Select2.prototype._registerDomEvents = function () {
|
5215 |
+
var self = this;
|
5216 |
+
|
5217 |
+
this.$element.on('change.select2', function () {
|
5218 |
+
self.dataAdapter.current(function (data) {
|
5219 |
+
self.trigger('selection:update', {
|
5220 |
+
data: data
|
5221 |
+
});
|
5222 |
+
});
|
5223 |
+
});
|
5224 |
+
|
5225 |
+
this.$element.on('focus.select2', function (evt) {
|
5226 |
+
self.trigger('focus', evt);
|
5227 |
+
});
|
5228 |
+
|
5229 |
+
this._syncA = Utils.bind(this._syncAttributes, this);
|
5230 |
+
this._syncS = Utils.bind(this._syncSubtree, this);
|
5231 |
+
|
5232 |
+
if (this.$element[0].attachEvent) {
|
5233 |
+
this.$element[0].attachEvent('onpropertychange', this._syncA);
|
5234 |
+
}
|
5235 |
+
|
5236 |
+
var observer = window.MutationObserver ||
|
5237 |
+
window.WebKitMutationObserver ||
|
5238 |
+
window.MozMutationObserver
|
5239 |
+
;
|
5240 |
+
|
5241 |
+
if (observer != null) {
|
5242 |
+
this._observer = new observer(function (mutations) {
|
5243 |
+
$.each(mutations, self._syncA);
|
5244 |
+
$.each(mutations, self._syncS);
|
5245 |
+
});
|
5246 |
+
this._observer.observe(this.$element[0], {
|
5247 |
+
attributes: true,
|
5248 |
+
childList: true,
|
5249 |
+
subtree: false
|
5250 |
+
});
|
5251 |
+
} else if (this.$element[0].addEventListener) {
|
5252 |
+
this.$element[0].addEventListener(
|
5253 |
+
'DOMAttrModified',
|
5254 |
+
self._syncA,
|
5255 |
+
false
|
5256 |
+
);
|
5257 |
+
this.$element[0].addEventListener(
|
5258 |
+
'DOMNodeInserted',
|
5259 |
+
self._syncS,
|
5260 |
+
false
|
5261 |
+
);
|
5262 |
+
this.$element[0].addEventListener(
|
5263 |
+
'DOMNodeRemoved',
|
5264 |
+
self._syncS,
|
5265 |
+
false
|
5266 |
+
);
|
5267 |
+
}
|
5268 |
+
};
|
5269 |
+
|
5270 |
+
Select2.prototype._registerDataEvents = function () {
|
5271 |
+
var self = this;
|
5272 |
+
|
5273 |
+
this.dataAdapter.on('*', function (name, params) {
|
5274 |
+
self.trigger(name, params);
|
5275 |
+
});
|
5276 |
+
};
|
5277 |
+
|
5278 |
+
Select2.prototype._registerSelectionEvents = function () {
|
5279 |
+
var self = this;
|
5280 |
+
var nonRelayEvents = ['toggle', 'focus'];
|
5281 |
+
|
5282 |
+
this.selection.on('toggle', function () {
|
5283 |
+
self.toggleDropdown();
|
5284 |
+
});
|
5285 |
+
|
5286 |
+
this.selection.on('focus', function (params) {
|
5287 |
+
self.focus(params);
|
5288 |
+
});
|
5289 |
+
|
5290 |
+
this.selection.on('*', function (name, params) {
|
5291 |
+
if ($.inArray(name, nonRelayEvents) !== -1) {
|
5292 |
+
return;
|
5293 |
+
}
|
5294 |
+
|
5295 |
+
self.trigger(name, params);
|
5296 |
+
});
|
5297 |
+
};
|
5298 |
+
|
5299 |
+
Select2.prototype._registerDropdownEvents = function () {
|
5300 |
+
var self = this;
|
5301 |
+
|
5302 |
+
this.dropdown.on('*', function (name, params) {
|
5303 |
+
self.trigger(name, params);
|
5304 |
+
});
|
5305 |
+
};
|
5306 |
+
|
5307 |
+
Select2.prototype._registerResultsEvents = function () {
|
5308 |
+
var self = this;
|
5309 |
+
|
5310 |
+
this.results.on('*', function (name, params) {
|
5311 |
+
self.trigger(name, params);
|
5312 |
+
});
|
5313 |
+
};
|
5314 |
+
|
5315 |
+
Select2.prototype._registerEvents = function () {
|
5316 |
+
var self = this;
|
5317 |
+
|
5318 |
+
this.on('open', function () {
|
5319 |
+
self.$container.addClass('select2-container--open');
|
5320 |
+
});
|
5321 |
+
|
5322 |
+
this.on('close', function () {
|
5323 |
+
self.$container.removeClass('select2-container--open');
|
5324 |
+
});
|
5325 |
+
|
5326 |
+
this.on('enable', function () {
|
5327 |
+
self.$container.removeClass('select2-container--disabled');
|
5328 |
+
});
|
5329 |
+
|
5330 |
+
this.on('disable', function () {
|
5331 |
+
self.$container.addClass('select2-container--disabled');
|
5332 |
+
});
|
5333 |
+
|
5334 |
+
this.on('blur', function () {
|
5335 |
+
self.$container.removeClass('select2-container--focus');
|
5336 |
+
});
|
5337 |
+
|
5338 |
+
this.on('query', function (params) {
|
5339 |
+
if (!self.isOpen()) {
|
5340 |
+
self.trigger('open', {});
|
5341 |
+
}
|
5342 |
+
|
5343 |
+
this.dataAdapter.query(params, function (data) {
|
5344 |
+
self.trigger('results:all', {
|
5345 |
+
data: data,
|
5346 |
+
query: params
|
5347 |
+
});
|
5348 |
+
});
|
5349 |
+
});
|
5350 |
+
|
5351 |
+
this.on('query:append', function (params) {
|
5352 |
+
this.dataAdapter.query(params, function (data) {
|
5353 |
+
self.trigger('results:append', {
|
5354 |
+
data: data,
|
5355 |
+
query: params
|
5356 |
+
});
|
5357 |
+
});
|
5358 |
+
});
|
5359 |
+
|
5360 |
+
this.on('keypress', function (evt) {
|
5361 |
+
var key = evt.which;
|
5362 |
+
|
5363 |
+
if (self.isOpen()) {
|
5364 |
+
if (key === KEYS.ESC || key === KEYS.TAB ||
|
5365 |
+
(key === KEYS.UP && evt.altKey)) {
|
5366 |
+
self.close();
|
5367 |
+
|
5368 |
+
evt.preventDefault();
|
5369 |
+
} else if (key === KEYS.ENTER) {
|
5370 |
+
self.trigger('results:select', {});
|
5371 |
+
|
5372 |
+
evt.preventDefault();
|
5373 |
+
} else if ((key === KEYS.SPACE && evt.ctrlKey)) {
|
5374 |
+
self.trigger('results:toggle', {});
|
5375 |
+
|
5376 |
+
evt.preventDefault();
|
5377 |
+
} else if (key === KEYS.UP) {
|
5378 |
+
self.trigger('results:previous', {});
|
5379 |
+
|
5380 |
+
evt.preventDefault();
|
5381 |
+
} else if (key === KEYS.DOWN) {
|
5382 |
+
self.trigger('results:next', {});
|
5383 |
+
|
5384 |
+
evt.preventDefault();
|
5385 |
+
}
|
5386 |
+
} else {
|
5387 |
+
if (key === KEYS.ENTER || key === KEYS.SPACE ||
|
5388 |
+
(key === KEYS.DOWN && evt.altKey)) {
|
5389 |
+
self.open();
|
5390 |
+
|
5391 |
+
evt.preventDefault();
|
5392 |
+
}
|
5393 |
+
}
|
5394 |
+
});
|
5395 |
+
};
|
5396 |
+
|
5397 |
+
Select2.prototype._syncAttributes = function () {
|
5398 |
+
this.options.set('disabled', this.$element.prop('disabled'));
|
5399 |
+
|
5400 |
+
if (this.options.get('disabled')) {
|
5401 |
+
if (this.isOpen()) {
|
5402 |
+
this.close();
|
5403 |
+
}
|
5404 |
+
|
5405 |
+
this.trigger('disable', {});
|
5406 |
+
} else {
|
5407 |
+
this.trigger('enable', {});
|
5408 |
+
}
|
5409 |
+
};
|
5410 |
+
|
5411 |
+
Select2.prototype._syncSubtree = function (evt, mutations) {
|
5412 |
+
var changed = false;
|
5413 |
+
var self = this;
|
5414 |
+
|
5415 |
+
// Ignore any mutation events raised for elements that aren't options or
|
5416 |
+
// optgroups. This handles the case when the select element is destroyed
|
5417 |
+
if (
|
5418 |
+
evt && evt.target && (
|
5419 |
+
evt.target.nodeName !== 'OPTION' && evt.target.nodeName !== 'OPTGROUP'
|
5420 |
+
)
|
5421 |
+
) {
|
5422 |
+
return;
|
5423 |
+
}
|
5424 |
+
|
5425 |
+
if (!mutations) {
|
5426 |
+
// If mutation events aren't supported, then we can only assume that the
|
5427 |
+
// change affected the selections
|
5428 |
+
changed = true;
|
5429 |
+
} else if (mutations.addedNodes && mutations.addedNodes.length > 0) {
|
5430 |
+
for (var n = 0; n < mutations.addedNodes.length; n++) {
|
5431 |
+
var node = mutations.addedNodes[n];
|
5432 |
+
|
5433 |
+
if (node.selected) {
|
5434 |
+
changed = true;
|
5435 |
+
}
|
5436 |
+
}
|
5437 |
+
} else if (mutations.removedNodes && mutations.removedNodes.length > 0) {
|
5438 |
+
changed = true;
|
5439 |
+
}
|
5440 |
+
|
5441 |
+
// Only re-pull the data if we think there is a change
|
5442 |
+
if (changed) {
|
5443 |
+
this.dataAdapter.current(function (currentData) {
|
5444 |
+
self.trigger('selection:update', {
|
5445 |
+
data: currentData
|
5446 |
+
});
|
5447 |
+
});
|
5448 |
+
}
|
5449 |
+
};
|
5450 |
+
|
5451 |
+
/**
|
5452 |
+
* Override the trigger method to automatically trigger pre-events when
|
5453 |
+
* there are events that can be prevented.
|
5454 |
+
*/
|
5455 |
+
Select2.prototype.trigger = function (name, args) {
|
5456 |
+
var actualTrigger = Select2.__super__.trigger;
|
5457 |
+
var preTriggerMap = {
|
5458 |
+
'open': 'opening',
|
5459 |
+
'close': 'closing',
|
5460 |
+
'select': 'selecting',
|
5461 |
+
'unselect': 'unselecting'
|
5462 |
+
};
|
5463 |
+
|
5464 |
+
if (args === undefined) {
|
5465 |
+
args = {};
|
5466 |
+
}
|
5467 |
+
|
5468 |
+
if (name in preTriggerMap) {
|
5469 |
+
var preTriggerName = preTriggerMap[name];
|
5470 |
+
var preTriggerArgs = {
|
5471 |
+
prevented: false,
|
5472 |
+
name: name,
|
5473 |
+
args: args
|
5474 |
+
};
|
5475 |
+
|
5476 |
+
actualTrigger.call(this, preTriggerName, preTriggerArgs);
|
5477 |
+
|
5478 |
+
if (preTriggerArgs.prevented) {
|
5479 |
+
args.prevented = true;
|
5480 |
+
|
5481 |
+
return;
|
5482 |
+
}
|
5483 |
+
}
|
5484 |
+
|
5485 |
+
actualTrigger.call(this, name, args);
|
5486 |
+
};
|
5487 |
+
|
5488 |
+
Select2.prototype.toggleDropdown = function () {
|
5489 |
+
if (this.options.get('disabled')) {
|
5490 |
+
return;
|
5491 |
+
}
|
5492 |
+
|
5493 |
+
if (this.isOpen()) {
|
5494 |
+
this.close();
|
5495 |
+
} else {
|
5496 |
+
this.open();
|
5497 |
+
}
|
5498 |
+
};
|
5499 |
+
|
5500 |
+
Select2.prototype.open = function () {
|
5501 |
+
if (this.isOpen()) {
|
5502 |
+
return;
|
5503 |
+
}
|
5504 |
+
|
5505 |
+
this.trigger('query', {});
|
5506 |
+
};
|
5507 |
+
|
5508 |
+
Select2.prototype.close = function () {
|
5509 |
+
if (!this.isOpen()) {
|
5510 |
+
return;
|
5511 |
+
}
|
5512 |
+
|
5513 |
+
this.trigger('close', {});
|
5514 |
+
};
|
5515 |
+
|
5516 |
+
Select2.prototype.isOpen = function () {
|
5517 |
+
return this.$container.hasClass('select2-container--open');
|
5518 |
+
};
|
5519 |
+
|
5520 |
+
Select2.prototype.hasFocus = function () {
|
5521 |
+
return this.$container.hasClass('select2-container--focus');
|
5522 |
+
};
|
5523 |
+
|
5524 |
+
Select2.prototype.focus = function (data) {
|
5525 |
+
// No need to re-trigger focus events if we are already focused
|
5526 |
+
if (this.hasFocus()) {
|
5527 |
+
return;
|
5528 |
+
}
|
5529 |
+
|
5530 |
+
this.$container.addClass('select2-container--focus');
|
5531 |
+
this.trigger('focus', {});
|
5532 |
+
};
|
5533 |
+
|
5534 |
+
Select2.prototype.enable = function (args) {
|
5535 |
+
if (this.options.get('debug') && window.console && console.warn) {
|
5536 |
+
console.warn(
|
5537 |
+
'Select2: The `select2("enable")` method has been deprecated and will' +
|
5538 |
+
' be removed in later Select2 versions. Use $element.prop("disabled")' +
|
5539 |
+
' instead.'
|
5540 |
+
);
|
5541 |
+
}
|
5542 |
+
|
5543 |
+
if (args == null || args.length === 0) {
|
5544 |
+
args = [true];
|
5545 |
+
}
|
5546 |
+
|
5547 |
+
var disabled = !args[0];
|
5548 |
+
|
5549 |
+
this.$element.prop('disabled', disabled);
|
5550 |
+
};
|
5551 |
+
|
5552 |
+
Select2.prototype.data = function () {
|
5553 |
+
if (this.options.get('debug') &&
|
5554 |
+
arguments.length > 0 && window.console && console.warn) {
|
5555 |
+
console.warn(
|
5556 |
+
'Select2: Data can no longer be set using `select2("data")`. You ' +
|
5557 |
+
'should consider setting the value instead using `$element.val()`.'
|
5558 |
+
);
|
5559 |
+
}
|
5560 |
+
|
5561 |
+
var data = [];
|
5562 |
+
|
5563 |
+
this.dataAdapter.current(function (currentData) {
|
5564 |
+
data = currentData;
|
5565 |
+
});
|
5566 |
+
|
5567 |
+
return data;
|
5568 |
+
};
|
5569 |
+
|
5570 |
+
Select2.prototype.val = function (args) {
|
5571 |
+
if (this.options.get('debug') && window.console && console.warn) {
|
5572 |
+
console.warn(
|
5573 |
+
'Select2: The `select2("val")` method has been deprecated and will be' +
|
5574 |
+
' removed in later Select2 versions. Use $element.val() instead.'
|
5575 |
+
);
|
5576 |
+
}
|
5577 |
+
|
5578 |
+
if (args == null || args.length === 0) {
|
5579 |
+
return this.$element.val();
|
5580 |
+
}
|
5581 |
+
|
5582 |
+
var newVal = args[0];
|
5583 |
+
|
5584 |
+
if ($.isArray(newVal)) {
|
5585 |
+
newVal = $.map(newVal, function (obj) {
|
5586 |
+
return obj.toString();
|
5587 |
+
});
|
5588 |
+
}
|
5589 |
+
|
5590 |
+
this.$element.val(newVal).trigger('change');
|
5591 |
+
};
|
5592 |
+
|
5593 |
+
Select2.prototype.destroy = function () {
|
5594 |
+
this.$container.remove();
|
5595 |
+
|
5596 |
+
if (this.$element[0].detachEvent) {
|
5597 |
+
this.$element[0].detachEvent('onpropertychange', this._syncA);
|
5598 |
+
}
|
5599 |
+
|
5600 |
+
if (this._observer != null) {
|
5601 |
+
this._observer.disconnect();
|
5602 |
+
this._observer = null;
|
5603 |
+
} else if (this.$element[0].removeEventListener) {
|
5604 |
+
this.$element[0]
|
5605 |
+
.removeEventListener('DOMAttrModified', this._syncA, false);
|
5606 |
+
this.$element[0]
|
5607 |
+
.removeEventListener('DOMNodeInserted', this._syncS, false);
|
5608 |
+
this.$element[0]
|
5609 |
+
.removeEventListener('DOMNodeRemoved', this._syncS, false);
|
5610 |
+
}
|
5611 |
+
|
5612 |
+
this._syncA = null;
|
5613 |
+
this._syncS = null;
|
5614 |
+
|
5615 |
+
this.$element.off('.select2');
|
5616 |
+
this.$element.attr('tabindex', this.$element.data('old-tabindex'));
|
5617 |
+
|
5618 |
+
this.$element.removeClass('select2-hidden-accessible');
|
5619 |
+
this.$element.attr('aria-hidden', 'false');
|
5620 |
+
this.$element.removeData('select2');
|
5621 |
+
|
5622 |
+
this.dataAdapter.destroy();
|
5623 |
+
this.selection.destroy();
|
5624 |
+
this.dropdown.destroy();
|
5625 |
+
this.results.destroy();
|
5626 |
+
|
5627 |
+
this.dataAdapter = null;
|
5628 |
+
this.selection = null;
|
5629 |
+
this.dropdown = null;
|
5630 |
+
this.results = null;
|
5631 |
+
};
|
5632 |
+
|
5633 |
+
Select2.prototype.render = function () {
|
5634 |
+
var $container = $(
|
5635 |
+
'<span class="select2 select2-container">' +
|
5636 |
+
'<span class="selection"></span>' +
|
5637 |
+
'<span class="dropdown-wrapper" aria-hidden="true"></span>' +
|
5638 |
+
'</span>'
|
5639 |
+
);
|
5640 |
+
|
5641 |
+
$container.attr('dir', this.options.get('dir'));
|
5642 |
+
|
5643 |
+
this.$container = $container;
|
5644 |
+
|
5645 |
+
this.$container.addClass('select2-container--' + this.options.get('theme'));
|
5646 |
+
|
5647 |
+
$container.data('element', this.$element);
|
5648 |
+
|
5649 |
+
return $container;
|
5650 |
+
};
|
5651 |
+
|
5652 |
+
return Select2;
|
5653 |
+
});
|
5654 |
+
|
5655 |
+
S2.define('jquery-mousewheel',[
|
5656 |
+
'jquery'
|
5657 |
+
], function ($) {
|
5658 |
+
// Used to shim jQuery.mousewheel for non-full builds.
|
5659 |
+
return $;
|
5660 |
+
});
|
5661 |
+
|
5662 |
+
S2.define('jquery.select2',[
|
5663 |
+
'jquery',
|
5664 |
+
'jquery-mousewheel',
|
5665 |
+
|
5666 |
+
'./select2/core',
|
5667 |
+
'./select2/defaults'
|
5668 |
+
], function ($, _, Select2, Defaults) {
|
5669 |
+
if ($.fn.select2 == null) {
|
5670 |
+
// All methods that should return the element
|
5671 |
+
var thisMethods = ['open', 'close', 'destroy'];
|
5672 |
+
|
5673 |
+
$.fn.select2 = function (options) {
|
5674 |
+
options = options || {};
|
5675 |
+
|
5676 |
+
if (typeof options === 'object') {
|
5677 |
+
this.each(function () {
|
5678 |
+
var instanceOptions = $.extend(true, {}, options);
|
5679 |
+
|
5680 |
+
var instance = new Select2($(this), instanceOptions);
|
5681 |
+
});
|
5682 |
+
|
5683 |
+
return this;
|
5684 |
+
} else if (typeof options === 'string') {
|
5685 |
+
var ret;
|
5686 |
+
var args = Array.prototype.slice.call(arguments, 1);
|
5687 |
+
|
5688 |
+
this.each(function () {
|
5689 |
+
var instance = $(this).data('select2');
|
5690 |
+
|
5691 |
+
if (instance == null && window.console && console.error) {
|
5692 |
+
console.error(
|
5693 |
+
'The select2(\'' + options + '\') method was called on an ' +
|
5694 |
+
'element that is not using Select2.'
|
5695 |
+
);
|
5696 |
+
}
|
5697 |
+
|
5698 |
+
ret = instance[options].apply(instance, args);
|
5699 |
+
});
|
5700 |
+
|
5701 |
+
// Check if we should be returning `this`
|
5702 |
+
if ($.inArray(options, thisMethods) > -1) {
|
5703 |
+
return this;
|
5704 |
+
}
|
5705 |
+
|
5706 |
+
return ret;
|
5707 |
+
} else {
|
5708 |
+
throw new Error('Invalid arguments for Select2: ' + options);
|
5709 |
+
}
|
5710 |
+
};
|
5711 |
+
}
|
5712 |
+
|
5713 |
+
if ($.fn.select2.defaults == null) {
|
5714 |
+
$.fn.select2.defaults = Defaults;
|
5715 |
+
}
|
5716 |
+
|
5717 |
+
return Select2;
|
5718 |
+
});
|
5719 |
+
|
5720 |
+
// Return the AMD loader configuration so it can be used outside of this file
|
5721 |
+
return {
|
5722 |
+
define: S2.define,
|
5723 |
+
require: S2.require
|
5724 |
+
};
|
5725 |
+
}());
|
5726 |
+
|
5727 |
+
// Autoload the jQuery bindings
|
5728 |
+
// We know that all of the modules exist above this, so we're safe
|
5729 |
+
var select2 = S2.require('jquery.select2');
|
5730 |
+
|
5731 |
+
// Hold the AMD module references on the jQuery function that was just loaded
|
5732 |
+
// This allows Select2 to use the internal loader outside of this file, such
|
5733 |
+
// as in the language files.
|
5734 |
+
jQuery.fn.select2.amd = S2;
|
5735 |
+
|
5736 |
+
// Return the Select2 instance for anyone who is importing it.
|
5737 |
+
return select2;
|
5738 |
+
}));
|
classes/modules/target-rule/target-rule.css
ADDED
@@ -0,0 +1,155 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#astra_settings_meta_box{
|
2 |
+
display: none;
|
3 |
+
}
|
4 |
+
|
5 |
+
#sidebar-settings .inside {
|
6 |
+
margin: 0;
|
7 |
+
padding: 0;
|
8 |
+
}
|
9 |
+
|
10 |
+
table.bsf-sb-table.widefat {
|
11 |
+
border: none;
|
12 |
+
}
|
13 |
+
|
14 |
+
.bsf-sb-table .bsf-sb-row-heading,
|
15 |
+
.bsf-sb-table .bsf-sb-row-content {
|
16 |
+
padding: 20px 10px;
|
17 |
+
border-bottom: 1px solid #eaeaea;
|
18 |
+
}
|
19 |
+
|
20 |
+
.bsf-sb-table .bsf-sb-row-heading {
|
21 |
+
width: 250px;
|
22 |
+
vertical-align: middle;
|
23 |
+
border-right: 1px solid #eaeaea;
|
24 |
+
}
|
25 |
+
|
26 |
+
|
27 |
+
.bsf-sb-help {
|
28 |
+
color: #b3b3b3;
|
29 |
+
cursor: help;
|
30 |
+
float: right;
|
31 |
+
font-size: 18px;
|
32 |
+
vertical-align: middle;
|
33 |
+
}
|
34 |
+
|
35 |
+
.bsf-sb-row-heading label {
|
36 |
+
display: inline-block;
|
37 |
+
font-size: 13px;
|
38 |
+
line-height: 1.4em;
|
39 |
+
font-weight: bold;
|
40 |
+
padding: 0;
|
41 |
+
margin: 0 0 3px;
|
42 |
+
color: #333;
|
43 |
+
}
|
44 |
+
|
45 |
+
.bsf-sb-row-content input {
|
46 |
+
width: 100%;
|
47 |
+
}
|
48 |
+
|
49 |
+
|
50 |
+
|
51 |
+
/* Select2 */
|
52 |
+
span.select2.select2-container.select2-container--default {
|
53 |
+
margin-top: 0;
|
54 |
+
}
|
55 |
+
|
56 |
+
li.select2-results__option.select2-results__message {
|
57 |
+
background: #ecebeb;
|
58 |
+
margin-bottom: 0;
|
59 |
+
}
|
60 |
+
.bsf-sb-row td .select2-container{
|
61 |
+
display: inline-block;
|
62 |
+
position: relative;
|
63 |
+
vertical-align: middle;
|
64 |
+
width: 100% !important;
|
65 |
+
}
|
66 |
+
|
67 |
+
.select2-container--default.select2-container--focus .select2-selection--multiple,
|
68 |
+
.select2-container--default .select2-selection--multiple {
|
69 |
+
border: 1px solid #ddd;
|
70 |
+
margin-top: 10px;
|
71 |
+
}
|
72 |
+
|
73 |
+
.bsf-sb-table .target_rule-condition,
|
74 |
+
.bsf-sb-table .user_role-condition,
|
75 |
+
.select2-container .select2-search--inline,
|
76 |
+
.select2-container--default .select2-search--inline .select2-search__field {
|
77 |
+
width: 100% !important;
|
78 |
+
}
|
79 |
+
|
80 |
+
/* Target Rule field */
|
81 |
+
.bsf-sb-target-rule-condition,
|
82 |
+
.bsf-sb-user-role-condition {
|
83 |
+
position: relative;
|
84 |
+
padding: 0 30px 0 0;
|
85 |
+
/*margin-top: 10px;*/
|
86 |
+
}
|
87 |
+
|
88 |
+
.target_rule-specific-page-wrap {
|
89 |
+
position: relative;
|
90 |
+
padding: 0 30px 0 0;
|
91 |
+
}
|
92 |
+
|
93 |
+
.user_role-add-rule-wrap,
|
94 |
+
.target_rule-add-rule-wrap,
|
95 |
+
.target_rule-add-exclusion-rule,
|
96 |
+
.user_role-add-rule-wrap {
|
97 |
+
margin-top: 15px;
|
98 |
+
}
|
99 |
+
|
100 |
+
.bsf-sb-target-rule-display-on,
|
101 |
+
.bsf-sb-target-rule-exclude-on {
|
102 |
+
margin-bottom: 10px;
|
103 |
+
}
|
104 |
+
|
105 |
+
.target_rule-condition-delete,
|
106 |
+
.user_role-condition-delete {
|
107 |
+
position: absolute;
|
108 |
+
color: #999;
|
109 |
+
right: 0px;
|
110 |
+
top: 0px;
|
111 |
+
font-size: 18px;
|
112 |
+
line-height: 18px;
|
113 |
+
width: 18px;
|
114 |
+
height: 18px;
|
115 |
+
display: inline-block;
|
116 |
+
cursor: pointer;
|
117 |
+
top: 50%;
|
118 |
+
transform: translateY(-50%);
|
119 |
+
}
|
120 |
+
|
121 |
+
.target_rule-condition-delete:hover {
|
122 |
+
color: #d54e21;
|
123 |
+
}
|
124 |
+
|
125 |
+
.target_rule-add-rule-wrap {
|
126 |
+
display: inline-block;
|
127 |
+
}
|
128 |
+
|
129 |
+
.target_rule-add-exclusion-rule {
|
130 |
+
display: inline-block;
|
131 |
+
margin-left: 10px;
|
132 |
+
}
|
133 |
+
|
134 |
+
.configure-content [data-element="exclude_from"],
|
135 |
+
.configure-content [data-element="exclusive_on"] {
|
136 |
+
padding-bottom: 0;
|
137 |
+
}
|
138 |
+
|
139 |
+
.configure-content .bsf-sb-allow-specific-posts input,
|
140 |
+
.configure-content .bsf-sb-post-types {
|
141 |
+
margin-right: 3px;
|
142 |
+
}
|
143 |
+
|
144 |
+
.hide-on-devices input[type=checkbox] {
|
145 |
+
margin-right: 5px;
|
146 |
+
}
|
147 |
+
|
148 |
+
.search-panel.search-close-icon {
|
149 |
+
pointer-events: auto;
|
150 |
+
cursor: pointer;
|
151 |
+
}
|
152 |
+
|
153 |
+
.bsf-sb-hidden {
|
154 |
+
display: none !important;
|
155 |
+
}
|
classes/modules/target-rule/target-rule.js
ADDED
@@ -0,0 +1,237 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
;(function ( $, window, undefined ) {
|
2 |
+
|
3 |
+
var init_target_rule_select2 = function( selector ) {
|
4 |
+
|
5 |
+
$(selector).select2({
|
6 |
+
|
7 |
+
placeholder: "Search pages / post / categories",
|
8 |
+
|
9 |
+
ajax: {
|
10 |
+
url: ajaxurl,
|
11 |
+
dataType: 'json',
|
12 |
+
method: 'post',
|
13 |
+
delay: 250,
|
14 |
+
data: function (params) {
|
15 |
+
return {
|
16 |
+
q: params.term, // search term
|
17 |
+
page: params.page,
|
18 |
+
action: 'bsf_sb_get_posts_by_query'
|
19 |
+
};
|
20 |
+
},
|
21 |
+
processResults: function (data) {
|
22 |
+
// console.log(data);
|
23 |
+
// console.log("inside");
|
24 |
+
// parse the results into the format expected by Select2.
|
25 |
+
// since we are using custom formatting functions we do not need to
|
26 |
+
// alter the remote JSON data
|
27 |
+
|
28 |
+
return {
|
29 |
+
results: data
|
30 |
+
};
|
31 |
+
},
|
32 |
+
cache: true
|
33 |
+
},
|
34 |
+
minimumInputLength: 2,
|
35 |
+
});
|
36 |
+
};
|
37 |
+
|
38 |
+
var update_target_rule_input = function(wrapper) {
|
39 |
+
var rule_input = wrapper.find('.bsf-sb-target_rule-input');
|
40 |
+
var old_value = rule_input.val();
|
41 |
+
var new_value = [];
|
42 |
+
|
43 |
+
wrapper.find('.bsf-sb-target-rule-condition').each(function(i) {
|
44 |
+
|
45 |
+
var $this = $(this);
|
46 |
+
var temp_obj = {};
|
47 |
+
var rule_condition = $this.find('select.target_rule-condition');
|
48 |
+
var specific_page = $this.find('select.target_rule-specific-page');
|
49 |
+
|
50 |
+
var rule_condition_val = rule_condition.val();
|
51 |
+
var specific_page_val = specific_page.val();
|
52 |
+
|
53 |
+
if ( '' != rule_condition_val ) {
|
54 |
+
|
55 |
+
temp_obj = {
|
56 |
+
type : rule_condition_val,
|
57 |
+
specific: specific_page_val
|
58 |
+
}
|
59 |
+
|
60 |
+
new_value.push( temp_obj );
|
61 |
+
};
|
62 |
+
})
|
63 |
+
|
64 |
+
|
65 |
+
var rules_string = JSON.stringify( new_value );
|
66 |
+
rule_input.val( rules_string );
|
67 |
+
};
|
68 |
+
|
69 |
+
var update_close_button = function(wrapper) {
|
70 |
+
|
71 |
+
type = wrapper.closest('.bsf-sb-target-rule-wrapper').attr('data-type');
|
72 |
+
rules = wrapper.find('.bsf-sb-target-rule-condition');
|
73 |
+
show_close = false;
|
74 |
+
|
75 |
+
if ( 'display' == type ) {
|
76 |
+
if ( rules.length > 1 ) {
|
77 |
+
show_close = true;
|
78 |
+
}
|
79 |
+
}else{
|
80 |
+
show_close = true;
|
81 |
+
}
|
82 |
+
|
83 |
+
rules.each(function() {
|
84 |
+
if ( show_close ) {
|
85 |
+
jQuery(this).find('.target_rule-condition-delete').removeClass('bsf-sb-hidden');
|
86 |
+
}else{
|
87 |
+
jQuery(this).find('.target_rule-condition-delete').addClass('bsf-sb-hidden');
|
88 |
+
}
|
89 |
+
});
|
90 |
+
};
|
91 |
+
|
92 |
+
var update_exclusion_button = function( force_show, force_hide ) {
|
93 |
+
var display_on = $('.bsf-sb-target-rule-display-on-wrap');
|
94 |
+
var exclude_on = $('.bsf-sb-target-rule-exclude-on-wrap');
|
95 |
+
|
96 |
+
var exclude_field_wrap = exclude_on.closest('tr');
|
97 |
+
var add_exclude_block = display_on.find('.target_rule-add-exclusion-rule');
|
98 |
+
var exclude_conditions = exclude_on.find('.bsf-sb-target-rule-condition');
|
99 |
+
|
100 |
+
if ( true == force_hide ) {
|
101 |
+
exclude_field_wrap.addClass( 'bsf-sb-hidden' );
|
102 |
+
add_exclude_block.removeClass( 'bsf-sb-hidden' );
|
103 |
+
}else if( true == force_show ){
|
104 |
+
exclude_field_wrap.removeClass( 'bsf-sb-hidden' );
|
105 |
+
add_exclude_block.addClass( 'bsf-sb-hidden' );
|
106 |
+
}else{
|
107 |
+
|
108 |
+
if ( 1 == exclude_conditions.length && '' == $(exclude_conditions[0]).find('select.target_rule-condition').val() ) {
|
109 |
+
exclude_field_wrap.addClass( 'bsf-sb-hidden' );
|
110 |
+
add_exclude_block.removeClass( 'bsf-sb-hidden' );
|
111 |
+
}else{
|
112 |
+
exclude_field_wrap.removeClass( 'bsf-sb-hidden' );
|
113 |
+
add_exclude_block.addClass( 'bsf-sb-hidden' );
|
114 |
+
}
|
115 |
+
}
|
116 |
+
|
117 |
+
};
|
118 |
+
|
119 |
+
$(document).ready(function($) {
|
120 |
+
|
121 |
+
jQuery( '.bsf-sb-target-rule-condition' ).each( function() {
|
122 |
+
var $this = $( this ),
|
123 |
+
condition = $this.find('select.target_rule-condition'),
|
124 |
+
condition_val = condition.val(),
|
125 |
+
specific_page = $this.next( '.target_rule-specific-page-wrap' );
|
126 |
+
|
127 |
+
if( 'specifics' == condition_val ) {
|
128 |
+
specific_page.slideDown( 300 );
|
129 |
+
}
|
130 |
+
} );
|
131 |
+
|
132 |
+
|
133 |
+
jQuery('select.target-rule-select2').each(function(index, el) {
|
134 |
+
init_target_rule_select2( el );
|
135 |
+
});
|
136 |
+
|
137 |
+
jQuery('.bsf-sb-target-rule-selector-wrapper').each(function() {
|
138 |
+
update_close_button( jQuery(this) );
|
139 |
+
})
|
140 |
+
|
141 |
+
/* Show hide exclusion button */
|
142 |
+
update_exclusion_button();
|
143 |
+
|
144 |
+
jQuery( document ).on( 'change', '.bsf-sb-target-rule-condition select.target_rule-condition' , function( e ) {
|
145 |
+
|
146 |
+
var $this = jQuery(this),
|
147 |
+
this_val = $this.val(),
|
148 |
+
field_wrap = $this.closest('.bsf-sb-target-rule-wrapper');
|
149 |
+
|
150 |
+
if( 'specifics' == this_val ) {
|
151 |
+
$this.closest( '.bsf-sb-target-rule-condition' ).next( '.target_rule-specific-page-wrap' ).slideDown( 300 );
|
152 |
+
} else {
|
153 |
+
$this.closest( '.bsf-sb-target-rule-condition' ).next( '.target_rule-specific-page-wrap' ).slideUp( 300 );
|
154 |
+
}
|
155 |
+
|
156 |
+
update_target_rule_input( field_wrap );
|
157 |
+
} );
|
158 |
+
|
159 |
+
jQuery( '.bsf-sb-target-rule-selector-wrapper' ).on( 'change', '.target-rule-select2', function(e) {
|
160 |
+
var $this = jQuery( this ),
|
161 |
+
field_wrap = $this.closest('.bsf-sb-target-rule-wrapper');
|
162 |
+
|
163 |
+
update_target_rule_input( field_wrap );
|
164 |
+
});
|
165 |
+
|
166 |
+
jQuery( '.bsf-sb-target-rule-selector-wrapper' ).on( 'click', '.target_rule-add-rule-wrap a', function(e) {
|
167 |
+
e.preventDefault();
|
168 |
+
e.stopPropagation();
|
169 |
+
var $this = jQuery( this ),
|
170 |
+
id = $this.attr( 'data-rule-id' ),
|
171 |
+
new_id = parseInt(id) + 1,
|
172 |
+
type = $this.attr( 'data-rule-type' ),
|
173 |
+
rule_wrap = $this.closest('.bsf-sb-target-rule-selector-wrapper').find('.target_rule-builder-wrap'),
|
174 |
+
template = wp.template( 'bsf-sb-target-rule-' + type + '-condition' ),
|
175 |
+
field_wrap = $this.closest('.bsf-sb-target-rule-wrapper');
|
176 |
+
|
177 |
+
rule_wrap.append( template( { id : new_id, type : type } ) );
|
178 |
+
|
179 |
+
init_target_rule_select2( '.bsf-sb-target-rule-'+type+'-on .target-rule-select2' );
|
180 |
+
|
181 |
+
$this.attr( 'data-rule-id', new_id );
|
182 |
+
|
183 |
+
update_close_button( field_wrap );
|
184 |
+
});
|
185 |
+
|
186 |
+
jQuery( '.bsf-sb-target-rule-selector-wrapper' ).on( 'click', '.target_rule-condition-delete', function(e) {
|
187 |
+
var $this = jQuery( this ),
|
188 |
+
rule_condition = $this.closest('.bsf-sb-target-rule-condition'),
|
189 |
+
field_wrap = $this.closest('.bsf-sb-target-rule-wrapper');
|
190 |
+
cnt = 0,
|
191 |
+
data_type = field_wrap.attr( 'data-type' ),
|
192 |
+
optionVal = $this.siblings('.target_rule-condition-wrap').children('.target_rule-condition').val();
|
193 |
+
|
194 |
+
if ( 'exclude' == data_type && '0' == rule_condition.attr('data-rule') ) {
|
195 |
+
|
196 |
+
field_wrap.find('.target_rule-condition').val('');
|
197 |
+
field_wrap.find('.target_rule-specific-page').val('');
|
198 |
+
field_wrap.find('.target_rule-condition').trigger('change');
|
199 |
+
update_exclusion_button( false, true );
|
200 |
+
|
201 |
+
} else {
|
202 |
+
|
203 |
+
$this.parent('.bsf-sb-target-rule-condition').next('.target_rule-specific-page-wrap').remove();
|
204 |
+
rule_condition.remove();
|
205 |
+
}
|
206 |
+
|
207 |
+
field_wrap.find('.bsf-sb-target-rule-condition').each(function(i) {
|
208 |
+
var condition = jQuery( this ),
|
209 |
+
old_rule_id = condition.attr('data-rule'),
|
210 |
+
select_location = condition.find('.target_rule-condition'),
|
211 |
+
select_specific = condition.find('.target_rule-specific-page'),
|
212 |
+
location_name = select_location.attr( 'name' );
|
213 |
+
|
214 |
+
condition.attr( 'data-rule', i );
|
215 |
+
|
216 |
+
select_location.attr( 'name', location_name.replace('['+old_rule_id+']', '['+i+']') );
|
217 |
+
|
218 |
+
condition.removeClass('bsf-sb-target-rule-'+old_rule_id).addClass('bsf-sb-target-rule-'+i);
|
219 |
+
|
220 |
+
cnt = i;
|
221 |
+
});
|
222 |
+
|
223 |
+
field_wrap.find('.target_rule-add-rule-wrap a').attr( 'data-rule-id', cnt )
|
224 |
+
|
225 |
+
update_close_button( field_wrap );
|
226 |
+
update_target_rule_input( field_wrap );
|
227 |
+
});
|
228 |
+
|
229 |
+
jQuery( '.bsf-sb-target-rule-selector-wrapper' ).on( 'click', '.target_rule-add-exclusion-rule a', function(e) {
|
230 |
+
e.preventDefault();
|
231 |
+
e.stopPropagation();
|
232 |
+
update_exclusion_button( true );
|
233 |
+
});
|
234 |
+
|
235 |
+
});
|
236 |
+
|
237 |
+
}(jQuery, window));
|
classes/modules/target-rule/user-role.js
ADDED
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
;(function ( $, window, undefined ) {
|
2 |
+
|
3 |
+
var user_role_update_close_button = function(wrapper) {
|
4 |
+
|
5 |
+
type = wrapper.closest('.bsf-sb-user-role-wrapper').attr('data-type');
|
6 |
+
rules = wrapper.find('.bsf-sb-user-role-condition');
|
7 |
+
show_close = false;
|
8 |
+
|
9 |
+
if ( rules.length > 1 ) {
|
10 |
+
show_close = true;
|
11 |
+
}
|
12 |
+
|
13 |
+
rules.each(function() {
|
14 |
+
if ( show_close ) {
|
15 |
+
jQuery(this).find('.user_role-condition-delete').removeClass('bsf-sb-hidden');
|
16 |
+
}else{
|
17 |
+
jQuery(this).find('.user_role-condition-delete').addClass('bsf-sb-hidden');
|
18 |
+
}
|
19 |
+
});
|
20 |
+
};
|
21 |
+
|
22 |
+
$(document).ready(function($) {
|
23 |
+
|
24 |
+
jQuery('.bsf-sb-user-role-selector-wrapper').each(function() {
|
25 |
+
user_role_update_close_button( jQuery(this) );
|
26 |
+
})
|
27 |
+
|
28 |
+
jQuery( '.bsf-sb-user-role-selector-wrapper' ).on( 'click', '.user_role-add-rule-wrap a', function(e) {
|
29 |
+
e.preventDefault();
|
30 |
+
e.stopPropagation();
|
31 |
+
var $this = jQuery( this ),
|
32 |
+
id = $this.attr( 'data-rule-id' ),
|
33 |
+
new_id = parseInt(id) + 1,
|
34 |
+
rule_wrap = $this.closest('.bsf-sb-user-role-selector-wrapper').find('.user_role-builder-wrap'),
|
35 |
+
template = wp.template( 'bsf-sb-user-role-condition' ),
|
36 |
+
field_wrap = $this.closest('.bsf-sb-user-role-wrapper');
|
37 |
+
|
38 |
+
rule_wrap.append( template( { id : new_id } ) );
|
39 |
+
|
40 |
+
$this.attr( 'data-rule-id', new_id );
|
41 |
+
|
42 |
+
user_role_update_close_button( field_wrap );
|
43 |
+
});
|
44 |
+
|
45 |
+
jQuery( '.bsf-sb-user-role-selector-wrapper' ).on( 'click', '.user_role-condition-delete', function(e) {
|
46 |
+
var $this = jQuery( this ),
|
47 |
+
rule_condition = $this.closest('.bsf-sb-user-role-condition'),
|
48 |
+
field_wrap = $this.closest('.bsf-sb-user-role-wrapper');
|
49 |
+
cnt = 0,
|
50 |
+
data_type = field_wrap.attr( 'data-type' ),
|
51 |
+
optionVal = $this.siblings('.user_role-condition-wrap').children('.user_role-condition').val();
|
52 |
+
|
53 |
+
rule_condition.remove();
|
54 |
+
|
55 |
+
field_wrap.find('.bsf-sb-user-role-condition').each(function(i) {
|
56 |
+
var condition = jQuery( this ),
|
57 |
+
old_rule_id = condition.attr('data-rule'),
|
58 |
+
select_location = condition.find('.user_role-condition'),
|
59 |
+
location_name = select_location.attr( 'name' );
|
60 |
+
|
61 |
+
condition.attr( 'data-rule', i );
|
62 |
+
|
63 |
+
select_location.attr( 'name', location_name.replace('['+old_rule_id+']', '['+i+']') );
|
64 |
+
|
65 |
+
condition.removeClass('bsf-sb-user-role-'+old_rule_id).addClass('bsf-sb-user-role-'+i);
|
66 |
+
|
67 |
+
cnt = i;
|
68 |
+
});
|
69 |
+
|
70 |
+
field_wrap.find('.user_role-add-rule-wrap a').attr( 'data-rule-id', cnt )
|
71 |
+
|
72 |
+
user_role_update_close_button( field_wrap );
|
73 |
+
});
|
74 |
+
});
|
75 |
+
}(jQuery, window));
|
readme.txt
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
=== Lightweight Sidebar Manager ===
|
2 |
+
Contributors: BrainstormForce
|
3 |
+
Donate link: https://www.brainstormforce.com/payment/
|
4 |
+
Tags: custom sidebar, sidebar manager, custom widget areas, widgets, conditional sidebar
|
5 |
+
Requires at least: 4.0
|
6 |
+
Tested up to: 4.8
|
7 |
+
Stable tag: trunk
|
8 |
+
License: GPLv2 or later
|
9 |
+
License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
10 |
+
|
11 |
+
Create new sidebar areas and display them conditionally on certain pages. Works with all themes.
|
12 |
+
|
13 |
+
== Description ==
|
14 |
+
|
15 |
+
Normally you have a sidebar that appears throughout the website. However, sometimes it is necessary to display a relevant, different sidebar on certain pages on the website. For an example: on WooCommerce pages, a sidebar with related or top seller products would be more relevant than latest comments, blog posts right?
|
16 |
+
|
17 |
+
This plugin helps you solve that problem as it allows you to create new sidebars and display them conditionally on certain locations of the website easily. Once the sidebar is created and displayed on pages you like, you can add relevant widgets in it.
|
18 |
+
|
19 |
+
Some of the Features:
|
20 |
+
|
21 |
+
1. Create unlimited sidebars
|
22 |
+
2. Place them any location your theme has defined (Footer Widgets / Left or Right Sidebar)
|
23 |
+
3. Works with any theme
|
24 |
+
4. Conditionally display sidebars on specific posts, pages, taxonomies or custom post types
|
25 |
+
5. Display sidebars based on user roles
|
26 |
+
|
27 |
+
== Installation ==
|
28 |
+
|
29 |
+
1. Upload the plugin files to the `/wp-content/plugins/plugin-name` directory, or install the plugin through the WordPress plugins screen directly.
|
30 |
+
2. Activate the plugin through the 'Plugins' screen in WordPress
|
31 |
+
3. Go to Appearance->Sidebars to create new sidebars
|
32 |
+
4. In Appearance->Widgets, you can add widgets in the newly added sidebar area.
|
33 |
+
|
34 |
+
== Frequently Asked Questions ==
|
35 |
+
|
36 |
+
= Which themes does this work with? =
|
37 |
+
|
38 |
+
This plugin works with all well coded themes that have sidebar locations defined.
|
39 |
+
|
40 |
+
= There are many other similar plugins. Why this? =
|
41 |
+
|
42 |
+
Other plugins we found are heavy with ugly interface, non supported, developed only for specific themes or affecting performance. So we wanted to develop something simple & straightforward so we can recommend it users of our Astra Theme.
|
43 |
+
|
44 |
+
|
45 |
+
== Screenshots ==
|
46 |
+
|
47 |
+
1. Add a New Sidebar from Appearance -> Sidebars -> Add New.
|
48 |
+
1. Give sidebar a name, Select a sidebar that is to be replaced and locations where the sidebar should appear.
|
49 |
+
1. Add Content to the newly created sidebar.
|
sidebar-manager.php
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Plugin Name: Sidebar Manager
|
4 |
+
* Plugin URI: http://www.brainstormforce.com
|
5 |
+
* Description: This is the plugin to create custom siderbars to your site.
|
6 |
+
* Version: 1.0.0
|
7 |
+
* Author: Brainstorm Force
|
8 |
+
* Author URI: https://www.brainstormforce.com/
|
9 |
+
* Text Domain: bsfsidebars
|
10 |
+
*
|
11 |
+
* @package Custom_Sidebars
|
12 |
+
*/
|
13 |
+
|
14 |
+
require_once 'classes/class-bsf-sb-loader.php';
|