/* ------------------------------------------------------------------------------------------------------------
W E P E D E S
------------------------------------------------------------------------------------------------------------- */
var _WPE_CONTEXT=null;
var _WPE_HISTORY=[];
var _WPECONFIG={checkbox1:'S',checkbox0:''};
$(function(){
$.fn.oldVal = $.fn.val;
$.fn.setChecked = function(c){
var v=(c==undefined || c==_WPECONFIG.checkbox1 || c==true)? _WPECONFIG.checkbox1 : _WPECONFIG.checkbox0;
$(this).each(function(a,b){
if( $(this).eq(a).attr('valfunction')!=undefined ){
window[$(this).eq(a).attr('valfunction')]($(this).eq(a),v);
}else{
ret=$(this).oldVal();
}
});
return $(this);
};
$.fn.val = function(v){
if(arguments.length && $(this).length ){
if(typeof(v)=='function')v=v.apply(this,arguments);
$(this).each(function(a,b){
if( $(this).eq(a).attr('valfunction')!=undefined ){
window[$(this).eq(a).attr('valfunction')]($(this).eq(a),v);
}else{
ret=$(this).oldVal(v);
}
/*
var role=$(this).eq(a).attr('role');
//console.log("1 val("+v+") role: "+role);
switch(role){
case 'checkbox':
if(v*1){
$(this).eq(a).attr('aria-checked',0);
}else{
$(this).eq(a).attr('aria-checked',1);
}
$(this).eq(a).change();
break;
case 'radio':
if( $(this).eq(a).attr('valfunction')!=undefined ){
ret=window[$(this).eq(a).attr('valfunction')]($(this).eq(a),v);
}else{
$(this).eq(a).attr('value',v);
}
// if( $(this).find('md-radio-button[value='+v+']').length ){
// $(this).eq(a).attr('value',v);
// $(this).eq(a).change();
// }
break;
// case 'text':
// $(this).oldVal(v);
// _wpInputChanged(this);
// break;
default:
$(this).oldVal(v);
}
*/
});
return $(this);
}else{
var uno=($(this).length==1);
var ret=[];
$(this).each(function(a,b){
if(uno){
if( $(this).eq(a).attr('valfunction')!=undefined ){
ret=window[$(this).eq(a).attr('valfunction')]($(this).eq(a));
}else{
ret=$(this).oldVal();
}
}else{
if( $(this).eq(a).attr('valfunction')!=undefined ){
ret.push( window[$(this).eq(a).attr('valfunction')]($(this).eq(a)) );
}else{
ret.push($(this).oldVal());
//ret.push( $(this).eq(a).attr('value') );
}
}
})
return ret;
}
}
})
/*
$(function(){
$.fn.oldVal = $.fn.val;
$.fn.val = function(v){
//I'm assuming here that you're setting/getting a data value on the object to keep track of it's "custom value"
if(arguments.length && $(this).length ){
if(typeof(v)=='function')v=v.apply(this,arguments);
$(this).each(function(a,b){
var role=$(this).eq(a).attr('role');
//console.log("1 val("+v+") role: "+role);
switch(role){
case 'checkbox':
if(v*1){
$(this).eq(a).attr('aria-checked',0);
}else{
$(this).eq(a).attr('aria-checked',1);
}
$(this).eq(a).change();
break;
case 'radio':
if( $(this).eq(a).attr('valfunction')!=undefined ){
ret=window[$(this).eq(a).attr('valfunction')]($(this).eq(a),v);
}else{
$(this).eq(a).attr('value',v);
}
// if( $(this).find('md-radio-button[value='+v+']').length ){
// $(this).eq(a).attr('value',v);
// $(this).eq(a).change();
// }
break;
// case 'text':
// $(this).oldVal(v);
// _wpInputChanged(this);
// break;
default:
$(this).oldVal(v);
}
})
return $(this);
}else{
var uno=($(this).length==1);
var ret=[];
$(this).each(function(a,b){
var role=$(this).eq(a).attr('role');
//console.log("2 val("+v+") role: "+role);
switch(role){
case 'checkbox':
if(uno){
ret=$(this).eq(a).attr('aria-checked');
}else{
ret.push($(this).eq(a).attr('aria-checked'));
}
break;
case 'radio':
if(uno){
if( $(this).eq(a).attr('valfunction')!=undefined ){
ret=window[$(this).eq(a).attr('valfunction')]($(this).eq(a));
}else{
ret=$(this).eq(a).attr('value');
}
}else{
if( $(this).eq(a).attr('valfunction')!=undefined ){
ret.push( window[$(this).eq(a).attr('valfunction')]($(this).eq(a)) );
}else{
ret.push( $(this).eq(a).attr('value') );
}
}
break;
default:
if(uno){
ret=$(this).oldVal();
}else{
ret.push($(this).oldVal());
}
}
})
return ret;
}
}
})
*/
function wLng(id,context){
if( context!=undefined ){
return context._lngjs[id] || id;
}else{
return _WPE_CONTEXT._lngjs[id] || id;
}
}
function wUniqueId(prefix){
if(prefix==undefined)prefix='wp';
return prefix+Math.floor((1 + Math.random()) * 0x1000000000000).toString(16).substring(1);
}
function wPF(ids,val,chg,context){
if(chg==undefined)chg=true;
ids=ids.replace(/\s/g, '');
if(ids.indexOf(',')!=-1){
ids=ids.split(',');
}else{
ids=[ids];
}
var err=[];
for(var x in ids){
var id=ids[x];
if(context!=undefined){
var contexto=$(context.__Container);
}else{
if( $(_WPE_CONTEXT.__Container).find('#'+id).length ){
var contexto=$(_WPE_CONTEXT.__Container);
}else{
err.push('No se ha encontrado el campo '+id);
continue;
}
}
if(chg){
contexto.find('#'+id).val(val).change();
}else{
contexto.find('#'+id).val(val);
}
}
if(err.length){
alert(err.join('
'));
}
}
function wPPF(id,val,chg,context){
if(context==undefined){
wPF(id,val,chg,_WOPENER);
}else{
wPF(id,val,chg,context);
}
}
function wGF(id,context){
if( context!=undefined ){
return $(context.__Container).find('#'+id).val();
}else{
return $(_WPE_CONTEXT.__Container).find('#'+id).val();
}
}
function wPGF(id,context){
if( context!=undefined ){
return $(context.__Container).find('#'+id).val();
}else{
return $(_WOPENER).find('#'+id).val();
}
}
function wGFPlain(id){
//only for H type controls
}
function wGO(id,context){
if(context!=undefined){return $(context.__Container).find('#'+id);}else{return $(_WPE_CONTEXT.__Container).find('#'+id);}
}
// getLabel
function wGL(id,context){
if( context!=undefined ){
return $(context.__Container).find('label[for='+id+']').text();
}else{
return $(_WPE_CONTEXT.__Container).find('label[for='+id+']').text();
}
}
function wHide(id,context){
if(id.indexOf(',')>-1){
var a=id.split(',');
}else{
var a=new Array(id);
}
for(id in a){
if( context!=undefined ){
$(context.__Container).find('#'+a[id]).closest('div').hide();
$(context.__Container).find('label[for='+a[id]+']').hide();
}else{
$(_WPE_CONTEXT.__Container).find('#'+a[id]).closest('div').hide();
$(_WPE_CONTEXT.__Container).find('label[for='+a[id]+']').hide();
}
}
}
function wShow(id,context){
if(id.indexOf(',')>-1){
var a=id.split(',');
}else{
var a=new Array(id);
}
for(id in a){
if( context!=undefined ){
$(context.__Container).find('#'+a[id]).closest('div').show();
$(context.__Container).find('label[for='+a[id]+']').show();
}else{
$(_WPE_CONTEXT.__Container).find('#'+a[id]).closest('div').show();
$(_WPE_CONTEXT.__Container).find('label[for='+a[id]+']').show();
}
}
}
function wEF(id,flg,context){
if(id.indexOf(',')>-1){
var a=id.split(',');
}else{
var a=new Array(id);
}
for(id in a){
if( context!=undefined ){
$(context.__Container).find('#'+a[id]).attr('readonly',!flg);
}else{
$(_WPE_CONTEXT.__Container).find('#'+a[id]).attr('readonly',!flg);
}
}
}
//ret false=error
function wPE(id,error,context){
//if(!Array.isArray(id))){}
if(typeof(id)=="object"){
id=$(id).attr('id');
}
if( context!=undefined ){
if(error==null||error==''){
context._jsCheckError =false;
}else{
context._jsCheckError =true;
context._fieldsWithError[id]=id;
}
}else{
if(error==null||error==''){
_WPE_CONTEXT._jsCheckError =false;
}else{
_WPE_CONTEXT._jsCheckError =true;
_WPE_CONTEXT._fieldsWithError[id]=id;
}
}
if(error==null||error==''){
window[wpControlsType+'_ePE'](id,null);
}else{
window[wpControlsType+'_ePE'](id,error);
if(window['wpFocus_'+id]!=undefined){
window['wpFocus_'+id]();
}else{
$('#'+id).focus();
}
}
}
var wpeErrorDefaults = {
alerts : true,
classes : {
container: 'wpeFldCont',
item : 'wpeFldErr',
alert : 'wpealert',
bad : 'wpebad'
}
};
function _eFieldError(field,text){
if(typeof(field)=="string")field=$('#'+field);
//if(!text||!field)return false;
field=$(field);
field.attr('aria-has-error',1).attr('aria-error-desc',text);
validator.mark(field,text);
}
function _eFieldErrorClear(field){
if(typeof(field)=="string")field=$('#'+field);
field=$(field);
field.attr('aria-has-error',0).attr('aria-error-desc','');
validator.unmark(field);
return;
if(typeof(id)=="object"){
id.removeClass(defaults.classes.bad);
$(id).attr('aria-has-error',0).attr('aria-error-desc','');
id=$(id).attr('id');
}else{
var field=$('#'+id);
field.removeClass(defaults.classes.bad).attr('aria-has-error',0).attr('aria-error-desc','');
}
$('.wpealert[for='+field.attr('id')+']').remove();
}
function wCallSrvDownload(tag, params, getpost ){
var script=_WPE_CONTEXT._Source;
if(tag==undefined || tag=='')return false;
if(params==undefined)params=null;
if(getpost==undefined||getpost==null)getpost='POST';
params=JSON.stringify(params);
jQuery('
').appendTo('body').submit().remove();
}
function wCallSrv(tag, params, callBackFun, getpost, responseDataType ){
var script=_WPE_CONTEXT._Source;
if(tag==undefined || tag=='')return false;
if(params==undefined)params=null;
if(getpost==undefined||getpost==null)getpost='POST';
if(responseDataType==undefined||responseDataType==null)responseDataType='html';
(function(params,callBackFun) {
var r='';
$.ajax({
url:CMD,
cache:false,
async:false,
type:getpost,
data:{cmd:'wpedes',script:script,mode:'Y',tag:tag,params:JSON.stringify(params)},
dataType:responseDataType
})
.done(function(ret){
r=ret;
})
.fail(function(jqXHR,textStatus,errorThrown){
});
callBackFun(r);
}(params,callBackFun));
}
var wpeModal=null;
function wLoadOnModal(obj,script, mode, params, data){
wpeLoadOnModal(obj,script, mode, params, data);
}
function wpeLoadOnModal(obj,script, mode, params, data){
wpeModal={};
wpeModal.modal=new geModal();
var $win=wpeModal.modal.new({keyboard: false});
if(params==undefined) params={};
var id=wpeModal.modal.id
params._wpeContainer=id;
params._iamModal=true;
wpeModal._WOPENER=_WPE_CONTEXT;
_WPE_HISTORY.push({
id:id,
obj:obj,
script:script,
mode:mode,
params:params,
data:data,
wpeModal:wpeModal,
_WOPENER:_WPE_CONTEXT
});
params._WPE_HISTORY=id;
$.ajax({
url:CMD,
cache:false,
async:false,
type:"POST",
data:{cmd:'wpedes',script:script,mode:mode,params:JSON.stringify(params),data:JSON.stringify(data)},
dataType:"html"
})
.done(function(ret){
$win.html(ret);
$win.addClass('modal-dialog modal-lg');
$win.unbind('shown.bs.modal').on('shown.bs.modal',function(e){
_WOPENER=wpeModal._WOPENER;
wpeModal.modal.expandH(true);
setTimeout('wpeModal.modal.expandH(true);',500);
});
wpeModal.modal.show();
// wpeModal.modal.expandH(true);
})
.fail(function(jqXHR,textStatus,errorThrown){
alert("ERROR LOADING FORM");
});
}
function wLoadOnParent(obj,script, mode, params){
wpeLoadOnParent(obj,script, mode, params);
}
function wpeLoadOnParent(obj,script, mode, params){
if(params==undefined)params=null;
var $container=$(obj).closest('[WPEDES-CONTAINER]');
wpeLoadOn($container,script, mode, params);
}
// *************************************************************************************************************************
function wLoadOn(obj, script, mode, params,data){
wpeLoadOn(obj, script, mode, params,data);
}
function wpeLoadOn(obj, script, mode, params,data){
$(obj).attr('WPEDES-CONTAINER','');
//$(obj).expandh();
if(params==undefined)params={};
if(data==undefined)data={};
if( $(obj).attr('id')==undefined ) $(obj).attr('id','_wpeContainer');
//se pasa siempre el contenedor principal
params._wpeContainer=$(obj).attr('id');
params.wpscript=script;
var id=wUniqueId();
_WPE_HISTORY.push({
id:id,
obj:obj,
script:script,
mode:mode,
params:params,
data:data
});
params._WPE_HISTORY=id;
(function(obj) {
var r='';
$.ajax({url:CMD,cache:false,async:false,type:"POST",dataType:"html",data:{cmd:'wpedes',script:script,mode:mode,params:JSON.stringify(params),data:JSON.stringify(data)}})
.done(function(ret){
r=ret;
})
.fail(function(jqXHR,textStatus,errorThrown){
alert("ERROR LOADING FORM");
});
$(obj).html(r);
}(obj));
}
// *************************************************************************************************************************
function wHistoryBack(_wpe_history,refresh){
wpeHistoryBack(_wpe_history,refresh);
}
function wpeHistoryBack(_wpe_history,refresh){
if(_wpe_history!=undefined){
var l=_WPE_HISTORY.length-1;
for(var x=l;x>-1;x--){
if( _WPE_HISTORY[x].id==_wpe_history ){
var padre=_WPE_HISTORY[x].params._WPE_HISTORY_PARENT;
_WPE_HISTORY[x].wpeModal.modal.close(event,false);
_WPE_HISTORY.splice(x, 1);
if( refresh!=false ){
var l=_WPE_HISTORY.length-1;
for(var xp=l;xp>-1;xp--){
if( _WPE_HISTORY[xp].id==padre ){
wpeLoadOn(_WPE_HISTORY[xp].obj, _WPE_HISTORY[xp].script, _WPE_HISTORY[xp].mode, _WPE_HISTORY[xp].params, _WPE_HISTORY[xp].data);
_WPE_HISTORY.splice(xp, 1);
break;
}
}
}
return;
}
}
}
var h=_WPE_HISTORY.pop();
// h=_WPE_HISTORY.pop();
if(h==undefined){
$('#'+_wpe_history).html('');
alert(__validator.message.completed);
}else{
if( refresh!=false ) wpeLoadOn(h.obj, h.script, h.mode, h.params);
}
}
// *************************************************************************************************************************
/*
Validator v1.1.0
(c) Yair Even Or
https://github.com/yairEO/validator
MIT-style license.
*/
var __validator = (function($){
var message, tests, checkField, validate, mark, unmark, field, minmax, defaults,
validateWords, lengthRange, lengthLimit, pattern, alertTxt, data,
email_illegalChars = /[\(\)\<\>\,\;\:\\\/\"\[\]]/,
email_filter = /^.+@.+\..{2,6}$/; // exmaple email "steve@s-i.photo"
// general text messages
message={invalid:'invalid input',empty:'please put something here',min:'input is too short',max:'input is too long',number_min:'too low',number_max:'too high',url:'invalid URL',number:'not a number',email:'email address is invalid',email_repeat:'emails do not match',password_repeat:'passwords do not match',repeat:'no match',complete:'input is not complete',select:'Please select an option',completed:'OPERATION COMPLETED'};
if(!window.console){
console={};
console.log=console.warn=function(){ return; }
}
// defaults
defaults = {
alerts : true,
classes : {
container: 'wpeFldCont',
item : 'wpeFldErr',
alert : 'wpealert',
bad : 'wpebad'
}
};
// Tests for each type of field (including Select element)
tests = {
sameAsPlaceholder : function(a){
return $.fn.placeholder && a.attr('placeholder') !== undefined && data.val == a.prop('placeholder');
},
hasValue : function(a){
if( !a ){
alertTxt = message.empty;
return false;
}
return true;
},
// 'linked' is a special test case for inputs which their values should be equal to each other (ex. confirm email or retype password)
linked : function(a,b){
if( b != a ){
// choose a specific message or a general one
alertTxt = message[data.type + '_repeat'] || message.no_match;
return false;
}
return true;
},
email : function(a){
if ( !email_filter.test( a ) || a.match( email_illegalChars ) ){
alertTxt = a ? message.email : message.empty;
return false;
}
return true;
},
// a "skip" will skip some of the tests (needed for keydown validation)
text : function(a, skip){
// make sure there are at least X number of words, each at least 2 chars long.
// for example 'john F kenedy' should be at least 2 words and will pass validation
if( validateWords ){
var words = a.split(' ');
// iterrate on all the words
var wordsLength = function(len){
for( var w = words.length; w--; )
if( words[w].length < len )
return false;
return true;
};
if( words.length < validateWords || !wordsLength(2) ){
alertTxt = message.complete;
return false;
}
return true;
}
if( !skip && lengthRange && a.length < lengthRange[0] ){
alertTxt = message.min;
return false;
}
// check if there is max length & field length is greater than the allowed
if( lengthRange && lengthRange[1] && a.length > lengthRange[1] ){
alertTxt = message.max;
return false;
}
// check if the field's value should obey any length limits, and if so, make sure the length of the value is as specified
if( lengthLimit && lengthLimit.length ){
while( lengthLimit.length ){
if( lengthLimit.pop() == a.length ){
alertTxt = message.complete;
return false;
}
}
}
if( pattern ){
var regex, jsRegex;
switch( pattern ){
case 'alphanumeric' :
regex = /^[a-z0-9]+$/i;
break;
case 'numeric' :
regex = /^[0-9]+$/i;
break;
case 'phone' :
regex = /^\+?([0-9]|[-|' '])+$/i;
break;
default :
regex = pattern;
}
try{
jsRegex = new RegExp(regex).test(a);
if( a && !jsRegex )
return false;
}
catch(err){
console.log(err, field, 'regex is invalid');
return false;
}
}
return true;
},
number : function(a){
// if not not a number
if( isNaN(parseFloat(a)) && !isFinite(a) ){
alertTxt = message.number;
return false;
}
// not enough numbers
else if( lengthRange && a.length < lengthRange[0] ){
alertTxt = message.min;
return false;
}
// check if there is max length & field length is greater than the allowed
else if( lengthRange && lengthRange[1] && a.length > lengthRange[1] ){
alertTxt = message.max;
return false;
}
else if( minmax[0] && (a|0) < minmax[0] ){
alertTxt = message.number_min;
return false;
}
else if( minmax[1] && (a|0) > minmax[1] ){
alertTxt = message.number_max;
return false;
}
return true;
},
// Date is validated in European format (day,month,year)
date : function(a){
var day, A = a.split(/[-./]/g), i;
// if there is native HTML5 support:
if( field[0].valueAsNumber )
return true;
for( i = A.length; i--; ){
if( isNaN(parseFloat(a)) && !isFinite(a) )
return false;
}
try{
day = new Date(A[2], A[1]-1, A[0]);
if( day.getMonth()+1 == A[1] && day.getDate() == A[0] )
return day;
return false;
}
catch(er){
console.log('date test: ', err);
return false;
}
},
url : function(a){
// minimalistic URL validation
function testUrl(url){
return /^(https?:\/\/)?([\w\d\-_]+\.+[A-Za-z]{2,})+\/?/.test( url );
}
if( !testUrl( a ) ){
alertTxt = a ? message.url : message.empty;
return false;
}
return true;
},
hidden : function(a){
if( lengthRange && a.length < lengthRange[0] ){
alertTxt = message.min;
return false;
}
if( pattern ){
var regex;
if( pattern == 'alphanumeric' ){
regex = /^[a-z0-9]+$/i;
if( !regex.test(a) ){
return false;
}
}
}
return true;
},
select : function(a){
if( !tests.hasValue(a) ){
alertTxt = message.select;
return false;
}
return true;
}
};
// marks invalid fields
mark = function( field, text ){
if(!text||!field) return false;
if( field.hasClass(defaults.classes.bad) ){
if( defaults.alerts ){
console.log('aaaaaa '+field.attr('id') );
$('.wpealert[for='+field.attr('id')+'] i').attr('title',text);
}
}else if( defaults.alerts ){
console.log('bbbbbbb '+field.attr('id') );
var warning = $('').html( "
" );
$('wp-error-icn[for='+field.attr('id')+']').html(warning);
//field.after( warning );
}
field.removeClass(defaults.classes.bad);
setTimeout(function(){
field.addClass(defaults.classes.bad);
}, 0);
};
// un-marks invalid fields
unmark = function( field ){
field.removeClass(defaults.classes.bad);
$('.wpealert[for='+field.attr('id')+']').remove();
};
function testByType(type, value){
if( type == 'tel' ) pattern = pattern || 'phone';
if( !type || type == 'password' || type == 'tel' || type == 'search' || type == 'file' ) type = 'text';
return tests[type] ? tests[type](value, true) : true;
}
function prepareFieldData(el){
field = $(el);
field.data( 'valid', true ); // initialize validity of field
field.data( 'type', field.attr('type') ); // every field starts as 'valid=true' until proven otherwise
pattern = field.attr('pattern');
}
// Validations per-character keypress
function keypress(e){
prepareFieldData(this);
// String.fromCharCode(e.charCode)
if( e.charCode ){
return testByType( this.type, this.value );
}
}
function checkField(){
//debugger;
// if( this.type !='hidden' && $(this).is(':hidden') ) return true; //saltar campos cuyo tipo no es hidden pero están ocultos por css
prepareFieldData(this);
field.data( 'val', field[0].value.replace(/^\s+|\s+$/g, "") ); // cache the value of the field and trim it
data = field.data();
// Check if there is a specific error message for that field, if not, use the default 'invalid' message
alertTxt = message[field.prop('name')] || message.invalid;
if( field[0].nodeName.toLowerCase() === "select" ){
data.type = 'select';
}
if( field[0].nodeName.toLowerCase() === "textarea" ){
data.type = 'text';
}
validateWords = data['validateWords'] || 0;
lengthRange = data['validateLengthRange'] ? (data['validateLengthRange']+'').split(',') : [1];
lengthLimit = data['validateLength'] ? (data['validateLength']+'').split(',') : false;
minmax = data['validateMinmax'] ? (data['validateMinmax']+'').split(',') : ''; // for type 'number', defines the minimum and/or maximum for the value as a number.
data.valid = tests.hasValue(data.val);
if( field.hasClass('optional') && !data.valid )
data.valid = true;
if( data.valid ){
if( tests.sameAsPlaceholder(field) ){
alertTxt = message.empty;
data.valid = false;
}
if( data.validateLinked ){
var linkedTo = data['validateLinked'].indexOf('#') == 0 ? $(data['validateLinked']) : $(':input[name=' + data['validateLinked'] + ']');
data.valid = tests.linked( data.val, linkedTo.val() );
}
else if( data.valid || data.type == 'select' )
data.valid = testByType(data.type, data.val);
}
if( data.valid )
unmark( field );
else{
mark( field, alertTxt );
submit = false;
}
return data.valid;
}
function checkAll( $form ){
$form = $($form);
if( $form.length == 0 ){
console.warn('element not found');
return false;
}
var that = this,
submit = true,
fieldsToCheck = $form.find(':input').filter('[required=required], .required, .optional').not('[disabled=disabled]');
fieldsToCheck.each(function(){
submit = submit * checkField.apply(this);
});
return !!submit;
}
return {
defaults : defaults,
checkField : checkField,
keypress : keypress,
checkAll : checkAll,
mark : mark,
unmark : unmark,
message : message,
tests : tests
}
})(jQuery);
// *************************************************************************************************************************
// http://lions-mark.com/jquery/scrollTo/
// //$('body').animate( {scrollTop: $('.voError').first().offset().top},3000 )
$.fn.scrollTo = function( target, options, callback ){
if(typeof options == 'function' && arguments.length == 2){ callback = options; options = target; }
var settings = $.extend({
scrollTarget : target,
offsetTop : 3,
duration : 1000,
easing : 'easeOutExpo' //'swing'
}, options);
return this.each(function(){
var scrollPane=$(this);var scrollTarget=(typeof(settings.scrollTarget)=="number")? settings.scrollTarget : $(settings.scrollTarget);if(!scrollTarget.length)return;
//var scrollY = (typeof scrollTarget == "number") ? scrollTarget : scrollTarget.offset().top + scrollPane.scrollTop() - parseInt(settings.offsetTop);
var scrollY=(typeof(scrollTarget)=="number")? scrollTarget : scrollTarget.offset().top - scrollPane.offset().top + scrollPane.scrollTop() - parseInt(settings.offsetTop);
scrollPane.animate({scrollTop:scrollY},parseInt(settings.duration),settings.easing,function(){
if (typeof callback=='function'){callback.call(this);}
});
});
}
// Subselect
// wSelectLoad( Field [, DependeDe [, Sql [, PutValor [, NmFunction ]]]] )
function wSelectLoad(_Source,data){
data=JSON.stringify(data);
$.ajax({
url:CMD,
cache:false,
async:false,
type:"POST",
data:{cmd:'wpedes',script:_Source,mode:'Ss',data:data},
dataType:"html"
})
.fail(function(jqXHR,textStatus,errorThrown){
alert("ERROR: eSelectLoad");
})
.done(function(ret){
eval(ret);
});
}
function wSelectValue(id,context){
if( context!=undefined ){
if( $(context.__Container).find('#'+id)[0].tagName=='INPUT' )
return $(context.__Container).find('#'+id)[0].value;
if( $(context.__Container).find('#'+id)[0].tagName=='SELECT' )
return $(context.__Container).find('#'+id).find('option[value="'+wGF(id)+'"]').text();
}else{
if( $(_WPE_CONTEXT.__Container).find('#'+id)[0].tagName=='INPUT' )
return $(_WPE_CONTEXT.__Container).find('#'+id)[0].value;
if( $(_WPE_CONTEXT.__Container).find('#'+id)[0].tagName=='SELECT' )
return $(_WPE_CONTEXT.__Container).find('#'+id).find('option[value="'+wGF(id)+'"]').text();
}
}
// **********************************************************************************
function wModal(){
return geModal();
}
function geModal(){
return {
id0:null,
id:null,
$element:null,
zindex:0,
//sav_WPE_CONTEXT:_WPE_CONTEXT,
new:function(){
this.id=wUniqueId('wpModal');
this.id0=this.id+'_0';
var z=this.getZIndex();
this.zindex=z;
var bh=$('body').outerHeight();
var wh=$(window).height()-1;
bh=(bh
');
$('body').append($modal);
this.$element=$('#'+this.id);
return $('#'+this.id);
},
show:function(){
var me=this;
var e=$.Event('show.bs.modal', { relatedTarget: this }); // relatedTarget -> geModal
this.$element.trigger(e);
if( this.$element.outerHeight() > $('body').outerHeight()-150 ){
this.expandH();
}
this.$element.on('click.dismiss.bs.modal', '[data-dismiss="modal"]', $.proxy(this.close, this));
$('#'+this.id+'_tapa').on('click', $.proxy(this.close, this));
// this.$element.find('button[type=submit]').click( $.proxy(function(){
// debugger;
// this.$element.find('form').submit();
// }, this) );
this.center();
$('#'+this.id0).fadeIn(195);
$('#'+this.id).effect('slide',{'direction':'up'}, 200, $.proxy(function(){
var e=$.Event('shown.bs.modal', { relatedTarget: this }); // relatedTarget -> geModal
this.$element.trigger(e);
//this.$element.on('keydown.dismiss.bs.modal', $.proxy(function (e) {
//this.$element.on('keypress', $.proxy(function (e) {
// debugger;
// e.which == 27 && this.close()
//}, this));
},this));
},
center:function(padre){
padre=padre||'body';
$('#'+this.id).css('left', ($(padre).width()-$('#'+this.id).width())/2 );
},
hide:function(){
var e=$.Event('hide.bs.modal',{relatedTarget:this});
this.$element.trigger(e);
$('#'+this.id0).fadeOut(200, $.proxy(function(){
var e=$.Event('hidden.bs.modal',{relatedTarget:this}); // relatedTarget -> geModal
this.$element.trigger(e);
},this));
},
close:function(event,deleteHistory){
deleteHistory=(deleteHistory==undefined)?true:deleteHistory;
var e=$.Event('close.bs.modal',{relatedTarget:this});
this.$element.trigger(e);
$('#'+this.id).effect('drop',{'direction':'up'}, 200, $.proxy(function(){
this.$element.off();
$('#'+this.id+'_tapa').off();
$('#'+this.id0).remove();
var e=$.Event('closed.bs.modal',{relatedTarget:this});
this.$element.trigger(e);
},this));
if(deleteHistory){
if(this.id==_WPE_HISTORY[_WPE_HISTORY.length-1].id)
_WPE_HISTORY.pop();
if(_WPE_HISTORY.length)
_WPE_CONTEXT=_WPE_HISTORY[_WPE_HISTORY.length-1]._WPE_CONTEXT;
}else{
if(_WPE_HISTORY.length)
_WPE_CONTEXT=_WPE_HISTORY[_WPE_HISTORY.length-2]._WPE_CONTEXT;
}
_WOPENER=_WPE_CONTEXT._WOPENER;
},
getZIndex:function(){
var z=0;
$('.geModal').each(function(){
var z0=$(this).css('z-index')*1;if(z0>z)z=z0;
});
return 10000+z+1;
},
expandH:function(sihacefalta){
if(sihacefalta==true){
//if( this.$element.outerHeight() < $('body').outerHeight()-150 ) return;
if( this.$element.outerHeight() < $(window).outerHeight()-150 ) return;
}
if(this.$element.find('.modal-body').length){
this.$element.find('.modal-body').css('overflow','auto');
var mh=this.$element.find('.modal-header').outerHeight();
var mf=this.$element.find('.modal-footer').outerHeight();
var bo=$(window).outerHeight()- $('#'+this.id).position().top; //var bo=$('body').outerHeight()- $('#'+this.id).position().top;
var mb=bo - mh - mf;
this.$element.find('.modal-body').css('height',mb-60);
}else if( this.$element.find('.panel-body').length ){
this.$element.find('.panel-body').css('overflow','auto');
var mh=this.$element.find('.panel-heading').outerHeight();
var mf=this.$element.find('.panel-footer').outerHeight();
var bo=$(window).outerHeight()- $('#'+this.id).position().top; //var bo=$('body').outerHeight()- $('#'+this.id).position().top;
var mb=bo - mh - mf;
this.$element.find('.panel-body').css('height',mb-60);
}
},
setHeight:function(h){
this.$element.css('height',h);
},
setBodyHeight:function(h){
this.$element.find('.modal-body').css('height',h);
}
}
}
var KC={DELETE:8,SUPR:46,INSERT:45,LEFT:37,RIGHT:39,UP:38,DOWN:40,TAB:9,ENTER:13,AVPAG:34,REPAG:33,START:36,END:35,SHIFT:16,BSHIFT:20,ALT:18,CTRL:17};
var KF={F1:112,F2:113,F3:114,F4:115,F5:116,F6:117,F7:118,F8:119,F9:120,F10:121,F11:122,F12:123};
var KCF=[KC.DELETE,KC.SUPR,KC.INSERT,KC.LEFT,KC.RIGHT,KC.UP,KC.DOWN,KC.TAB,KC.ENTER,KC.AVPAG,KC.REPAG,KC.START,KC.END,KC.SHIFT,KC.BSHIFT,KC.ALT,KC.CTRL];
var KFF=[KF.F1,KF.F2,KF.F3,KF.F4,KF.F5,KF.F6,KF.F7,KF.F8,KF.F9,KF.F10,KF.F11,KF.F12];
_WPKC=KCF.join(KFF);
function _wpRoleKeydown(o){
//console.log(window.event.keyCode);
var v10=$(o).attr('aria-v10');if(v10==undefined||v10=='')return true;
if(event.ctrlKey || KCF.indexOf(window.event.keyCode)!=-1)return true;
var re=new RegExp(v10);if(!re.test(window.event.key))event.preventDefault();
}
function _wpRoleChange(o){
if($(o).val()=='')return;
var v20=$(o).attr('aria-v20');
if(v20!=undefined&&v20!='')window[v20](o);
var v30=$(o).attr('aria-v30');
if(v30!=undefined&&v30!=''){
if(v30.substr(-1)==')'){
var ret=window[v30];
}else{
var re=new RegExp(v30);
var ret=re.test($(o).val());
}
if(!ret){
wPE(o,$(o).attr('aria-error')||'ERROR' );
}else{
wPE(o,null);
}
}
}
function _wpSetError(o,s){
//debugger;
// $(o).attr('aria-has-error',1).attr('aria-error-desc',s);
// validator.mark($(o),s);
}
var WP={
checkForm:function($form){
$form=$($form);
if(!$form.length)return false;
var haserr=false,ftc=$form.find('.wp-form-control').not('[disabled=disabled]').not('.optional');
ftc.each(function(){
haserr=haserr||WP.fieldHasError.apply(this);
});
return haserr;
},
fieldHasError:function(o){
$(this).change();
// if( $(this).attr('aria-has-error')!=1 ){
if( $(this).attr('required')!=undefined && $(this).val()==''){
$(this).attr('aria-has-error',1);
wPE( $(this),__validator.message.required);
var wpGDFTab = '#wpGDFTab_'+$('#'+$(this).attr('id')).closest('.tab-pane').attr('id');
if($(wpGDFTab).length)$(wpGDFTab).click();
}else{
wPE( $(this),null);
}
// }
return $(this).attr('aria-has-error')==1;
},
date:function(a,b){var c,d,e=["Sun","Mon","Tues","Wednes","Thurs","Fri","Satur","January","February","March","April","May","June","July","August","September","October","November","December"],f=/\\?(.?)/gi,g=function(a,b){return d[a]?d[a]():b},h=function(a,b){for(a=String(a);a.length9?-1:0)},Y:function(){return c.getFullYear()},y:function(){return d.Y().toString().slice(-2)},a:function(){return c.getHours()>11?"pm":"am"},A:function(){return d.a().toUpperCase()},B:function(){var a=3600*c.getUTCHours(),b=60*c.getUTCMinutes(),d=c.getUTCSeconds();return h(Math.floor((a+b+d+3600)/86.4)%1e3,3)},g:function(){return d.G()%12||12},G:function(){return c.getHours()},h:function(){return h(d.g(),2)},H:function(){return h(d.G(),2)},i:function(){return h(c.getMinutes(),2)},s:function(){return h(c.getSeconds(),2)},u:function(){return h(1e3*c.getMilliseconds(),6)},e:function(){var a="Not supported (see source code of date() for timezone on how to add support)";throw new Error(a)},I:function(){var a=new Date(d.Y(),0),b=Date.UTC(d.Y(),0),c=new Date(d.Y(),6),e=Date.UTC(d.Y(),6);return a-b!==c-e?1:0},O:function(){var a=c.getTimezoneOffset(),b=Math.abs(a);return(a>0?"-":"+")+h(100*Math.floor(b/60)+b%60,4)},P:function(){var a=d.O();return a.substr(0,3)+":"+a.substr(3,2)},T:function(){return"UTC"},Z:function(){return 60*-c.getTimezoneOffset()},c:function(){return"Y-m-d\\TH:i:sP".replace(f,g)},r:function(){return"D, d M Y H:i:s O".replace(f,g)},U:function(){return c/1e3|0}};var i=function(a,b){return c=void 0===b?new Date:b instanceof Date?new Date(b):new Date(1e3*b),a.replace(f,g)};return i(a,b)}
}
function _wpRoleF4_v10(o){
if($(o).attr('aria-v10')==undefined)return true;
var v10=$(o).attr('aria-v10');
if(v10.substr(-1)==')'){
if( !window[v10.substr(0,v10.indexOf('('))](o)){
event.preventDefault(); return false;
}
}
if(KCF.indexOf(window.event.keyCode)!=-1)return true;
var re=new RegExp(v10);
if( !re.test(window.event.key) )event.preventDefault();
}
function _wpRoleF4_v20(o){
var err=false;
$(o).attr('aria-has-error',0).attr('aria-error-desc','');
wPE(o,null);
if($(o).attr('aria-v20')!=undefined){
window[$(o).attr('aria-v20')](o);
}
var v=$(o).val();
if($(o).attr('aria-min')!=undefined){
if(v<$(o).attr('aria-min')){
err=true;
wPE(o, $(o).attr('aria-min-error')||'Errorrr-min' );
return;
}
}
if($(o).attr('aria-max')!=undefined){
if(v>$(o).attr('aria-max')){
err=true;
wPE(o, $(o).attr('aria-max-error')||'Errorrr-max' );
return;
}
}
if( v!='' && $(o).attr('aria-v30')!=undefined ){
var v30=$(o).attr('aria-v30');
if(v30.substr(-1)==')'){
var ret=window[v30];
}else{
var re=new RegExp(v30);
var ret=re.test($(o).val());
}
if(!ret){
wPE(o, $(o).attr('aria-error')||'ERROR' );
}
}
}
function _wpF4ValBefore(o){
return;
var v=$(o).val();
var vl=v.length;
if( v.length==1 ){
v='0'+v;
$(o).val( WP.date(v+'-m-Y') );
return;
}
var c='';
if(v.indexof('-')!=-1)var c='-';
if(v.indexof('/')!=-1)var c='/';
if(c!=''){
var a=v.split(c);
}else{
var a=new Array(v);
}
}
//------------------------------------------------------------------------------------------------------------
function wConfirm(text,ops){
ge_confirm(text,ops);
}
function ge_confirm(text,ops){
if(!$('#modalConfirm').length){
$('body').append('');
}
if( ops.defaultButton==undefined || ops.defaultButton=='ok' ){
ops.defaultButton='#modalConfirm_ok';
$('#modalConfirm_ok').removeClass('btn-default').addClass('btn-primary');
$('#modalConfirm_cncl').removeClass('btn-primary').addClass('btn-default');
}else if(ops.defaultButton=='cancel'){
ops.defaultButton='#modalConfirm_cncl';
$('#modalConfirm_cncl').removeClass('btn-default').addClass('btn-primary');
$('#modalConfirm_ok').removeClass('btn-primary').addClass('btn-default');
}
$("#modalConfirm_title").html( (ops.title==undefined)?'':ops.title );
$("#modalConfirm_text").html(text);
if(ops.okbutton==undefined) ops.okbutton=wLng('ok');
ops.okbutton=(ops.okbutton==''||ops.okbutton==null)? '':ops.okbutton;
$("#modalConfirm_ok").html(ops.okbutton);
if(ops.cnclbutton==undefined)ops.cnclbutton=wLng('cancel');
ops.cnclbutton=(ops.cnclbutton==''||ops.cnclbutton==null)? '':ops.cnclbutton;
$("#modalConfirm_cncl").html(ops.cnclbutton);
$("#modalConfirm_ok").unbind('click');
if(ops.okCallback!=''&&ops.okCallback!=null)
$("#modalConfirm_ok").click(function(){ ops.okCallback(); });
$("#modalConfirm_cncl").unbind('click');
if(ops.cnclCallback!=''&&ops.cnclCallback!=null)
$("#modalConfirm_cncl").click(function(){ ops.cnclCallback(); });
$('#modalConfirm').modal('show').on('shown.bs.modal', function (e) {
$(ops.defaultButton).focus();
})
}
//---------------------------------------------------------------------------------------------------
//function wpAlert(tit,msg,callBackFuncionOnClose){
// alert(tit,msg,callBackFuncionOnClose);
//}
//---------------------------------------------------------------------------------------------------
// prototipado del alert
(function() {
window.alert = function(msg,tit,callBackFuncionOnClose) {
if(!$('#wp_eAlert').length){
var close=('cerrar'=='')? 'close': 'cerrar';
$('body').append('');
}
tit=(tit==''||tit==undefined)? 'INFO':tit;
$('#wp_eAlert_title').html(tit);
$('#wp_eAlert_body').html(msg);
$('#wp_eAlert_CloseButton').unbind('click');
if( typeof(callBackFuncionOnClose)=='function' ){
$('#wp_eAlert_CloseButton').on('click',function(){
callBackFuncionOnClose();
});
}else if(typeof(callBackFuncionOnClose)=='string'){
$('#wp_eAlert_CloseButton').on('click',function(){
eval(callBackFuncionOnClose);
});
}
$('#wp_eAlert').modal({show:true});
};
})();
function wAlertClose(){
$('#wp_eAlert').modal('hide');
}
//---------------------------------------------------------------------------------------------------
// Eliminar elemento/s de un array, bien por clave/s, bien por indice/s
Object.defineProperty(Array.prototype, 'remove', {
enumerable: false,
value: function(que,byindex) {
if(byindex==undefined){
if( que instanceof Array ){
for(var x in que){
try{this.splice( this.indexOf(que[x]),1);}catch(e){}
}
}else{
try{this.splice( this.indexOf(que),1);}catch(e){}
}
}else{
if(typeof(que)=="array"){
var cta=que.length;
while(cta>0){
try{this.splice(que[cta-1],1);}catch(e){}
cta--;
}
}else{
try{this.splice(que,1);}catch(e){}
}
}
}
});
//---------------------------------------------------------------------------------------------------
function wAddOption(f,a,context){
if(typeof(a)=="string"){
var b=a.split(';');var a=new Array();var z='';
for(var x in b){z=b[x].split('|');a[z[0]]=z[1]||'';}
}
for(var x in a){
var attr=''.split('');
if(a[x].length==1)a[x][1]=a[x][0];
for(var y in a[x]){
if(y==1)continue;
if(y==0){ attr.push('value="'+a[x][y]+'"');continue; }
attr.push('data-attr-'+y+'="'+a[x][y]+'"');
}
attr=attr.join(' ',attr);
wGO(f,context).closest('wp-input-container').find('wp-select-container').append(''+a[x][1]+'');
}
_wpRemountClickSV(f);
}
function wClearSelect(id,change,context){
wGO(id,context).closest('wp-input-container').find('wp-select-container').html('');
if(context!=undefined){
var contexto=$(context.__Container);
}else{
if( $(_WPE_CONTEXT.__Container).find('#'+id).length ){
var contexto=$(_WPE_CONTEXT.__Container);
}
}
contexto.find('#'+id).attr('bal','');
contexto.find('#'+id).attr('value','');
if(change==true)
contexto.find('#'+id).change();
}
function wSelectFirst(id){
$('wp-input-container[for="'+id+'"] wp-select-container wp-sel-op:first-child').click();
}
//---------------------------------------------------------------------------------------------------
function wGetCookie(c){
var n=c+"=";
var ca=document.cookie.split(';');
for(var i=0;i