Created
July 9, 2014 09:22
-
-
Save benheu/75d0cf550e6ae22d1ea7 to your computer and use it in GitHub Desktop.
Current front-subscribers.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Return 1 if a > b | |
// Return -1 if a < b | |
// Return 0 if a == b | |
function version_compare(a, b) | |
{ | |
if (a === b) | |
{ | |
return 0; | |
} | |
var a_components = a.split("."); | |
var b_components = b.split("."); | |
var len = Math.min(a_components.length, b_components.length); | |
// loop while the components are equal | |
for (var i = 0; i < len; i++) | |
{ | |
// A bigger than B | |
if (parseInt(a_components[i]) > parseInt(b_components[i])) | |
{ | |
return 1; | |
} | |
// B bigger than A | |
if (parseInt(a_components[i]) < parseInt(b_components[i])) | |
{ | |
return -1; | |
} | |
} | |
// If one's a prefix of the other, the longer one is greater. | |
if (a_components.length > b_components.length) | |
{ | |
return 1; | |
} | |
if (a_components.length < b_components.length) | |
{ | |
return -1; | |
} | |
// Otherwise they are the same. | |
return 0; | |
} | |
jQuery(function($){ | |
if ( $.fn.on === undefined ) { | |
// emulate on function for older versions | |
$.fn.on = function(events, selector, data, handler) { | |
if(typeof(selector) === 'function') { | |
$(this.context).live(events, selector); | |
} else { | |
$(selector).live(events, data, handler); | |
} | |
return this; | |
}; | |
} | |
$(document).on('click', '.showerrors', function() { | |
$('.xdetailed-errors').toggle(); | |
return false; | |
}); | |
$(document).on('click', '.shownotices', function() { | |
$('.xdetailed-updated').toggle(); | |
return false; | |
}); | |
$('form.widget_wysija').on('focus', 'input[placeholder]', function() { | |
if($(this).val() === $(this).attr('placeholder')) { | |
$(this).val(''); | |
} | |
}); | |
$('form.widget_wysija').on('blur', 'input[placeholder]', function() { | |
if($(this).val() === '') { | |
$(this).val($(this).attr('placeholder')); | |
} | |
}); | |
// retro compatibility default value labels in the old forms | |
$('form.widget_wysija').on('focus', 'input.defaultlabels', function() { | |
if($(this).val() === $(this).attr('title')) { | |
$(this).val(''); | |
} | |
}); | |
// retro compatibility default value labels in the old forms | |
$('form.widget_wysija').on('blur', 'input.defaultlabels', function() { | |
if($(this).val() === '') { | |
$(this).val($(this).attr('title')); | |
} | |
}); | |
$(document).on('submit', 'form.widget_wysija', function(event) { | |
// prevent default behaviour | |
event.preventDefault(); | |
// if no ajax is set, let's skip the ajax request and defaults to html submit | |
if(wysijaAJAX.noajax !== undefined) return $(this).validationEngine('validate'); | |
// check if the form is valid | |
if($(this).validationEngine('validate') === true) { | |
var action = $(this).find('input[name="action"]').val(), | |
controller = $(this).find('input[name="controller"]').val(), | |
form_id = $(this).attr('id'), | |
data = $(this).serializeArray(); | |
// set ajax request parameters | |
wysijaAJAX.task = action; | |
wysijaAJAX.controller = controller; | |
// set form id | |
wysijaAJAX.formid = form_id; | |
// set form data | |
$.each(data, function(index, value) { | |
wysijaAJAX['data['+index+'][name]'] = value.name; | |
wysijaAJAX['data['+index+'][value]'] = value.value; | |
}); | |
// display loading message | |
$('#msg-'+form_id).html('<div class="allmsgs"><blink>'+wysijaAJAX.loadingTrans+'</blink></div>'); | |
// fade form out | |
$('#'+form_id).fadeOut(); | |
// make ajax request | |
$.ajax({ | |
type: 'post', | |
url: wysijaAJAX.ajaxurl, | |
data: wysijaAJAX, | |
success: function(response) { | |
$('#msg-'+form_id).html('<div class="allmsgs"></div>'); | |
if(!response['result']) $('#'+form_id).fadeIn(); | |
$.each(response['msgs'], function(level, messages) { | |
if(!$('#msg-'+form_id+' .allmsgs .'+level+' ul').length) $('#msg-'+form_id+' .allmsgs').append('<div class="'+level+'"><ul></ul></div>'); | |
$.each(messages,function(key,val){ | |
$('#msg-'+form_id+' .allmsgs .'+level+' ul').append("<li>"+val+"</li>"); | |
}); | |
}); | |
}, | |
error: function(XMLHttpRequest, textStatus, errorThrown) { | |
$('#msg-'+form_id).html('<div class="allmsgs"></div>'); | |
$('#msg-'+form_id+' .allmsgs').html('<div class="error"><ul><li>Oops! There is a problem with this form:</li><li>textStatus:'+textStatus+'</li><li>errorThrown:'+errorThrown+'</li><li>responseText:'+XMLHttpRequest.responseText+'</li></ul></div>'); | |
}, | |
dataType: 'jsonp' | |
}); | |
} | |
return false; | |
}); | |
// when dom is loaded | |
$(function() { | |
// attach validation engine to all the wysija forms | |
// attach validation engine to all the wysija forms | |
var prompPosition = 'centerRight'; | |
if(wysijaAJAX.is_rtl) prompPosition = 'centerLeft'; | |
$('form.widget_wysija').validationEngine('attach', { | |
promptPosition: prompPosition, | |
scroll: false | |
}); | |
// make sure we empty placeholder values before running the validation | |
$('form.widget_wysija').bind('jqv.form.validating', function() { | |
$(this).find('input[placeholder]').each(function() { | |
if($(this).val() === $(this).attr('placeholder')) { | |
$(this).val(''); | |
} | |
}); | |
}); | |
// set placeholders values | |
$('form.widget_wysija').find('input[placeholder]').each(function() { | |
if($(this).val() === '') { | |
$(this).val($(this).attr('placeholder')); | |
} | |
}); | |
// retro compatibility default value labels in the old forms | |
$('form.widget_wysija').bind('jqv.form.validating', function() { | |
$(this).find('input.defaultlabels').each(function() { | |
if($(this).val() === $(this).attr('title')) { | |
$(this).val(''); | |
} | |
}); | |
}); | |
// retro compatibility default value labels in the old forms | |
$('form.widget_wysija').find('input.defaultlabels').each(function() { | |
if($(this).val() === '') { | |
$(this).val($(this).attr('title')); | |
} | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment