PluginProbe
LoftLoader / 2.1.10
LoftLoader v2.1.10
trunk 1.0.0 1.0.1 1.0.2 2.0.0 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 2.3 2.3.1 2.3.2 2.3.3 All 34 releases
loftloader / assets / js / customize.js

customize.js in LoftLoader 2.1.10, at assets/js/customize.js

188 lines 6.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * Copyright (c) Loft.Ocean
3 * http://www.loftocean.com
4 */
5
6 (function(api, $){
7 $('head').append($('<style>', {'id': 'loftloader-hide-site-title', 'text': '.site-title { opacity: 0; }'}));
8 // Main Switch section
9 api.LoftLoaderSwitchSection = api.Section.extend({
10 initialize: function () {
11 return api.Section.prototype.initialize.apply( this, arguments );
12 },
13 ready: function(){
14 var checked = this.container.find('input[name=loftloader-main-switch]').attr('checked') ? true : false;
15 checked ? '' : $('#customize-theme-controls').addClass('loftloader-settings-disabled');
16 $('#customize-theme-controls').addClass('loftloader-controls-wrapper');
17 },
18 attachEvents: function () {
19 var container = this.container;
20 container.on('change', 'input[name=loftloader-main-switch]', function(e){
21 var checked = $(this).attr('checked') ? true : false,
22 $element = container.find('#customize-control-loftloader_main_switch input[type=checkbox]'),
23 controls_wrap = $('#customize-theme-controls');
24
25 checked ? $element.attr('checked', 'checked') : $element.removeAttr('checked');
26 $element.trigger('change');
27 checked ? controls_wrap.removeClass('loftloader-settings-disabled') : controls_wrap.addClass('loftloader-settings-disabled');
28 });
29 }
30 });
31 $.extend(api.sectionConstructor, {loftloader_switch: api.LoftLoaderSwitchSection});
32
33 // Slider control
34 api.controlConstructor.slider = api.Control.extend({
35 ready: function(){
36 var elem = this.container.find('.loader-ui-slider'),
37 input = this.container.find('input[data-customize-setting-link]');
38 elem.slider({
39 'range': 'min',
40 'min': elem.data('min'),
41 'max': elem.data('max'),
42 'value': elem.data('value'),
43 'step': elem.data('step'),
44 'slide': function(event, ui){
45 input.val(ui.value).trigger('change');
46 }
47 });
48 }
49 });
50
51 // Register event handler for hide controls/description
52 api.bind('ready', function(e){
53 // Change the site title in string "You are customizing ..."
54 loftloader_lite_i18n ? $('.site-title').text(loftloader_lite_i18n.name) : '';
55 $('#loftloader-hide-site-title').remove();
56
57 // Init for loader 2.0 customizer, when sync from lower version
58 var settings = api.get(),
59 $custom_img = $('#customize-control-loftloader_custom_img');
60 if($custom_img.length && !$custom_img.find('.attachment-thumb').length && settings && settings['loftloader_custom_img']){
61 var image = settings['loftloader_custom_img'];
62 if(image){
63 var $container = $custom_img.find('.attachment-media-view').addClass('attachment-media-view-image'),
64 $image = $('<div>', {'class': "thumbnail thumbnail-image"}).append($('<img>', {'class': "attachment-thumb", 'src': image}));
65
66 $container.children('.placeholder').css('display', 'none').after($image).remove();
67 }
68 }
69
70 $('body')
71 .on('change', 'input[type=number]', function(e){
72 var val = parseInt($(this).val()),
73 min = $(this).attr('min') ? parseInt($(this).attr('min')) : 1;
74 (val < min) ? $(this).val(min).trigger('change') : '';
75 })
76 .on('change', 'input.loftlader-checkbox', function(e){
77 var checked = $(this).attr('checked') ? true : false,
78 $element = $(this).siblings('input');
79 if($element.length){
80 checked ? $element.attr('checked', 'checked') : $element.removeAttr('checked');
81 $element.trigger('change');
82 }
83 })
84 .on('click', '.customize-more-toggle', function(e){
85 e.preventDefault();
86 var self = $(this),
87 description = $(this).siblings('.customize-control-description');
88
89 if(description.length){
90 self.hasClass('expanded') ? description.slideUp('slow') : description.slideDown('slow', function(){ $(this).css('display', 'block'); });
91 self.toggleClass('expanded');
92 }
93 })
94 .on('click', '.loftloader-any-page-generate', function(e){
95 e.preventDefault();
96 var shortcode = api.loftloader_generate_parameters();
97 $(this).siblings('.loftloader-any-page-shortcode').val('[loftloader ' + shortcode + ']').select();
98 });
99 });
100
101 /**
102 * Convert to string 'on' if current value is boolean true (not other value equals to true)
103 * @param value mix, the value to check
104 * @return mix, string 'on' if current value equals to boolean true, otherwise return the original value.
105 */
106 function loftloader_check_boolean(value){
107 return (value === true) ? 'on' : value;
108 }
109 /**
110 * Get customize setting value
111 * @param id string, the setting id
112 * @return mix, return dirty value/setting value or false (the id not exists)
113 **/
114 function loftloader_get_setting_value(id){
115 var settings = api.get(), //settings.settings, dirty_values = api.dirtyValues(),
116 value = settings[id] ? settings[id] : false; //dirty_values[id] ? dirty_values[id] : (settings[id] ? settings[id]['value'] : false);
117 if(typeof value === 'string'){
118 value = value.trim();
119 }
120 return loftloader_check_boolean(value);
121 }
122
123 // Generate loftloader parameters
124 api.loftloader_generate_parameters = function(){
125 var dependency = {
126 'loftloader_bg_color': {},
127 'loftloader_bg_opacity': {},
128 'loftloader_bg_animation': {},
129 'loftloader_loader_type': {
130 'sun': [
131 'loftloader_loader_color'
132 ],
133 'circles': [
134 'loftloader_loader_color'
135 ],
136 'wave': [
137 'loftloader_loader_color'
138 ],
139 'square': [
140 'loftloader_loader_color'
141 ],
142 'beating': [
143 'loftloader_loader_color'
144 ],
145 'frame': [
146 'loftloader_loader_color',
147 'loftloader_custom_img'
148 ],
149 'imgloading': [
150 'loftloader_custom_img',
151 'loftloader_img_width'
152 ]
153 },
154 'loftloader_show_close_timer': {},
155 'loftloader_show_close_tip': {},
156 'loftloader_inline_js': {}
157 };
158 var loftloader = type_value = loop = '';
159 if(loftloader_get_setting_value('loftloader_main_switch') === 'on'){
160 loftloader = 'loftloader_main_switch=on loftloader_show_range=sitewide';
161 for(var id in dependency){
162 type_value = loftloader_get_setting_value(id);
163 switch(id){
164 case 'loftloader_show_close_tip':
165 type_value = type_value ? ( '"' + btoa( unescape( encodeURIComponent( type_value ) ) ) + '"' ) : '""';
166 case 'loftloader_bg_color':
167 case 'loftloader_bg_opacity':
168 case 'loftloader_bg_animation':
169 loop = [];
170 break;
171 default:
172 loop = dependency[id][type_value] ? dependency[id][type_value] : [];
173 }
174 loftloader += ' ' + id + '=' + type_value;
175 if(loop){
176 for(var j in loop){
177 loftloader += ' ' + loop[j] + '=' + loftloader_get_setting_value(loop[j]);
178 }
179 }
180 }
181 }
182 else{
183 loftloader = 'loftloader_main_switch=false';
184 }
185 return loftloader;
186 }
187 })(wp.customize, jQuery);
188