1/*global __awpcp_js_data, __awpcp_js_l10n, ajaxurl*/ 2 3/*! 4 * jQuery Tiny Pub/Sub - v0.3 - 11/4/2010 5 * http://benalman.com/ 6 * 7 * Copyright (c) 2010 "Cowboy" Ben Alman 8 * Dual licensed under the MIT and GPL licenses. 9 * http://benalman.com/about/license/ 10 */ 11(function($){ 12 var o = $({}); 13 14 $.subscribe = function() { 15 o.bind.apply( o, arguments ); 16 }; 17 18 $.unsubscribe = function() { 19 o.unbind.apply( o, arguments ); 20 }; 21 22 $.publish = function() { 23 o.trigger.apply( o, arguments ); 24 }; 25})(jQuery); 26 27 28 29(function($) { 30 31 /* AWPCP Main Object */ 32 33 var AWPCP = function() { 34 if (typeof __awpcp_js_data === 'object') { 35 this.options = __awpcp_js_data; 36 } else { 37 this.options = {}; 38 } 39 40 if (typeof __awpcp_js_l10n === 'object') { 41 this.localization = __awpcp_js_l10n; 42 } else { 43 this.localization = {}; 44 } 45 46 if (this.get('ajaxurl') === null) { 47 if (typeof AWPCP !== 'undefined' && AWPCP.ajaxurl) { 48 this.set('ajaxurl', AWPCP.ajaxurl); 49 } else if (ajaxurl) { 50 this.set('ajaxurl', ajaxurl); 51 } else { 52 this.set('ajaxurl', '/wp-admin/admin-ajax.php'); 53 } 54 } 55 }; 56 57 $.extend(AWPCP.prototype, { 58 set: function(name, value) { 59 this.options[name] = value; 60 return this; 61 }, 62 63 get: function(name) { 64 return this.options[name] ? this.options[name] : null; 65 }, 66 67 l10n: function(context, message) { 68 if (this.localization.hasOwnProperty(context)) { 69 if (!message) { 70 return this.localization[context]; 71 } else if (message && this.localization[context].hasOwnProperty(message)) { 72 return this.localization[context][message]; 73 } 74 } 75 return ''; 76 }, 77 78 /** 79 * Common validation setup: 80 * 81 * - make reCAPTCHA fields required 82 * - default jQuery Validate configuration 83 * @return {[type]} [description] 84 */ 85 validate: function(defaults) { 86 // if there are reCAPTCHA fields in the page, make them required 87 $('[name="recaptcha_response_field"]').addClass('required'); 88 89 $.extend($.validator.messages, $.AWPCP.get('default-validation-messages')); 90 91 $.validator.addMethod('money', (function() { 92 var decimal = $.AWPCP.get('decimal-separator'), 93 thousands = $.AWPCP.get('thousands-separator'), 94 pattern = new RegExp('^-?(?:\\d+|\\d{1,3}(?:\\' + thousands + '\\d{3})+)?(?:\\' + decimal + '\\d+)?$'); 95 return function(value, element) { 96 return this.optional(element) || pattern.test(value); 97 }; 98 })()/*, validation message provided as a default validation message in awpcp.php */); 99 100 $.validator.addClassRules('integer', { 101 integer: true 102 }); 103 104 $.validator.setDefaults(defaults || { 105 errorClass: 'invalid', 106 errorElement: 'span', 107 errorPlacement: function (error, element) { 108 error.addClass('awpcp-error'); 109 var tables = ['payment_term', 'credit_plan', 'payment_method']; 110 if ($.inArray(element.attr('name'), tables) !== -1) { 111 error.insertBefore(element.closest('table')); 112 } else if (element.closest('.awpcp-form-spacer').length) { 113 error.appendTo(element.closest('.awpcp-form-spacer')); 114 } 115 } 116 }); 117 } 118 }); 119 120 $.AWPCP = new AWPCP(); 121 122 /* Widgets */ 123 124 $.AWPCP.CategoriesDropdown = function(dropdown) { 125 this.dropdown = dropdown.change(function() { 126 var category = parseInt($(this).val(), 10); 127 if (category > 0) { 128 $.publish('/category/updated', [category]); 129 } 130 }); 131 132 this.dropdown.change(); 133 }; 134 135 $.AWPCP.DatepickerField = function(element) { 136 var self = this; 137 138 self.element = $(element); 139 140 self.element.parent().find('[datepicker-placeholder]').datepicker({ 141 dateFormat: $.AWPCP.get('date-format'), 142 altField: self.element, 143 altFormat: 'yy/mm/dd' 144 }); 145 }; 146 147 $.AWPCP.PaginationForm = function(form) { 148 this.form = $(form); 149 this.form.find('select').change(function() { 150 this.form.submit(); 151 }); 152 }; 153 154 /* Common Operations */ 155 156 $(function() { 157 $('.awpcp-pagination-form').each(function() { 158 $.noop(new $.AWPCP.PaginationForm(this)); 159 }); 160 }); 161 162})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.