Skip to content

Commit 2e1bdeb

Browse files
Backwards compatbility with jQuery.
1 parent f51e759 commit 2e1bdeb

1 file changed

Lines changed: 26 additions & 10 deletions

File tree

src/js/admin.js

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,22 +105,22 @@
105105
}
106106

107107
function updateResizeSettings() {
108-
if (jQuery('#tinypng_sizes_0').prop('checked')) {
108+
if (propOf('#tinypng_sizes_0', 'checked')) {
109109
jQuery('.tiny-resize-available').show()
110110
jQuery('.tiny-resize-unavailable').hide()
111111
} else {
112112
jQuery('.tiny-resize-available').hide()
113113
jQuery('.tiny-resize-unavailable').show()
114114
}
115115

116-
var original_enabled = jQuery('#tinypng_resize_original_enabled').prop('checked')
116+
var original_enabled = propOf('#tinypng_resize_original_enabled', 'checked')
117117
jQuery('#tinypng_resize_original_width, #tinypng_resize_original_height').each(function (i, el) {
118118
el.disabled = !original_enabled
119119
})
120120
}
121121

122122
function updatePreserveSettings() {
123-
if (jQuery('#tinypng_sizes_0').prop('checked')) {
123+
if (propOf('#tinypng_sizes_0', 'checked')) {
124124
jQuery('.tiny-preserve').show()
125125
} else {
126126
jQuery('.tiny-preserve').hide()
@@ -148,6 +148,26 @@
148148
}
149149
}
150150

151+
function propOf(selector, property) {
152+
if (typeof jQuery.fn.prop === 'function') {
153+
/* Added in 1.6. Before jQuery 1.6, the .attr() method sometimes took
154+
property values into account. */
155+
return jQuery(selector).prop(property)
156+
} else {
157+
return jQuery(selector).attr(property)
158+
}
159+
}
160+
161+
function setPropOf(selector, property, value) {
162+
if (typeof jQuery.fn.prop === 'function') {
163+
/* Added in 1.6. Before jQuery 1.6, the .attr() method sometimes took
164+
property values into account. */
165+
jQuery(selector).prop(property, value)
166+
} else {
167+
jQuery(selector).attr(property, value)
168+
}
169+
}
170+
151171
function changeEnterKeyTarget(selector, button) {
152172
eventOn('keyup keypress', selector, function(event) {
153173
var code = event.keyCode || event.which
@@ -162,11 +182,7 @@
162182
case 'upload-php':
163183
eventOn('click', 'button.tiny-compress', compressImage)
164184

165-
if (typeof jQuery.fn.prop === 'function') {
166-
jQuery('button.tiny-compress').prop('disabled', null)
167-
} else {
168-
jQuery('button.tiny-compress').attr('disabled', null)
169-
}
185+
setPropOf('button.tiny-compress', 'disabled', null)
170186

171187
jQuery('<option>').val('tiny_bulk_action').text(tinyCompress.L10nBulkAction).appendTo('select[name=action]')
172188
jQuery('<option>').val('tiny_bulk_action').text(tinyCompress.L10nBulkAction).appendTo('select[name=action2]')
@@ -188,12 +204,12 @@
188204
})
189205
}
190206

191-
jQuery('input[name*=tinypng_sizes], input#tinypng_resize_original_enabled').on('click', function() {
207+
eventOn('click', 'input[name*=tinypng_sizes], #tinypng_resize_original_enabled', function() {
192208
/* Unfortunately, we need some additional information to display
193209
the correct notice. */
194210
totalSelectedSizes = jQuery('input[name*=tinypng_sizes]:checked').length
195211
var image_count_url = ajaxurl + '?action=tiny_image_sizes_notice&image_sizes_selected=' + totalSelectedSizes
196-
if (jQuery('input#tinypng_resize_original_enabled').prop('checked') && jQuery('input#tinypng_sizes_0').prop('checked')) {
212+
if (propOf('#tinypng_resize_original_enabled', 'checked') && propOf('#tinypng_sizes_0', 'checked')) {
197213
image_count_url += '&resize_original=true'
198214
}
199215
jQuery('#tiny-image-sizes-notice').load(image_count_url)

0 commit comments

Comments
 (0)