PluginProbe
Print, PDF & Email by PrintFriendly / 3.11.2
Print, PDF & Email by PrintFriendly v3.11.2
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 / admin.js

admin.js in Print, PDF & Email by PrintFriendly 3.11.2, at admin.js

263 lines 8.3 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').change(function(){
93 pf_custom_text_change();
94 }).change();
95
96 jQuery('#custom_text').keyup(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 jQuery('#custom span.printfriendly-text2').text( jQuery('#custom_text').val() );
103 }
104
105 function pf_initialize_preview(urlInputSelector, previewSelector) {
106 var el = jQuery(urlInputSelector);
107 var imgUrl = jQuery.trim(el.val());
108 var preview = jQuery(previewSelector + '-preview');
109 var error = jQuery(previewSelector + '-error');
110 el.bind('input paste change keyup', function() {
111 setTimeout(function() {
112 // ie shows error if we try to merge the two below into a single statement
113 var img = jQuery('<img/>');
114 var imgUrl = jQuery.trim(el.val());
115 img.load(function() {
116 error.html('');
117 preview.html('').append(img);})
118 .error(function() {
119 preview.html('');
120 if(img.attr('src') != '') {
121 error.html('<div class="error settings-error"><p><strong>Invalid Image URL</strong></p></div>');
122 }
123 }).attr('src', imgUrl);
124 // hide error for empty url
125 if(imgUrl == '')
126 error.html('');
127 }, 100);
128 });
129 }
130
131 pf_initialize_preview('#custom_image', '#pf-custom-button');
132 pf_initialize_preview('#upload-an-image', '#pf-image');
133 jQuery('#custom_image, #upload-an-image').change();
134 jQuery('#custom_image').bind('focus', function() {
135 jQuery('#custom-image').attr('checked', 'checked');
136 jQuery('#pf-custom-button-error').show();
137 });
138 jQuery('#button-style input.radio').bind('change', function() {
139 if(jQuery('#custom-image').attr('checked')) {
140 jQuery('#pf-custom-button-error').show();
141 } else {
142 jQuery('#pf-custom-button-error').hide();
143 }
144 }).change();
145
146 jQuery('#pf-logo').bind('change', function() {
147 if(jQuery(this).val() == 'favicon') {
148 jQuery('.custom-logo, #image-preview').hide();
149 } else {
150 jQuery('.custom-logo').css('display', 'inline-block');
151 jQuery('#image-preview').show();
152 }
153 }).change();
154
155 jQuery('#website_protocol').bind('change', function() {
156 if(jQuery(this).val() == 'https') {
157 jQuery('#https-beta-registration').show('slow');
158 } else {
159 jQuery('#https-beta-registration').hide('slow');
160 }
161 }).change();
162
163 jQuery('#password_protected').bind('change', function() {
164 if(jQuery(this).val() == 'yes') {
165 jQuery('#javascript').val('yes').change();
166 pf_on_javascript();
167 jQuery('#javascript').attr('disabled', 'disabled');
168 jQuery('#pf-javascript-container').hide('slow');
169 } else {
170 jQuery('#javascript').removeAttr('disabled');
171 jQuery('#pf-javascript-container').show('slow');
172 }
173 }).change();
174
175 jQuery('#javascript').bind('change', function() {
176 if(jQuery(this).val() == 'yes') {
177 pf_on_javascript();
178 } else {
179 pf_on_no_javascript();
180 }
181 }).change();
182
183 function pf_on_javascript() {
184 jQuery('.javascript').show();
185 jQuery('.no-javascript').hide();
186 }
187
188 function pf_on_no_javascript() {
189 jQuery('.javascript').hide();
190 jQuery('.no-javascript').show();
191 }
192
193 function pf_reset_style() {
194 jQuery('.printfriendly-text2').css('font-size',14);
195 jQuery('.printfriendly-text2').css('color','#000000');
196 }
197
198 function pf_apply_style() {
199 jQuery('.printfriendly-text2').css('color', jQuery('#text_color').val() );
200 size = jQuery('#text_size').val();
201 jQuery('.printfriendly-text2').css('font-size',parseInt(size));
202 }
203
204 // postboxes setup
205 jQuery('.if-js-closed').removeClass('if-js-closed').addClass('closed');
206
207 // categories checkboxes
208 var category_ids = jQuery('#category_ids').val();
209
210 if( typeof category_ids !== 'undefined' ) {
211 category_ids = category_ids.split(',');
212
213 if(category_ids[0] == 'all') {
214 var ids = [];
215 jQuery('#categorydiv :checkbox').each(function() {
216 jQuery(this).attr('checked', 'checked');
217 });
218 jQuery('#category-all :checkbox').each(function() {
219 ids.push(jQuery(this).val());
220 });
221 // for older wp versions we do not have per category settings so
222 // ids array will be empty and in that case we shouldn't replace 'all'
223 if(ids.length != 0) {
224 jQuery('#category_ids').val(ids.join(','));
225 }
226 } else {
227
228 jQuery('#categorydiv :checkbox').each(function() {
229 if(jQuery.inArray(jQuery(this).val(), category_ids) != -1) {
230 jQuery(this).attr('checked', 'checked');
231 }
232 });
233 }
234 }
235
236 jQuery('#categorydiv :checkbox').click(function() {
237 var values = jQuery('#category_ids').val();
238 var ids = [];
239 if(values != '')
240 ids = values.split(',');
241
242 var id = jQuery(this).val();
243
244 if(jQuery(this).is(':checked'))
245 ids.push(id);
246 else {
247 ids = jQuery.grep(ids, function(value) {
248 return value != id;
249 });
250 }
251
252 jQuery('#category_ids').val(ids.join(','));
253 });
254
255 // page checkboxes TODO...
256
257 var $pfIcon = jQuery('#pf-icon');
258 $pfIcon.change(function() {
259 jQuery('#custom_image').val('https://cdn.printfriendly.com/' + $pfIcon.val());
260 jQuery('#custom_image, #upload-an-image').change();
261 });
262 });
263