git-svn-id: https://192.168.0.254/svn/Proyectos.ASong2U_Web/trunk@23 cd1a4ea2-8c7f-e448-aada-19d1fee9e1d6
153 lines
4.8 KiB
JavaScript
153 lines
4.8 KiB
JavaScript
jQuery(document).ready(function(){
|
|
|
|
var j = jQuery;
|
|
|
|
j.validator.addMethod("validacionDestinatario", function(value, element, param) {
|
|
var result = false;
|
|
var idFriendVal = j("#friend_ids").val();
|
|
var eMailFriendVal = j("#friend_email").val();
|
|
var eMailRegExp = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
|
|
|
|
if (idFriendVal != "") {
|
|
result = true;
|
|
} else {
|
|
if ((eMailFriendVal != "") && (eMailRegExp.test(eMailFriendVal))) {
|
|
result = true;
|
|
}
|
|
}
|
|
|
|
return result;
|
|
|
|
}, "validacionDestinatario");
|
|
|
|
// validate signup form on keyup and submit
|
|
j("#new-dedication-form").validate({
|
|
rules: {
|
|
dedicate_to_input: {
|
|
required: true,
|
|
validacionDestinatario : true
|
|
}
|
|
},
|
|
ignore: [],
|
|
messages: {
|
|
dedicate_to_input: "Please choose one member name or enter a valid email"
|
|
}
|
|
});
|
|
|
|
/*var onAutocompleteSelect = function(value, data) {
|
|
j('#selection').html('<img src="\/global\/flags\/small\/' + data + '.png" alt="" \/> ' + value);
|
|
alert(data);
|
|
}*/
|
|
|
|
var options = {
|
|
minLength: 1,
|
|
serviceUrl: ajaxurl,
|
|
width: 300,
|
|
delimiter: /(,|;)\s*/,
|
|
onSelect: ia_on_autocomplete_select,
|
|
deferRequestBy: 0, //miliseconds
|
|
params: {
|
|
action: 'bp_dedication_autocomplete_ajax_handler'
|
|
},
|
|
noCache: true //set to true, to disable caching
|
|
};
|
|
|
|
j("#dedicate_to_input").autocomplete(options);
|
|
|
|
j("#dedicate_to_input").change(function(){
|
|
if(j('#dedicate_to_input').val() == '') {
|
|
j('#friend_ids').val('');
|
|
j('#friend_email').val('');
|
|
}
|
|
|
|
if(j('#dedicate_to_input').val().indexOf('@', 0) != -1 && j('#dedicate_to_input').val().indexOf('.', 0) != -1) {
|
|
j('#friend_email').val(j('#dedicate_to_input').val());
|
|
j('#friend_ids').val(',-1');
|
|
} else {
|
|
j('#friend_email').val('');
|
|
j('#friend_ids').val('');
|
|
}
|
|
});
|
|
|
|
var url = '';
|
|
|
|
j('#video_url').change(function(){
|
|
// Check for empty input field
|
|
if(j('#video_url').val() != ''){
|
|
// Get youtube video's thumbnail url
|
|
// using jYoutube jQuery plugin
|
|
url = j.jYoutube(j('#video_url').val());
|
|
title = getYouTubeInfo(j('#video_url').val(),
|
|
function(artist, song){
|
|
j('#artist_name').val(artist);
|
|
j('#song_name').val(song);
|
|
|
|
});
|
|
|
|
// Now append this image to <div id="thumbs">
|
|
j('#thumbs').html(j('<img src="'+url+'" />'));
|
|
}
|
|
});
|
|
|
|
if (j('#video_url').val()) {
|
|
j('#video_url').trigger('change');
|
|
}
|
|
|
|
j("#user-list li a.remove").live("click", function() {
|
|
var friend_id = j(this).prop('id');
|
|
|
|
friend_id = friend_id.split('-');
|
|
friend_id = friend_id[1];
|
|
|
|
j.post( ajaxurl, {
|
|
action: 'bp_dedication_add_user_ajax_handler',
|
|
'friend_action': 'remove',
|
|
'cookie': encodeURIComponent(document.cookie),
|
|
//'_wpnonce': j("input#_wpnonce_invite_uninvite_user").val(),
|
|
'friend_id': friend_id
|
|
},
|
|
function(response)
|
|
{
|
|
friendIDs = j('#friend_ids').val().split(',');
|
|
friendIDs.splice(j.inArray(friend_id, friendIDs),1);
|
|
j('#friend_ids').val(friendIDs.toString());
|
|
|
|
j('#user-list li#uid-' + friend_id).remove();
|
|
});
|
|
|
|
return false;
|
|
});
|
|
|
|
});
|
|
|
|
function ia_on_autocomplete_select( value, data ) {
|
|
var j = jQuery;
|
|
var friendIDs;
|
|
|
|
// Check the right checkbox
|
|
//j('#invite-anyone-member-list input#f-' + data).prop('checked',true);
|
|
|
|
//j('#dedicate_to_input').addClass('loading');
|
|
|
|
j.post( ajaxurl, {
|
|
action: 'bp_dedication_add_user_ajax_handler',
|
|
'friend_action': 'add',
|
|
'cookie': encodeURIComponent(document.cookie),
|
|
//'_wpnonce': j("input#_wpnonce_invite_uninvite_user").val(),
|
|
'friend_id': data
|
|
},
|
|
function(response)
|
|
{
|
|
friendIDs = j('#friend_ids').val().split(',');
|
|
friendIDs.push(data);
|
|
j('#friend_ids').val(friendIDs.toString());
|
|
|
|
/*j('#user-list').html('');
|
|
j('#user-list').append(response);*/
|
|
//j('#dedicate_to_input').removeClass('loading');
|
|
});
|
|
|
|
// Remove the value from the send-to-input box
|
|
// j('#dedicate_to_input').val('');
|
|
}
|
|
|