PluginProbe
LoftLoader / 2.3.1
LoftLoader v2.3.1
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.3.1, at assets/js/customize.js

221 lines 7.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 var current_url = document.createElement( 'a' ), current_search;
58 current_url.href = api.previewer.previewUrl();
59 current_search = api.utils.parseQueryString( current_url.search.substr( 1 ) );
60 api.previewer.unbind( 'url' ).bind( 'url', function( url ) {
61 var previewer = this, onUrlChange, urlChanged = false, urlParser;
62 urlParser = document.createElement( 'a' );
63 urlParser.href = url;
64 urlParser.search = $.param( { 'plugin': 'loftloader-lite' } );
65 url = urlParser.href;
66 previewer.scroll = 0;
67 onUrlChange = function() {
68 urlChanged = true;
69 };
70 previewer.previewUrl.bind( onUrlChange );
71 previewer.previewUrl.set( url );
72 previewer.previewUrl.unbind( onUrlChange );
73 if ( ! urlChanged ) {
74 previewer.refresh();
75 }
76 } );
77 if ( ! current_search['plugin'] ) {
78 current_search['plugin'] = 'loftloader-lite';
79 current_url.search = $.param( current_search );
80 api.previewer.previewUrl.set( current_url.href );
81 }
82
83
84 // Init for loader 2.0 customizer, when sync from lower version
85 var settings = api.get(),
86 $custom_img = $('#customize-control-loftloader_custom_img');
87 if($custom_img.length && !$custom_img.find('.attachment-thumb').length && settings && settings['loftloader_custom_img']){
88 var image = settings['loftloader_custom_img'];
89 if(image){
90 var $container = $custom_img.find('.attachment-media-view').addClass('attachment-media-view-image'),
91 $image = $('<div>', {'class': "thumbnail thumbnail-image"}).append($('<img>', {'class': "attachment-thumb", 'src': image}));
92
93 $container.children('.placeholder').css('display', 'none').after($image).remove();
94 }
95 }
96
97 $('body')
98 .on('change', 'input[type=number]', function(e){
99 var val = parseInt($(this).val()),
100 min = $(this).attr('min') ? parseInt($(this).attr('min')) : 1;
101 (val < min) ? $(this).val(min).trigger('change') : '';
102 })
103 .on('change', 'input.loftlader-checkbox', function(e){
104 var checked = $(this).attr('checked') ? true : false,
105 $element = $(this).siblings('input');
106 if($element.length){
107 checked ? $element.attr('checked', 'checked') : $element.removeAttr('checked');
108 $element.trigger('change');
109 }
110 })
111 .on('click', '.customize-more-toggle', function(e){
112 e.preventDefault();
113 var self = $(this),
114 description = $(this).siblings('.customize-control-description');
115
116 if(description.length){
117 self.hasClass('expanded') ? description.slideUp('slow') : description.slideDown('slow', function(){ $(this).css('display', 'block'); });
118 self.toggleClass('expanded');
119 }
120 })
121 .on('click', '.loftloader-any-page-generate', function(e){
122 e.preventDefault();
123 var shortcode = api.loftloader_generate_parameters();
124 $(this).siblings('.loftloader-any-page-shortcode').val('[loftloader ' + shortcode + ']').select();
125 });
126 });
127
128 /**
129 * Convert to string 'on' if current value is boolean true (not other value equals to true)
130 * @param value mix, the value to check
131 * @return mix, string 'on' if current value equals to boolean true, otherwise return the original value.
132 */
133 function loftloader_check_boolean(value){
134 return (value === true) ? 'on' : value;
135 }
136 /**
137 * Get customize setting value
138 * @param id string, the setting id
139 * @return mix, return dirty value/setting value or false (the id not exists)
140 **/
141 function loftloader_get_setting_value(id){
142 var settings = api.get(), //settings.settings, dirty_values = api.dirtyValues(),
143 value = settings[id] ? settings[id] : false; //dirty_values[id] ? dirty_values[id] : (settings[id] ? settings[id]['value'] : false);
144 if(typeof value === 'string'){
145 value = value.trim();
146 }
147 return loftloader_check_boolean(value);
148 }
149
150 // Generate loftloader parameters
151 api.loftloader_generate_parameters = function(){
152 var dependency = {
153 'loftloader_bg_color': {},
154 'loftloader_bg_opacity': {},
155 'loftloader_bg_animation': {},
156 'loftloader_loader_type': {
157 'sun': [
158 'loftloader_loader_color'
159 ],
160 'circles': [
161 'loftloader_loader_color'
162 ],
163 'wave': [
164 'loftloader_loader_color'
165 ],
166 'square': [
167 'loftloader_loader_color'
168 ],
169 'beating': [
170 'loftloader_loader_color'
171 ],
172 'frame': [
173 'loftloader_loader_color',
174 'loftloader_custom_img'
175 ],
176 'imgloading': [
177 'loftloader_custom_img',
178 'loftloader_img_width'
179 ]
180 },
181 'loftloader_show_close_timer': {},
182 'loftloader_show_close_tip': {},
183 'loftloader_max_load_time': {},
184 'loftloader_inline_js': {}
185 };
186 var loftloader = type_value = loop = '';
187 if(loftloader_get_setting_value('loftloader_main_switch') === 'on'){
188 loftloader = 'loftloader_main_switch=on loftloader_show_range=sitewide';
189 for(var id in dependency){
190 type_value = loftloader_get_setting_value(id);
191 switch(id){
192 case 'loftloader_show_close_tip':
193 type_value = type_value ? ( '"' + btoa( unescape( encodeURIComponent( type_value ) ) ) + '"' ) : '""';
194 case 'loftloader_bg_color':
195 case 'loftloader_bg_opacity':
196 case 'loftloader_bg_animation':
197 loop = [];
198 break;
199 case 'loftloader_max_load_time':
200 if ( ! type_value ) {
201 type_value = 0;
202 }
203 break;
204 default:
205 loop = dependency[id][type_value] ? dependency[id][type_value] : [];
206 }
207 loftloader += ' ' + id + '=' + type_value;
208 if(loop){
209 for(var j in loop){
210 loftloader += ' ' + loop[j] + '=' + loftloader_get_setting_value(loop[j]);
211 }
212 }
213 }
214 }
215 else{
216 loftloader = 'loftloader_main_switch=false';
217 }
218 return loftloader;
219 }
220 })(wp.customize, jQuery);
221