PluginProbe
Print, PDF & Email by PrintFriendly / 3.13.0
Print, PDF & Email by PrintFriendly v3.13.0
5.5.13 5.5.12 5.5.11 trunk 0.2 0.9 1.0 2.0 2.1.8 3.0 3.0.9 3.1.6 3.10.0 3.11.0 3.11.1 3.11.2 3.12.0 3.12.1 3.12.2 3.12.3 3.12.4 3.12.5 3.13.0 3.14.0 3.14.1 All 95 releases
printfriendly / trunk / admin.js

admin.js in Print, PDF & Email by PrintFriendly 3.13.0, at trunk/admin.js

277 lines 9.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 // Throughout the admin I chose to use slow animations to make it clear that stuff is being hidden or shown depending on settings.
2 jQuery(document).ready(function() {
3 jQuery('.show_list').change(function() {
4 if (jQuery('.show_list:checked').length == 0) {
5 jQuery('.content_placement').hide('slow');
6 jQuery('.content_placement input').attr('disabled','disabled');
7 jQuery('.show_template').attr('checked', 'checked');
8 } else {
9 jQuery('.show_template').attr('checked', false);
10 jQuery('.content_placement').show('slow');
11 jQuery('.content_placement input').removeAttr('disabled');
12 }
13
14 var postName = 'printfriendly_option[show_on_posts]';
15 var homeName = 'printfriendly_option[show_on_homepage]';
16
17 var optionName = jQuery(this).attr('name');
18 if (optionName == homeName || optionName == postName){
19 if(jQuery(this).is(':checked')) {
20 jQuery('#pf-categories').show('slow');
21 } else if(!jQuery('input[name="' + homeName + '"]').is(':checked')
22 && !jQuery('input[name="' + postName + '"]').is(':checked')) {
23 jQuery('#pf-categories').hide('slow');
24 }
25 }
26 }).change();
27
28 jQuery('.show_template').change(function() {
29 if(jQuery(this).is(':checked')) {
30 jQuery('.show_list').attr('checked', false);
31 jQuery('.show_list').attr('disabled', 'disabled');
32 jQuery('.content_placement').hide('slow');
33 jQuery('.content_placement input').attr('disabled','disabled');
34 jQuery('#pf-categories-metabox').hide('slow');
35 } else {
36 jQuery('.show_list').removeAttr('disabled');
37 jQuery('.content_placement').show('slow');
38 jQuery('.content_placement input').removeAttr('disabled');
39 }
40 }).change();
41
42 jQuery('#toggle-categories').click(function() {
43 if(jQuery('#pf-categories-metabox').is(':visible')) {
44 jQuery('#pf-categories-metabox').hide('slow');
45 } else {
46 jQuery('#pf-categories-metabox').show('slow');
47 }
48 });
49
50 jQuery(document).mouseup(function (e) {
51 var container = jQuery("#pf-categories");
52
53 if (container.has(e.target).length === 0) {
54 jQuery('#pf-categories-metabox').hide('slow');
55 }
56 });
57
58 jQuery('#colorSelector').ColorPicker({
59 color: jQuery('#text_color').val(),
60 onShow: function (colpkr) {
61 jQuery(colpkr).fadeIn(500);
62 return false;
63 },
64 onHide: function (colpkr) {
65 jQuery(colpkr).fadeOut(500);
66 return false;
67 },
68 onChange: function (hsb, hex, rgb) {
69 jQuery('#colorSelector div').css('backgroundColor', '#' + hex);
70 jQuery('#text_color').val('#' + hex);
71 jQuery('.printfriendly-text2').css('color','#' + hex);
72 }
73 });
74
75 jQuery('#text_size').change(function(){
76 size = jQuery('#text_size').val();
77 jQuery('.printfriendly-text2').css('font-size',parseInt(size));
78 }).change();
79
80 jQuery('#css input').change(function() {
81 if(jQuery(this).attr('checked')) {
82 jQuery(this).val('off');
83 jQuery('#margin, #txt-color, #txt-size').hide('slow');
84 pf_reset_style();
85 } else {
86 jQuery(this).val('on');
87 jQuery('#margin, #txt-color, #txt-size').show('slow');
88 pf_apply_style();
89 }
90 }).change();
91
92 jQuery('#custom_text').bind('change keyup', function(){
93 pf_custom_text_change();
94 });
95
96 jQuery("[name='printfriendly_option[custom_button_text]']").change(function(){
97 pf_custom_text_change();
98 });
99
100 function pf_custom_text_change(){
101 jQuery('#buttongroup3 span:not(.printandpdf)').text( jQuery('#custom_text').val() );
102 var newText = (jQuery("[name='printfriendly_option[custom_button_text]']:checked").val() === 'no-text') ? '' : jQuery('#custom_text').val();
103 jQuery('#custom-btn-group span.printfriendly-text2').text( newText );
104 }
105
106 function pf_initialize_preview(urlInputSelector, previewSelector) {
107 var el = jQuery(urlInputSelector);
108 var imgUrl = jQuery.trim(el.val());
109 var preview = jQuery(previewSelector + '-preview');
110 var error = jQuery(previewSelector + '-error');
111
112 el.bind('input paste change keyup', function() {
113 setTimeout(function() {
114 // ie shows error if we try to merge the two below into a single statement
115 var img = jQuery('<img/>');
116 var customButtonIcon = jQuery("[name='printfriendly_option[custom_button_icon]']:checked").val();
117
118 if (customButtonIcon === 'custom-image') {
119 imgUrl = jQuery('#custom_image').val();
120 } else if (customButtonIcon === 'no-image') {
121 imgUrl = '';
122 } else {
123 imgUrl = customButtonIcon;
124 }
125
126 img.load(function() {
127 error.html('');
128 preview.html('').append(img);})
129 .error(function() {
130 preview.html('');
131 if(img.attr('src') != '') {
132 error.html('<div class="error settings-error"><p><strong>Invalid Image URL</strong></p></div>');
133 }
134 }).attr('src', imgUrl);
135 // hide error for empty url
136 if(imgUrl == '')
137 error.html('');
138 }, 100);
139 });
140 }
141
142 pf_initialize_preview('#custom_image', '#pf-custom-button');
143 pf_initialize_preview("[name='printfriendly_option[custom_button_icon]']", '#pf-custom-button');
144 pf_initialize_preview('#upload-an-image', '#pf-image');
145 jQuery('#custom_image, #upload-an-image').change();
146 jQuery('#custom_image').bind('focus', function() {
147 jQuery('#custom-image').attr('checked', 'checked');
148 jQuery('#pf-custom-button-error').show();
149 });
150 jQuery('#button-style input.radio').bind('change', function() {
151 if(jQuery('#custom-image').attr('checked')) {
152 jQuery('#pf-custom-button-error').show();
153 } else {
154 jQuery('#pf-custom-button-error').hide();
155 }
156 }).change();
157
158 jQuery('#pf-logo').bind('change', function() {
159 if(jQuery(this).val() == 'favicon') {
160 jQuery('.custom-logo, #image-preview').hide();
161 } else {
162 jQuery('.custom-logo').css('display', 'inline-block');
163 jQuery('#image-preview').show();
164 }
165 }).change();
166
167 jQuery('#website_protocol').bind('change', function() {
168 if(jQuery(this).val() == 'https') {
169 jQuery('#https-beta-registration').show('slow');
170 } else {
171 jQuery('#https-beta-registration').hide('slow');
172 }
173 }).change();
174
175 jQuery('#password_protected').bind('change', function() {
176 if(jQuery(this).val() == 'yes') {
177 jQuery('#javascript').val('yes').change();
178 pf_on_javascript();
179 jQuery('#javascript').attr('disabled', 'disabled');
180 jQuery('#pf-javascript-container').hide('slow');
181 } else {
182 jQuery('#javascript').removeAttr('disabled');
183 jQuery('#pf-javascript-container').show('slow');
184 }
185 }).change();
186
187 jQuery('#javascript').bind('change', function() {
188 if(jQuery(this).val() == 'yes') {
189 pf_on_javascript();
190 } else {
191 pf_on_no_javascript();
192 }
193 }).change();
194
195 function pf_on_javascript() {
196 jQuery('.javascript').show();
197 jQuery('.no-javascript').hide();
198 }
199
200 function pf_on_no_javascript() {
201 jQuery('.javascript').hide();
202 jQuery('.no-javascript').show();
203 }
204
205 function pf_reset_style() {
206 jQuery('.printfriendly-text2').css('font-size',14);
207 jQuery('.printfriendly-text2').css('color','#000000');
208 }
209
210 function pf_apply_style() {
211 jQuery('.printfriendly-text2').css('color', jQuery('#text_color').val() );
212 size = jQuery('#text_size').val();
213 jQuery('.printfriendly-text2').css('font-size',parseInt(size));
214 }
215
216 // postboxes setup
217 jQuery('.if-js-closed').removeClass('if-js-closed').addClass('closed');
218
219 // categories checkboxes
220 var category_ids = jQuery('#category_ids').val();
221
222 if( typeof category_ids !== 'undefined' ) {
223 category_ids = category_ids.split(',');
224
225 if(category_ids[0] == 'all') {
226 var ids = [];
227 jQuery('#categorydiv :checkbox').each(function() {
228 jQuery(this).attr('checked', 'checked');
229 });
230 jQuery('#category-all :checkbox').each(function() {
231 ids.push(jQuery(this).val());
232 });
233 // for older wp versions we do not have per category settings so
234 // ids array will be empty and in that case we shouldn't replace 'all'
235 if(ids.length != 0) {
236 jQuery('#category_ids').val(ids.join(','));
237 }
238 } else {
239
240 jQuery('#categorydiv :checkbox').each(function() {
241 if(jQuery.inArray(jQuery(this).val(), category_ids) != -1) {
242 jQuery(this).attr('checked', 'checked');
243 }
244 });
245 }
246 }
247
248 jQuery('#categorydiv :checkbox').click(function() {
249 var values = jQuery('#category_ids').val();
250 var ids = [];
251 if(values != '')
252 ids = values.split(',');
253
254 var id = jQuery(this).val();
255
256 if(jQuery(this).is(':checked'))
257 ids.push(id);
258 else {
259 ids = jQuery.grep(ids, function(value) {
260 return value != id;
261 });
262 }
263
264 jQuery('#category_ids').val(ids.join(','));
265 });
266
267 jQuery('#custom_image').click(function() {
268 jQuery("#custom-image-rb").prop('checked', true);
269 jQuery("#custom-image-rb").trigger("change");
270 });
271
272 jQuery('#custom_text').click(function() {
273 jQuery("#custom-text-rb").prop('checked', true);
274 jQuery("#custom-text-rb").trigger("change");
275 });
276 });
277