PluginProbe
LoftLoader / trunk
LoftLoader vtrunk
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 trunk, at assets/js/customize.js

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