PluginProbe
QuadMenu – Mega Menu / 1.8.8
QuadMenu – Mega Menu v1.8.8
3.3.8 3.3.7 3.3.6 trunk 1.8.4 1.8.5 1.8.7 1.8.8 1.8.9 1.9.0 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 All 88 releases
quadmenu / lib / ReduxCore / inc / fields / select / field_select.js

field_select.js in QuadMenu – Mega Menu 1.8.8, at lib/ReduxCore/inc/fields/select/field_select.js

87 lines 3.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /*global redux_change, redux*/
2
3 (function( $ ) {
4 "use strict";
5
6 redux.field_objects = redux.field_objects || {};
7 redux.field_objects.select = redux.field_objects.select || {};
8
9 redux.field_objects.select.init = function( selector ) {
10 if ( !selector ) {
11 selector = $( document ).find( '.redux-container-select:visible' );
12 }
13
14 $( selector ).each(
15 function() {
16 var el = $( this );
17 var parent = el;
18
19 if ( !el.hasClass( 'redux-field-container' ) ) {
20 parent = el.parents( '.redux-field-container:first' );
21 }
22 if ( parent.is( ":hidden" ) ) { // Skip hidden fields
23 return;
24 }
25 if ( parent.hasClass( 'redux-field-init' ) ) {
26 parent.removeClass( 'redux-field-init' );
27 } else {
28 return;
29 }
30
31 el.find( 'select.redux-select-item' ).each(
32 function() {
33
34 var default_params = {
35 width: 'resolve',
36 triggerChange: true,
37 allowClear: true
38 };
39 if ( $(this).attr('multiple') == "multiple" ) {
40 default_params.width = "100%";
41 }
42
43 if ( $( this ).siblings( '.select2_params' ).size() > 0 ) {
44 var select2_params = $( this ).siblings( '.select2_params' ).val();
45 select2_params = JSON.parse( select2_params );
46 default_params = $.extend( {}, default_params, select2_params );
47 }
48
49 if ( $( this ).hasClass( 'font-icons' ) ) {
50 default_params = $.extend(
51 {}, {
52 formatResult: redux.field_objects.select.addIcon,
53 formatSelection: redux.field_objects.select.addIcon,
54 escapeMarkup: function( m ) {
55 return m;
56 }
57 }, default_params
58 );
59 }
60
61 $( this ).select2( default_params );
62
63 if ( $( this ).hasClass( 'select2-sortable' ) ) {
64 default_params = {};
65 default_params.bindOrder = 'sortableStop';
66 default_params.sortableOptions = {placeholder: 'ui-state-highlight'};
67 $( this ).select2Sortable( default_params );
68 }
69
70 $( this ).on(
71 "change", function() {
72 redux_change( $( $( this ) ) );
73 $( this ).select2SortableOrder();
74 }
75 );
76 }
77 );
78 }
79 );
80 };
81
82 redux.field_objects.select.addIcon = function( icon ) {
83 if ( icon.hasOwnProperty( 'id' ) ) {
84 return "<span class='elusive'><i class='" + icon.id + "'></i>" + "&nbsp;&nbsp;" + icon.text + "</span>";
85 }
86 };
87 })( jQuery );