| 1 |
/* ============================================================= |
| 2 |
* JQuery or Other Extension |
| 3 |
* ============================================================= |
| 4 |
*/ |
| 5 |
|
| 6 |
"use strict"; |
| 7 |
|
| 8 |
jQuery.fn.getAttributes = function() { |
| 9 |
var attributes = {}; |
| 10 |
if (!this.length) |
| 11 |
return this; |
| 12 |
jQuery.each(this[0].attributes, function(index, attr) { |
| 13 |
attributes[attr.name] = attr.value; |
| 14 |
}); |
| 15 |
return attributes; |
| 16 |
}; |
| 17 |
jQuery.fn.getDatas = function() { |
| 18 |
var attributes = {}, |
| 19 |
prefix = "data-vp-"; |
| 20 |
if (!this.length) |
| 21 |
return this; |
| 22 |
jQuery.each(this[0].attributes, function(index, attr) { |
| 23 |
if (attr.name.substring(0, prefix.length) == prefix) |
| 24 |
{ |
| 25 |
attributes[attr.name.substring(prefix.length)] = attr.value; |
| 26 |
} |
| 27 |
}); |
| 28 |
return attributes; |
| 29 |
}; |
| 30 |
jQuery.fn.exists = function () { |
| 31 |
return this.length !== 0; |
| 32 |
}; |
| 33 |
if (!String.prototype.trimChar) { |
| 34 |
String.prototype.trimChar = function(string) { return this.replace(new RegExp('^' + string + '+|' + string + '+$', 'g'), ''); }; |
| 35 |
} |
| 36 |
if (!String.prototype.format) { |
| 37 |
String.prototype.format = function() { |
| 38 |
var args = arguments; |
| 39 |
return this.replace(/{(\d+)}/g, function(match, number) { |
| 40 |
return typeof args[number] != 'undefined' ? args[number] : match; |
| 41 |
}); |
| 42 |
}; |
| 43 |
} |
| 44 |
if (!String.prototype.replaceAll){ |
| 45 |
/** |
| 46 |
* ReplaceAll by Fagner Brack (MIT Licensed) |
| 47 |
* Replaces all occurrences of a substring in a string |
| 48 |
*/ |
| 49 |
String.prototype.replaceAll = function(token, newToken, ignoreCase) { |
| 50 |
var str, i = -1, _token; |
| 51 |
if((str = this.toString()) && typeof token === "string") { |
| 52 |
_token = ignoreCase === true? token.toLowerCase() : undefined; |
| 53 |
while((i = ( |
| 54 |
_token !== undefined? |
| 55 |
str.toLowerCase().indexOf( |
| 56 |
_token, |
| 57 |
i >= 0? i + newToken.length : 0 |
| 58 |
) : str.indexOf( |
| 59 |
token, |
| 60 |
i >= 0? i + newToken.length : 0 |
| 61 |
) |
| 62 |
)) !== -1 ) { |
| 63 |
str = str.substring(0, i) |
| 64 |
.concat(newToken) |
| 65 |
.concat(str.substring(i + token.length)); |
| 66 |
} |
| 67 |
} |
| 68 |
return str; |
| 69 |
}; |
| 70 |
} |
| 71 |
// Validation Functions |
| 72 |
jQuery.fn.validationVal = function() { |
| 73 |
var $this = this, |
| 74 |
val = '', |
| 75 |
tagName = $this.prop('tagName'), |
| 76 |
checked; |
| 77 |
|
| 78 |
if (($this.length > 1 && $this.attr('type') != 'radio') || $this.attr('multiple')) { val = []; } |
| 79 |
|
| 80 |
var initialVal = val; |
| 81 |
|
| 82 |
$this.each(function(i) { |
| 83 |
var $field = jQuery(this); |
| 84 |
|
| 85 |
switch (tagName) |
| 86 |
{ |
| 87 |
case 'SELECT': |
| 88 |
if ($field.has('[multiple]')) |
| 89 |
{ |
| 90 |
val = $field.val(); |
| 91 |
} |
| 92 |
else |
| 93 |
{ |
| 94 |
val = $field.val(); |
| 95 |
} |
| 96 |
break; |
| 97 |
case 'INPUT': |
| 98 |
switch ($this.attr('type')) |
| 99 |
{ |
| 100 |
case 'text': |
| 101 |
val = $field.val(); |
| 102 |
break; |
| 103 |
case 'radio': |
| 104 |
checked = $field.prop('checked'); |
| 105 |
if (typeof checked !== 'undefined' && checked !== false) |
| 106 |
val = $field.val(); |
| 107 |
break; |
| 108 |
case 'checkbox': |
| 109 |
checked = $field.prop('checked'); |
| 110 |
if ($this.length > 1) |
| 111 |
{ |
| 112 |
if (typeof checked !== 'undefined' && checked !== false) { val.push($field.val()); } // multiple |
| 113 |
} |
| 114 |
else |
| 115 |
{ |
| 116 |
val = null; |
| 117 |
if (typeof checked !== 'undefined' && checked !== false) { val = $field.val(); } // multiple |
| 118 |
} |
| 119 |
break; |
| 120 |
} |
| 121 |
break; |
| 122 |
case 'TEXTAREA': |
| 123 |
val = $field.val(); |
| 124 |
break; |
| 125 |
default: |
| 126 |
val = $field.val(); |
| 127 |
break; |
| 128 |
} |
| 129 |
}); |
| 130 |
|
| 131 |
// quick fix trial |
| 132 |
if (val === null) |
| 133 |
val = initialVal; |
| 134 |
return val; |
| 135 |
}; |
| 136 |
|
| 137 |
// hidding plugin |
| 138 |
jQuery.fn.vp_slideUp = function(callback){ |
| 139 |
var $this = this; |
| 140 |
|
| 141 |
$this.each(function(i){ |
| 142 |
var $el = jQuery(this); |
| 143 |
if(!$el.hasClass('vp-hide')) |
| 144 |
{ |
| 145 |
$el.slideUp('fast', function() { |
| 146 |
jQuery(this).addClass('vp-hide') |
| 147 |
.slideDown(0, callback); |
| 148 |
}); |
| 149 |
} |
| 150 |
}); |
| 151 |
}; |
| 152 |
jQuery.fn.vp_slideDown = function(callback){ |
| 153 |
var $this = this; |
| 154 |
|
| 155 |
$this.each(function(i){ |
| 156 |
var $el = jQuery(this); |
| 157 |
if($el.hasClass('vp-hide')) |
| 158 |
{ |
| 159 |
$el.slideUp(0, function() { |
| 160 |
jQuery(this).removeClass('vp-hide') |
| 161 |
.slideDown('fast', callback); |
| 162 |
}); |
| 163 |
} |
| 164 |
}); |
| 165 |
}; |
| 166 |
jQuery.fn.vp_fadeOut = function(callback){ |
| 167 |
var $this = this; |
| 168 |
if(!$this.hasClass('vp-hide')) |
| 169 |
{ |
| 170 |
$this.fadeOut('fast', function() { |
| 171 |
jQuery(this).addClass('vp-hide') |
| 172 |
.fadeIn(0, callback); |
| 173 |
}); |
| 174 |
} |
| 175 |
}; |
| 176 |
jQuery.fn.vp_fadeIn = function(callback){ |
| 177 |
var $this = this; |
| 178 |
if($this.hasClass('vp-hide')) |
| 179 |
{ |
| 180 |
$this.fadeOut(0,function() { |
| 181 |
jQuery(this).removeClass('vp-hide') |
| 182 |
.fadeIn('fast', callback); |
| 183 |
}); |
| 184 |
} |
| 185 |
}; |
| 186 |
jQuery.fn.vp_toggle = function(callback){ |
| 187 |
var $this = this; |
| 188 |
if($this.hasClass('vp-hide')) |
| 189 |
{ |
| 190 |
$this.slideUp(0,function() { |
| 191 |
jQuery(this).removeClass('vp-hide') |
| 192 |
.slideDown('fast', callback); |
| 193 |
}); |
| 194 |
} |
| 195 |
else |
| 196 |
{ |
| 197 |
$this.slideUp('fast', function() { |
| 198 |
jQuery(this).addClass('vp-hide') |
| 199 |
.slideDown(0, callback); |
| 200 |
}); |
| 201 |
} |
| 202 |
}; |
| 203 |
|
| 204 |
/* |
| 205 |
* ============================================================= |
| 206 |
*/ |
| 207 |
|
| 208 |
|
| 209 |
/** |
| 210 |
* ============================================================= |
| 211 |
* Vafpress function |
| 212 |
* ============================================================= |
| 213 |
*/ |
| 214 |
|
| 215 |
/** |
| 216 |
* vafpress global namespace |
| 217 |
*/ |
| 218 |
var vp = {}; |
| 219 |
|
| 220 |
vp.isNumber = function(n) { |
| 221 |
return !isNaN(parseFloat(n)) && isFinite(n); |
| 222 |
}; |
| 223 |
vp.parseOpt = function(optString) { |
| 224 |
var openIdx, closeIdx, temp, tempArr, opt = {}; |
| 225 |
for (var i = 0; i < optString.length; i++) |
| 226 |
{ |
| 227 |
if (optString[i] == '(') |
| 228 |
{ |
| 229 |
openIdx = i; |
| 230 |
} |
| 231 |
if (optString[i] == ')') |
| 232 |
{ |
| 233 |
closeIdx = i; |
| 234 |
temp = optString.substring(openIdx + 1, closeIdx); |
| 235 |
tempArr = temp.split(':'); |
| 236 |
opt[tempArr[0]] = vp.isNumber(tempArr[1]) ? parseFloat(tempArr[1]) : tempArr[1]; |
| 237 |
} |
| 238 |
} |
| 239 |
return opt; |
| 240 |
}; |
| 241 |
|
| 242 |
vp.wp_ext2type = function ( ext ) { |
| 243 |
var ext2type = { |
| 244 |
image : ['jpg', 'jpeg', 'bmp', 'gif', 'png'], |
| 245 |
audio : ['aac', 'ac3', 'aif', 'aiff', 'm3a', 'm4a', 'm4b', 'mka', 'mp1', 'mp2', 'mp3', 'ogg', 'oga', 'ram', 'wav', 'wma'], |
| 246 |
video : ['asf', 'avi', 'divx', 'dv', 'flv', 'm4v', 'mkv', 'mov', 'mp4', 'mpeg', 'mpg', 'mpv', 'ogm', 'ogv', 'qt', 'rm', 'vob', 'wmv'], |
| 247 |
document : ['doc', 'docx', 'docm', 'dotm', 'odt', 'pages', 'pdf', 'rtf', 'wp', 'wpd'], |
| 248 |
spreadsheet : ['numbers', 'ods', 'xls', 'xlsx', 'xlsm', 'xlsb'], |
| 249 |
interactive : ['swf', 'key', 'ppt', 'pptx', 'pptm', 'pps', 'ppsx', 'ppsm', 'sldx', 'sldm', 'odp'], |
| 250 |
text : ['asc', 'csv', 'tsv', 'txt'], |
| 251 |
archive : ['bz2', 'cab', 'dmg', 'gz', 'rar', 'sea', 'sit', 'sqx', 'tar', 'tgz', 'zip', '7z'], |
| 252 |
code : ['css', 'htm', 'html', 'php', 'js'] |
| 253 |
}; |
| 254 |
|
| 255 |
var result = 'default'; |
| 256 |
|
| 257 |
for(var type in ext2type) |
| 258 |
{ |
| 259 |
if(ext2type.hasOwnProperty(type)) |
| 260 |
{ |
| 261 |
if(jQuery.inArray(ext, ext2type[type]) !== -1 ) |
| 262 |
{ |
| 263 |
result = type; |
| 264 |
break; |
| 265 |
} |
| 266 |
} |
| 267 |
} |
| 268 |
return result; |
| 269 |
}; |
| 270 |
|
| 271 |
vp.get_url_extension = function(url){ |
| 272 |
var regex = new RegExp(/(.*)[\/\\]([^\/\\]+)\.(\w+)/i); |
| 273 |
var url_info = regex.exec(url); |
| 274 |
if(url_info) |
| 275 |
{ |
| 276 |
if (typeof url_info[3] != 'undefined') |
| 277 |
{ |
| 278 |
return url_info[3]; |
| 279 |
} |
| 280 |
} |
| 281 |
return ''; |
| 282 |
}; |
| 283 |
|
| 284 |
vp.jqid = function(id) { |
| 285 |
return '#' + id.replace(/([:\.\[\]])/g,'\\$1'); |
| 286 |
}; |
| 287 |
|
| 288 |
vp.jqidwild = function(id) { |
| 289 |
id = id.replace(/([:\.\[\]])/g,'\\$1'); |
| 290 |
id = '[id*=' + id + ']'; |
| 291 |
return id; |
| 292 |
}; |
| 293 |
|
| 294 |
vp.jqname = function(name) { |
| 295 |
return '[name="' + name + '"]'; |
| 296 |
}; |
| 297 |
|
| 298 |
vp.jqnamewild = function(name) { |
| 299 |
return '[name*="' + name + '"]'; |
| 300 |
}; |
| 301 |
|
| 302 |
vp.thejqid = function(id, thecase) { |
| 303 |
if(thecase === 'option') |
| 304 |
return vp.jqid(id); |
| 305 |
if(thecase === 'metabox') |
| 306 |
return vp.jqidwild(id); |
| 307 |
return id; |
| 308 |
}; |
| 309 |
|
| 310 |
vp.thejqname = function(name, thecase) { |
| 311 |
if(thecase === 'option') |
| 312 |
return vp.jqname(name); |
| 313 |
if(thecase === 'metabox') |
| 314 |
return vp.jqnamewild(name); |
| 315 |
return name; |
| 316 |
}; |
| 317 |
|
| 318 |
vp.validateAlphabet = function(type, val) { |
| 319 |
// ignore array and empty string, since they should be handled by 'required' rule |
| 320 |
if (val === '' || jQuery.isArray(val) || jQuery.inArray(type, vp_wp.alphabet_validatable) == -1) { return true; } |
| 321 |
var regex = new RegExp(/^[A-Z\s]+$/i); |
| 322 |
return regex.test(val); |
| 323 |
}; |
| 324 |
|
| 325 |
vp.validateAlphaNumeric = function(type, val) { |
| 326 |
// ignore array and empty string, since they should be handled by 'required' rule |
| 327 |
if (val === '' || jQuery.isArray(val) || jQuery.inArray(type, vp_wp.alphanumeric_validatable) == -1) { return true; } |
| 328 |
|
| 329 |
var regex = new RegExp(/^[A-Z0-9]+$/i); |
| 330 |
return regex.test(val); |
| 331 |
}; |
| 332 |
|
| 333 |
vp.validateNumeric = function(type, val) { |
| 334 |
// ignore array and empty string, since they should be handled by 'required' rule |
| 335 |
if (val === '' || jQuery.isArray(val) || jQuery.inArray(type, vp_wp.numeric_validatable) == -1) { return true; } |
| 336 |
|
| 337 |
var regex = new RegExp(/^[-+]?[0-9]*\.?[0-9]+$/); |
| 338 |
return regex.test(val); |
| 339 |
}; |
| 340 |
|
| 341 |
vp.validateEmail = function(type, val) { |
| 342 |
// ignore array and empty string, since they should be handled by 'required' rule |
| 343 |
if (val === '' || jQuery.isArray(val) || jQuery.inArray(type, vp_wp.email_validatable) == -1) { return true; } |
| 344 |
|
| 345 |
var regex = new RegExp(/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i); |
| 346 |
return regex.test(val); |
| 347 |
}; |
| 348 |
|
| 349 |
vp.validateURL = function(type, val) { |
| 350 |
// ignore array and empty string, since they should be handled by 'required' rule |
| 351 |
if (val === '' || jQuery.isArray(val) || jQuery.inArray(type, vp_wp.url_validatable) == -1) { return true; } |
| 352 |
|
| 353 |
var regex = new RegExp(/^(ftp|http|https):\/\/[^ "]+$/i); |
| 354 |
return regex.test(val); |
| 355 |
}; |
| 356 |
|
| 357 |
vp.validateMaxLength = function(type, val, n) { |
| 358 |
// ignore array |
| 359 |
if (jQuery.inArray(type, vp_wp.maxlength_validatable) != -1) { return true; } |
| 360 |
|
| 361 |
return (val.length <= n) ? true : false; |
| 362 |
}; |
| 363 |
|
| 364 |
vp.validateMinLength = function(type, val, n) { |
| 365 |
// ignore array |
| 366 |
if (jQuery.inArray(type, vp_wp.minlength_validatable) != -1) { return true; } |
| 367 |
|
| 368 |
return (val.length >= n) ? true : false; |
| 369 |
}; |
| 370 |
|
| 371 |
vp.validateRequired = function(type, val) { |
| 372 |
// only check if it's empty array, if it's not, it will go true anyway.. |
| 373 |
if (jQuery.isArray(val) && jQuery.isEmptyObject(val)) return false; |
| 374 |
return (val) ? true : false; |
| 375 |
}; |
| 376 |
|
| 377 |
// validation function loop |
| 378 |
vp.fields_validation_loop = function(fields){ |
| 379 |
|
| 380 |
var msgHTML = '<li class="validation-msg vp-error"></li>', |
| 381 |
errors = 0; |
| 382 |
|
| 383 |
for (var i = 0; i < fields.length; i++) |
| 384 |
{ |
| 385 |
var field = fields[i], |
| 386 |
$tr = jQuery(vp.jqid(field.name)), |
| 387 |
$parent = $tr.parents('.vp-meta-group').exists() ? $tr.parents('.vp-meta-group') : $tr.parents('.vp-section'); |
| 388 |
|
| 389 |
// if field is now deleted and not found |
| 390 |
if($tr.length <= 0) |
| 391 |
continue; |
| 392 |
|
| 393 |
// if field is inactive due to dependencies mechanism |
| 394 |
if($tr.hasClass('vp-dep-inactive') || ($parent.exists() && $parent.hasClass('vp-dep-inactive'))) |
| 395 |
continue; |
| 396 |
|
| 397 |
var $msgs = $tr.children('div.field').children('.validation-msgs').children('ul'), |
| 398 |
$input = jQuery('[name="' + field.name + '"]'), |
| 399 |
val = $input.validationVal(), |
| 400 |
type = field.type, |
| 401 |
rules = field.rules.split('|'); |
| 402 |
|
| 403 |
field.nError = 0; |
| 404 |
for (var j = 0; j < rules.length; j++) |
| 405 |
{ |
| 406 |
var rule = rules[j], |
| 407 |
q1 = rule.indexOf('['), |
| 408 |
q2 = rule.indexOf(']'), |
| 409 |
def = (q1 >= 0) ? rule.substring(0, q1) : rule, |
| 410 |
res = '', |
| 411 |
n; |
| 412 |
|
| 413 |
switch (def) |
| 414 |
{ |
| 415 |
case 'alphabet': |
| 416 |
if (!vp.validateAlphabet(type, val)) { res = vp_wp.val_msg.alphabet.format(); } |
| 417 |
break; |
| 418 |
case 'alphanumeric': |
| 419 |
if (!vp.validateAlphaNumeric(type, val)) { res = vp_wp.val_msg.alphanumeric.format(); } |
| 420 |
break; |
| 421 |
case 'numeric': |
| 422 |
if (!vp.validateNumeric(type, val)) { res = vp_wp.val_msg.numeric.format(); } |
| 423 |
break; |
| 424 |
case 'email': |
| 425 |
if (!vp.validateEmail(type, val)) { res = vp_wp.val_msg.email.format(); } |
| 426 |
break; |
| 427 |
case 'url': |
| 428 |
if (!vp.validateURL(type, val)) { res = vp_wp.val_msg.url.format(); } |
| 429 |
break; |
| 430 |
case 'maxlength': |
| 431 |
n = rule.substring(q1 + 1, q2); |
| 432 |
if (!vp.validateMaxLength(type, val, n)) { res = vp_wp.val_msg.maxlength.format(n); } |
| 433 |
break; |
| 434 |
case 'minlength': |
| 435 |
n = rule.substring(q1 + 1, q2); |
| 436 |
if (!vp.validateMinLength(type, val, n)) { res= vp_wp.val_msg.minlength.format(n); } |
| 437 |
break; |
| 438 |
case 'maxselected': |
| 439 |
n = rule.substring(q1 + 1, q2); |
| 440 |
if (!vp.validateMaxLength(type, val, n)) { res = vp_wp.val_msg.maxselected.format(n); } |
| 441 |
break; |
| 442 |
case 'minselected': |
| 443 |
n = rule.substring(q1 + 1, q2); |
| 444 |
if (!vp.validateMinLength(type, val, n)) { res= vp_wp.val_msg.minselected.format(n); } |
| 445 |
break; |
| 446 |
case 'required': |
| 447 |
if (!vp.validateRequired(type, val)) { res = vp_wp.val_msg.required.format(); } |
| 448 |
break; |
| 449 |
} |
| 450 |
|
| 451 |
if (res !== '') |
| 452 |
{ |
| 453 |
// push into errors pool |
| 454 |
field.nError += 1; |
| 455 |
|
| 456 |
// set message |
| 457 |
var $msg = jQuery(msgHTML); |
| 458 |
$msg.html(res); |
| 459 |
$msg.appendTo($msgs); |
| 460 |
} |
| 461 |
} |
| 462 |
|
| 463 |
if (field.nError > 0) |
| 464 |
{ |
| 465 |
errors += 1; |
| 466 |
$tr.addClass('vp-error'); |
| 467 |
} |
| 468 |
} |
| 469 |
return errors; |
| 470 |
}; |
| 471 |
|
| 472 |
// custom checkbox and radiobutton handler |
| 473 |
vp.custom_check_radio_event = function(parent, selector){ |
| 474 |
jQuery(parent).delegate(selector, "click", function(e){ |
| 475 |
e.preventDefault(); |
| 476 |
var $control = jQuery(this).find('input'), |
| 477 |
type = $control.attr('type'); |
| 478 |
if(type == 'radio') |
| 479 |
{ |
| 480 |
jQuery(this).parent().parent().find('input').each(function(i){ |
| 481 |
jQuery(this).removeClass('checked'); |
| 482 |
$control.prop('checked', false); |
| 483 |
}); |
| 484 |
$control.prop('checked', true).change(); |
| 485 |
} |
| 486 |
else if(type == 'checkbox') |
| 487 |
{ |
| 488 |
if ($control.is(':checked')) |
| 489 |
$control.prop('checked', false); |
| 490 |
else |
| 491 |
$control.prop('checked', true); |
| 492 |
$control.trigger('change'); |
| 493 |
} |
| 494 |
}); |
| 495 |
jQuery(parent).delegate(selector, "change", function(e){ |
| 496 |
e.preventDefault(); |
| 497 |
var $control = jQuery(this).find('input'); |
| 498 |
if ($control.is(':checked')) |
| 499 |
$control.addClass('checked'); |
| 500 |
else |
| 501 |
$control.removeClass('checked'); |
| 502 |
}); |
| 503 |
}; |
| 504 |
|
| 505 |
// vafpress binding related functions |
| 506 |
vp.binding_action = function(ids, field, func, thecase) { |
| 507 |
var $source_tr = jQuery(vp.jqid(field.source)), |
| 508 |
$source = jQuery('[name="' + field.source + '"]'), |
| 509 |
values = []; |
| 510 |
|
| 511 |
for (var i = 0; i < ids.length; i++) |
| 512 |
{ |
| 513 |
var val = jQuery(vp.thejqname(ids[i], thecase)).validationVal(); |
| 514 |
if (jQuery.isArray(val) && val.length == 0) { |
| 515 |
val = null; |
| 516 |
} |
| 517 |
values.push(val); |
| 518 |
} |
| 519 |
|
| 520 |
var data = { |
| 521 |
action : 'vp_ajax_wrapper', |
| 522 |
func : func, |
| 523 |
params : values |
| 524 |
}; |
| 525 |
|
| 526 |
// get loader |
| 527 |
var $loader = $source_tr.find('.vp-js-bind-loader'), |
| 528 |
$input = $source_tr.find('.input'); |
| 529 |
|
| 530 |
if (field.type == 'vp-html') { |
| 531 |
$loader.vp_fadeIn(); |
| 532 |
} else { |
| 533 |
$input.vp_fadeOut(function(){ |
| 534 |
$loader.vp_fadeIn(); |
| 535 |
}); |
| 536 |
} |
| 537 |
|
| 538 |
jQuery.post(ajaxurl, data, function(response) { |
| 539 |
$loader.vp_fadeOut(function(){ |
| 540 |
$input.vp_fadeIn(); |
| 541 |
}); |
| 542 |
if (response.status) |
| 543 |
{ |
| 544 |
var data; |
| 545 |
switch(field.type) |
| 546 |
{ |
| 547 |
case 'vp-select': |
| 548 |
case 'vp-multiselect': |
| 549 |
$source = jQuery('[name="' + field.source + '"]'); |
| 550 |
if(response.data !== null) |
| 551 |
{ |
| 552 |
data = response.data instanceof Array ? response.data : [response.data]; |
| 553 |
$source.val(data).change(); |
| 554 |
} |
| 555 |
break; |
| 556 |
case 'vp-checkbox': |
| 557 |
if(response.data !== null) |
| 558 |
{ |
| 559 |
data = response.data instanceof Array ? response.data : [response.data]; |
| 560 |
$source.prop('checked', false).change(); |
| 561 |
jQuery.each(data, function(key, value) { |
| 562 |
$source.filter('[value="'+ value +'"]').prop('checked', true).change(); |
| 563 |
}); |
| 564 |
} |
| 565 |
break; |
| 566 |
case 'vp-toggle': |
| 567 |
if(response.data !== null) |
| 568 |
{ |
| 569 |
if(response.data) |
| 570 |
$source.prop('checked', true).change(); |
| 571 |
else |
| 572 |
$source.prop('checked', false).change(); |
| 573 |
} |
| 574 |
break; |
| 575 |
case 'vp-checkimage': |
| 576 |
if(response.data !== null) |
| 577 |
{ |
| 578 |
data = response.data instanceof Array ? response.data : [response.data]; |
| 579 |
$source.prop('checked', false).change(); |
| 580 |
jQuery.each(data, function(key, value) { |
| 581 |
$source.filter('[value="'+ value +'"]').prop('checked', true).change(); |
| 582 |
}); |
| 583 |
} |
| 584 |
vp.init_tipsy(); |
| 585 |
break; |
| 586 |
case 'vp-radiobutton': |
| 587 |
if(response.data !== null) |
| 588 |
{ |
| 589 |
data = response.data instanceof Array ? response.data : [response.data]; |
| 590 |
$source.prop('checked', false).change(); |
| 591 |
jQuery.each(data, function(key, value) { |
| 592 |
$source.filter('[value="'+ value +'"]').prop('checked', true).change(); |
| 593 |
}); |
| 594 |
} |
| 595 |
break; |
| 596 |
case 'vp-radioimage': |
| 597 |
if(response.data !== null) |
| 598 |
{ |
| 599 |
data = response.data instanceof Array ? response.data : [response.data]; |
| 600 |
$source.prop('checked', false).change(); |
| 601 |
jQuery.each(data, function(key, value) { |
| 602 |
$source.filter('[value="'+ value +'"]').prop('checked', true).change(); |
| 603 |
}); |
| 604 |
} |
| 605 |
vp.init_tipsy(); |
| 606 |
break; |
| 607 |
case 'vp-html': |
| 608 |
if(response.data !== null) |
| 609 |
{ |
| 610 |
jQuery(vp.jqid(field.source + '_dom')).html(response.data); |
| 611 |
jQuery(vp.jqname(field.source)).val(response.data); |
| 612 |
} |
| 613 |
break; |
| 614 |
default: |
| 615 |
$source = jQuery(vp.jqname(field.source)); |
| 616 |
$source.val(response.data); |
| 617 |
} |
| 618 |
jQuery('[name="' + field.source + '"]:first').keypress().keyup().change().blur(); |
| 619 |
} |
| 620 |
}, 'JSON'); |
| 621 |
}; |
| 622 |
|
| 623 |
vp.binding_event = function(ids, idx, field, func, parent, thecase) |
| 624 |
{ |
| 625 |
var change = ['vp-select', 'vp-checkbox', 'vp-checkimage', 'vp-radiobutton', 'vp-radioimage', 'vp-multiselect', 'vp-toggle', 'vp-upload'], |
| 626 |
typing = ['vp-textbox', 'vp-slider', 'vp-color', 'vp-date'], |
| 627 |
name = vp.thejqname(ids[idx], thecase), |
| 628 |
dest_type = jQuery(vp.thejqid(ids[idx], thecase)).attr('data-vp-type'); |
| 629 |
|
| 630 |
if(jQuery.inArray(dest_type, change) !== -1 ) |
| 631 |
{ |
| 632 |
jQuery(parent).delegate(name, 'change', function(){vp.binding_action(ids, field, func, thecase);}); |
| 633 |
} |
| 634 |
else if(jQuery.inArray(dest_type, typing) !== -1 ) |
| 635 |
{ |
| 636 |
jQuery(name).typing({ |
| 637 |
stop: function(event, $elem){ |
| 638 |
vp.binding_action(ids, field, func, thecase); |
| 639 |
}, |
| 640 |
delay: 400 |
| 641 |
}); |
| 642 |
} |
| 643 |
else |
| 644 |
{ |
| 645 |
jQuery(parent).delegate(name, 'change', function(){vp.binding_action(ids, field, func, thecase);}); |
| 646 |
} |
| 647 |
}; |
| 648 |
|
| 649 |
/* |
| 650 |
* ============================================================= |
| 651 |
*/ |
| 652 |
|
| 653 |
// vafpress binding related functions |
| 654 |
vp.items_binding_action = function(ids, field, func, thecase) { |
| 655 |
var $source_tr = jQuery(vp.jqid(field.source)), |
| 656 |
$source = jQuery('[name="' + field.source + '"]'), |
| 657 |
values = []; |
| 658 |
|
| 659 |
for (var i = 0; i < ids.length; i++) |
| 660 |
{ |
| 661 |
values.push(jQuery(vp.thejqname(ids[i], thecase)).validationVal()); |
| 662 |
} |
| 663 |
|
| 664 |
var data = { |
| 665 |
action : 'vp_ajax_wrapper', |
| 666 |
func : func, |
| 667 |
params : values |
| 668 |
}; |
| 669 |
|
| 670 |
// get loader |
| 671 |
var $loader = $source_tr.find('.vp-js-bind-loader'), |
| 672 |
$input = $source_tr.find('.input'); |
| 673 |
|
| 674 |
$input.vp_fadeOut(function(){ |
| 675 |
$loader.vp_fadeIn(); |
| 676 |
}); |
| 677 |
|
| 678 |
jQuery.post(ajaxurl, data, function(response) { |
| 679 |
$loader.vp_fadeOut(function(){ |
| 680 |
$input.vp_fadeIn(); |
| 681 |
}); |
| 682 |
if (response.status) |
| 683 |
{ |
| 684 |
var $source; |
| 685 |
switch(field.type) |
| 686 |
{ |
| 687 |
case 'vp-select': |
| 688 |
case 'vp-multiselect': |
| 689 |
$source = jQuery('[name="' + field.source + '"]'); |
| 690 |
$source.empty(); |
| 691 |
$source.append(jQuery("<option></option>")); |
| 692 |
response.data !== null && jQuery.each(response.data, function(key, value) { |
| 693 |
$source |
| 694 |
.append(jQuery("<option></option>") |
| 695 |
.attr("value",value.value) |
| 696 |
.text(value.label)); |
| 697 |
}); |
| 698 |
break; |
| 699 |
case 'vp-checkbox': |
| 700 |
$source = $input; |
| 701 |
$source.empty(); |
| 702 |
$source = jQuery(vp.jqid(field.source)).find('.input'); |
| 703 |
response.data !== null && jQuery.each(response.data, function(key, value) { |
| 704 |
$source.append(jQuery('<label><input class="vp-input" type="checkbox" name="' + field.source + '" value="' + value.value + '"><span></span>'+ value.label + '</label>')); |
| 705 |
}); |
| 706 |
break; |
| 707 |
case 'vp-checkimage': |
| 708 |
$source = $input; |
| 709 |
$source.empty(); |
| 710 |
$source = jQuery(vp.jqid(field.source)).find('.input'); |
| 711 |
response.data !== null && jQuery.each(response.data, function(key, value) { |
| 712 |
$source.append(jQuery('<label><input class="vp-input" type="checkbox" name="' + field.source + '" value="' + value.value + '"><img src="' + value.img + '" alt="' + value.label + '" class="vp-js-tipsy image-item" style="" original-title="' + value.value + '"></label>')); |
| 713 |
}); |
| 714 |
vp.init_tipsy(); |
| 715 |
break; |
| 716 |
case 'vp-radiobutton': |
| 717 |
$source = $input; |
| 718 |
$source.empty(); |
| 719 |
$source = jQuery(vp.jqid(field.source)).find('.input'); |
| 720 |
response.data !== null && jQuery.each(response.data, function(key, value) { |
| 721 |
$source.append(jQuery('<label><input class="vp-input" type="radio" name="' + field.source + '" value="' + value.value + '"><span></span>'+ value.label + '</label>')); |
| 722 |
}); |
| 723 |
break; |
| 724 |
case 'vp-radioimage': |
| 725 |
$source = $input; |
| 726 |
$source.empty(); |
| 727 |
$source = jQuery(vp.jqid(field.source)).find('.input'); |
| 728 |
response.data !== null && jQuery.each(response.data, function(key, value) { |
| 729 |
$source.append(jQuery('<label><input class="vp-input" type="radio" name="' + field.source + '" value="' + value.value + '"><img src="' + value.img + '" alt="' + value.label + '" class="vp-js-tipsy image-item" style="" original-title="' + value.value + '"></label>')); |
| 730 |
}); |
| 731 |
vp.init_tipsy(); |
| 732 |
break; |
| 733 |
} |
| 734 |
jQuery('[name="' + field.source + '"]:first').change().blur(); |
| 735 |
} |
| 736 |
}, 'JSON'); |
| 737 |
}; |
| 738 |
|
| 739 |
vp.items_binding_event = function(ids, idx, field, func, parent, thecase) |
| 740 |
{ |
| 741 |
var change = ['vp-select', 'vp-checkbox', 'vp-checkimage', 'vp-radiobutton', 'vp-radioimage', 'vp-multiselect', 'vp-toggle', 'vp-upload'], |
| 742 |
typing = ['vp-textbox', 'vp-slider', 'vp-color', 'vp-date'], |
| 743 |
name = vp.thejqname(ids[idx], thecase), |
| 744 |
dest_type = jQuery(vp.thejqid(ids[idx], thecase)).attr('data-vp-type'); |
| 745 |
|
| 746 |
if(jQuery.inArray(dest_type, change) !== -1 ) |
| 747 |
{ |
| 748 |
jQuery(parent).delegate(name, 'change', function(){vp.items_binding_action(ids, field, func, thecase);}); |
| 749 |
} |
| 750 |
else if(jQuery.inArray(dest_type, typing) !== -1 ) |
| 751 |
{ |
| 752 |
jQuery(name).typing({ |
| 753 |
stop: function(event, $elem){ |
| 754 |
vp.items_binding_action(ids, field, func, thecase); |
| 755 |
}, |
| 756 |
delay: 400 |
| 757 |
}); |
| 758 |
} |
| 759 |
else |
| 760 |
{ |
| 761 |
jQuery(parent).delegate(name, 'change', function(){vp.binding_action(ids, field, func, thecase);}); |
| 762 |
} |
| 763 |
}; |
| 764 |
|
| 765 |
/* |
| 766 |
* ============================================================= |
| 767 |
*/ |
| 768 |
|
| 769 |
// vafpress dependencies related functions |
| 770 |
vp.dependency_action = function(ids, field, func) { |
| 771 |
|
| 772 |
var $source_tr = jQuery(vp.jqid(field.source)), |
| 773 |
$source = jQuery('[name="' + field.source + '"]'), |
| 774 |
values = [], |
| 775 |
targets = []; |
| 776 |
|
| 777 |
for (var i = 0; i < ids.length; i++) |
| 778 |
{ |
| 779 |
targets.push(jQuery(vp.jqid(ids[i]))); |
| 780 |
values.push(jQuery('[name="' + ids[i] + '"]').validationVal()); |
| 781 |
} |
| 782 |
|
| 783 |
var data = { |
| 784 |
action : 'vp_ajax_wrapper', |
| 785 |
func : func, |
| 786 |
params : values |
| 787 |
}; |
| 788 |
|
| 789 |
// get loader |
| 790 |
jQuery.each(targets, function(idx, val){ |
| 791 |
var $loader = val.find('.vp-js-bind-loader'); |
| 792 |
$loader.vp_fadeIn(); |
| 793 |
}); |
| 794 |
|
| 795 |
jQuery.post(ajaxurl, data, function(response) { |
| 796 |
jQuery.each(targets, function(idx, val){ |
| 797 |
var $loader = val.find('.vp-js-bind-loader'); |
| 798 |
$loader.vp_fadeOut(); |
| 799 |
}); |
| 800 |
|
| 801 |
if (response.status) |
| 802 |
{ |
| 803 |
if(response.data) |
| 804 |
{ |
| 805 |
$source_tr.removeClass('vp-dep-inactive'); |
| 806 |
$source_tr.vp_fadeIn(); |
| 807 |
} |
| 808 |
else |
| 809 |
{ |
| 810 |
$source_tr.addClass('vp-dep-inactive'); |
| 811 |
$source_tr.vp_fadeOut(); |
| 812 |
} |
| 813 |
} |
| 814 |
}, 'JSON'); |
| 815 |
}; |
| 816 |
|
| 817 |
vp.dependency_event = function(ids, idx, field, func, parent){ |
| 818 |
|
| 819 |
var change = ['vp-select', 'vp-checkbox', 'vp-checkimage', 'vp-radiobutton', 'vp-radioimage', 'vp-multiselect', 'vp-toggle', 'vp-upload'], |
| 820 |
typing = ['vp-textbox', 'vp-slider', 'vp-color', 'vp-date'], |
| 821 |
name = vp.thejqname(ids[idx], 'option'), |
| 822 |
dest_type = jQuery(vp.thejqid(ids[idx], 'option')).attr('data-vp-type'); |
| 823 |
|
| 824 |
if(jQuery.inArray(dest_type, change) !== -1 ) |
| 825 |
{ |
| 826 |
jQuery(parent).delegate(name, 'change', function(){vp.dependency_action(ids, field, func);}); |
| 827 |
} |
| 828 |
else if(jQuery.inArray(dest_type, typing) !== -1 ) |
| 829 |
{ |
| 830 |
jQuery(name).typing({ |
| 831 |
stop: function(event, $elem){ |
| 832 |
vp.dependency_action(ids, field, func); |
| 833 |
}, |
| 834 |
delay: 400 |
| 835 |
}); |
| 836 |
} |
| 837 |
else |
| 838 |
{ |
| 839 |
jQuery(parent).delegate(name, 'change', function(){vp.binding_action(ids, field, func, thecase);}); |
| 840 |
} |
| 841 |
}; |
| 842 |
|
| 843 |
/* |
| 844 |
* ============================================================= |
| 845 |
*/ |
| 846 |
|
| 847 |
/** |
| 848 |
* ============================================================= |
| 849 |
* Control Fields JS Trigering |
| 850 |
* ============================================================= |
| 851 |
*/ |
| 852 |
|
| 853 |
function theValidate(elem, options, $slider) |
| 854 |
{ |
| 855 |
var $this = jQuery(elem), |
| 856 |
val = $this.val(); |
| 857 |
if(val === '') |
| 858 |
return; |
| 859 |
if (!vp.validateNumeric('vp-textbox', val)) |
| 860 |
{ |
| 861 |
$this.val(options.min); |
| 862 |
$slider.slider('value', options.min); |
| 863 |
} |
| 864 |
if (val > options.max) |
| 865 |
{ |
| 866 |
$this.val(options.max); |
| 867 |
$slider.slider('value', options.max); |
| 868 |
} |
| 869 |
else if (val < options.min) |
| 870 |
{ |
| 871 |
$this.val(options.min); |
| 872 |
$slider.slider('value', options.min); |
| 873 |
} |
| 874 |
else |
| 875 |
{ |
| 876 |
$slider.slider('value', $this.val()); |
| 877 |
} |
| 878 |
} |
| 879 |
|
| 880 |
vp.init_slider = function($elements) |
| 881 |
{ |
| 882 |
if (jQuery.fn.slider) |
| 883 |
{ |
| 884 |
$elements.each(function(i, el) { |
| 885 |
var $slider = jQuery(this), |
| 886 |
options = jQuery(this).getDatas(); |
| 887 |
options = vp.parseOpt(options.opt); |
| 888 |
options.range = 'min'; |
| 889 |
options.slide = function(event, ui) { |
| 890 |
$slider.prev('.slideinput').val(ui.value); |
| 891 |
$slider.prev('.slideinput').trigger('keypress'); |
| 892 |
$slider.prev('.slideinput').trigger('keyup'); |
| 893 |
}; |
| 894 |
$slider.slider(options); |
| 895 |
|
| 896 |
$slider.prev('.slideinput').keypress(function(e) { |
| 897 |
var charCode = (typeof e.which == "number") ? e.which : e.keyCode; |
| 898 |
if (e.altKey || e.ctrlKey || e.shiftKey) |
| 899 |
return true; |
| 900 |
if (jQuery.inArray(charCode, [45, 46, 8, 0]) != -1 || (charCode >= 48 && charCode <= 57) ) |
| 901 |
return true; |
| 902 |
return false; |
| 903 |
}) |
| 904 |
.blur(function(e){ |
| 905 |
theValidate(this, options, $slider); |
| 906 |
$slider.prev('.slideinput').keypress().keyup(); |
| 907 |
}) |
| 908 |
}); |
| 909 |
} |
| 910 |
}; |
| 911 |
|
| 912 |
|
| 913 |
vp.upload_callback = function() {}; |
| 914 |
|
| 915 |
if ( vp_wp.use_new_media_upload ) |
| 916 |
{ |
| 917 |
var _orig_send_attachment = wp.media.editor.send.attachment, |
| 918 |
_orig_send_link = wp.media.editor.send.link, |
| 919 |
_orig_send_to_editor = window.send_to_editor; |
| 920 |
|
| 921 |
vp.upload_callback = function(e) { |
| 922 |
var $this = jQuery(this), |
| 923 |
$input = $this.parent('.buttons').prev('input'), |
| 924 |
$preview = $this.parent('.buttons').siblings('.image').find('img'); |
| 925 |
|
| 926 |
// handler for attachment |
| 927 |
wp.media.editor.send.attachment = function(props, attachment) { |
| 928 |
|
| 929 |
$input.val(attachment.url); |
| 930 |
$input.trigger('change'); |
| 931 |
|
| 932 |
if(attachment.type === 'image') |
| 933 |
$preview.attr('src', attachment.url); |
| 934 |
else |
| 935 |
$preview.attr('src', attachment.icon); |
| 936 |
|
| 937 |
wp.media.editor.send.attachment = _orig_send_attachment; |
| 938 |
window.send_to_editor = _orig_send_to_editor; |
| 939 |
}; |
| 940 |
|
| 941 |
// handler for link |
| 942 |
window.send_to_editor = function(html) { |
| 943 |
if (html !== '') |
| 944 |
{ |
| 945 |
var info = get_url_info(html); |
| 946 |
$input.val(info.imgurl); |
| 947 |
$input.trigger('change'); |
| 948 |
$preview.attr('src', info.iconurl); |
| 949 |
} |
| 950 |
window.send_to_editor = _orig_send_to_editor; |
| 951 |
wp.media.editor.send.attachment = _orig_send_attachment; |
| 952 |
}; |
| 953 |
wp.media.editor.open($this); |
| 954 |
return false; |
| 955 |
}; |
| 956 |
} |
| 957 |
else |
| 958 |
{ |
| 959 |
var _orig_send_to_editor = window.send_to_editor; |
| 960 |
|
| 961 |
vp.upload_callback = function(e) { |
| 962 |
var _custom_media = true, |
| 963 |
$input = jQuery(this).parent('.buttons').prev('input'), |
| 964 |
$preview = jQuery(this).parent('.buttons').siblings('.image').find('img'); |
| 965 |
|
| 966 |
tb_show('Upload Image', 'media-upload.php?&post_id=0&referer=vafpress&TB_iframe=true'); |
| 967 |
|
| 968 |
window.send_to_editor = function(html) { |
| 969 |
if (html !== '') |
| 970 |
{ |
| 971 |
var info = get_url_info(html); |
| 972 |
$input.val(info.imgurl); |
| 973 |
$input.trigger('change'); |
| 974 |
$preview.attr('src', info.iconurl); |
| 975 |
} |
| 976 |
window.send_to_editor = _orig_send_to_editor; |
| 977 |
tb_remove(); |
| 978 |
}; |
| 979 |
return false; |
| 980 |
}; |
| 981 |
} |
| 982 |
|
| 983 |
function get_url_info(html) |
| 984 |
{ |
| 985 |
var ext, type, imgurl, iconurl, $el = jQuery(html); |
| 986 |
if ($el.prop('tagName') == 'A') |
| 987 |
{ |
| 988 |
imgurl = jQuery(html).attr('href'); |
| 989 |
ext = vp.get_url_extension(imgurl); |
| 990 |
type = vp.wp_ext2type(ext); |
| 991 |
iconurl = imgurl; |
| 992 |
if(type !== 'image') |
| 993 |
{ |
| 994 |
iconurl = vp_wp.wp_include_url + 'images/crystal/' + type + '.png' ; |
| 995 |
} |
| 996 |
} |
| 997 |
else if($el.prop('tagName') == 'IMG') |
| 998 |
{ |
| 999 |
imgurl = jQuery(html).attr('src'); |
| 1000 |
iconurl = imgurl; |
| 1001 |
} |
| 1002 |
return {imgurl: imgurl, iconurl: iconurl}; |
| 1003 |
} |
| 1004 |
|
| 1005 |
vp.remove_upload_callback = function(e) { |
| 1006 |
var $this = jQuery(this), |
| 1007 |
$input = $this.parent('.buttons').prev('input'), |
| 1008 |
$preview = $this.parent('.buttons').siblings('.image').find('img'); |
| 1009 |
|
| 1010 |
$input.val(''); |
| 1011 |
$preview.attr('src', ''); |
| 1012 |
}; |
| 1013 |
|
| 1014 |
jQuery(document).on('click', '.vp-js-upload', vp.upload_callback); |
| 1015 |
jQuery(document).on('click', '.vp-js-remove-upload', vp.remove_upload_callback); |
| 1016 |
|
| 1017 |
vp.init_colorpicker = function($elements) |
| 1018 |
{ |
| 1019 |
if (jQuery.fn.colorpicker) |
| 1020 |
{ |
| 1021 |
if($elements.length <= 0) |
| 1022 |
return; |
| 1023 |
$elements.each(function() { |
| 1024 |
var $colorpicker = jQuery(this), |
| 1025 |
options = jQuery(this).getDatas(); |
| 1026 |
|
| 1027 |
options = vp.parseOpt(options.opt); |
| 1028 |
|
| 1029 |
$colorpicker.colorpicker({ |
| 1030 |
format: options.format |
| 1031 |
}).on('changeColor', function(ev){ |
| 1032 |
var color; |
| 1033 |
if(options.format == 'hex') |
| 1034 |
{ |
| 1035 |
color = ev.color.toHex(); |
| 1036 |
} |
| 1037 |
else if(options.format == 'rgba') |
| 1038 |
{ |
| 1039 |
color = ev.color.toRGB(); |
| 1040 |
color = 'rgba(' + color.r + ',' + color.g + ',' + color.b + ',' + color.a + ')'; |
| 1041 |
} |
| 1042 |
else if(options.format == 'rgb') |
| 1043 |
{ |
| 1044 |
color = ev.color.toRGB(); |
| 1045 |
color = 'rgb(' + color.r + ',' + color.g + ',' + color.b + ')'; |
| 1046 |
} |
| 1047 |
$colorpicker.prev('label').find('span').css('background-color', color); |
| 1048 |
}).on('blur', function(ev){ |
| 1049 |
$colorpicker.prev('label').find('span').css('background-color', $colorpicker.val()); |
| 1050 |
$colorpicker.keypress().keyup(); |
| 1051 |
}); |
| 1052 |
}); |
| 1053 |
} |
| 1054 |
}; |
| 1055 |
|
| 1056 |
vp.init_datepicker = function($elements) |
| 1057 |
{ |
| 1058 |
if (jQuery.fn.datepicker) |
| 1059 |
{ |
| 1060 |
if($elements.length <= 0) |
| 1061 |
return; |
| 1062 |
$elements.each(function() { |
| 1063 |
var options = jQuery(this).getDatas(); |
| 1064 |
options = vp.parseOpt(options.opt); |
| 1065 |
options.onSelect = function(){ |
| 1066 |
jQuery(this).trigger('keypress'); |
| 1067 |
jQuery(this).trigger('keyup'); |
| 1068 |
jQuery(this).trigger('blur'); |
| 1069 |
}; |
| 1070 |
jQuery(this).datepicker(options); |
| 1071 |
jQuery(this).datepicker('setDate', options.value); |
| 1072 |
}); |
| 1073 |
} |
| 1074 |
}; |
| 1075 |
|
| 1076 |
vp.init_controls = function($parent) |
| 1077 |
{ |
| 1078 |
// init date picker |
| 1079 |
vp.init_datepicker($parent.find('.vp-js-datepicker')); |
| 1080 |
vp.init_fontawesome_chooser($parent.find('.vp-js-fontawesome')); |
| 1081 |
vp.init_select2($parent.find('.vp-js-select2')); |
| 1082 |
vp.init_sorter($parent.find('.vp-js-sorter')); |
| 1083 |
vp.init_colorpicker($parent.find('.vp-js-colorpicker')); |
| 1084 |
vp.init_slider($parent.find('.vp-js-slider')); |
| 1085 |
vp.init_ace_editor($parent.find('.vp-js-codeeditor')); |
| 1086 |
vp.init_wpeditor($parent.find('.vp-js-wpeditor')); |
| 1087 |
}; |
| 1088 |
|
| 1089 |
// Fontawesome Chooser |
| 1090 |
vp.init_fontawesome_chooser = function($elements) |
| 1091 |
{ |
| 1092 |
if (jQuery.fn.select2) |
| 1093 |
{ |
| 1094 |
if($elements.length <= 0) |
| 1095 |
return; |
| 1096 |
var format = function vp_fontawesome_chooser_format(icon){ |
| 1097 |
return '<span class="fontawesome"><i class="fa ' + icon.id + '"></i>' + icon.text + '</span>'; |
| 1098 |
}; |
| 1099 |
$elements.select2({ |
| 1100 |
formatResult: format, |
| 1101 |
formatSelection: format, |
| 1102 |
escapeMarkup: function(m) { return m; }, |
| 1103 |
allowClear: true, |
| 1104 |
placeholder: vp_wp.ctrl_msg.fac_placeholder |
| 1105 |
}); |
| 1106 |
} |
| 1107 |
}; |
| 1108 |
|
| 1109 |
// Select2 |
| 1110 |
vp.init_select2 = function($elements) |
| 1111 |
{ |
| 1112 |
if (jQuery.fn.select2) |
| 1113 |
{ |
| 1114 |
if($elements.length <= 0) |
| 1115 |
return; |
| 1116 |
$elements.select2({allowClear: true, placeholder: vp_wp.ctrl_msg.select2_placeholder}); |
| 1117 |
} |
| 1118 |
}; |
| 1119 |
|
| 1120 |
// Sorter |
| 1121 |
vp.init_sorter = function($elements) |
| 1122 |
{ |
| 1123 |
if (jQuery.fn.select2Sortable) |
| 1124 |
{ |
| 1125 |
if($elements.length <= 0) |
| 1126 |
return; |
| 1127 |
|
| 1128 |
$elements.each(function(i, el) { |
| 1129 |
var $el = jQuery(el), |
| 1130 |
options = $el.getDatas(); |
| 1131 |
options = vp.parseOpt(options.opt); |
| 1132 |
$el.select2(options).select2Sortable({bindOrder: 'sortableStop'}); |
| 1133 |
}); |
| 1134 |
|
| 1135 |
} |
| 1136 |
}; |
| 1137 |
|
| 1138 |
// Tipsy |
| 1139 |
vp.init_tipsy = function() |
| 1140 |
{ |
| 1141 |
if (jQuery.fn.tipsy) |
| 1142 |
{ |
| 1143 |
jQuery('.vp-js-tipsy.description').tipsy({ live: true, gravity : 'e' }); |
| 1144 |
jQuery('.vp-js-tipsy.slideinput').tipsy({ live: true, trigger : 'focus' }); |
| 1145 |
jQuery('.vp-js-tipsy.image-item').tipsy({ live: true }); |
| 1146 |
} |
| 1147 |
}; |
| 1148 |
vp.init_tipsy(); |
| 1149 |
|
| 1150 |
// Init Sorter |
| 1151 |
vp.init_ace_editor = function($elements) |
| 1152 |
{ |
| 1153 |
if(window.ace !== 'undefined') |
| 1154 |
{ |
| 1155 |
if($elements.length <= 0) |
| 1156 |
return; |
| 1157 |
$elements.each(function() { |
| 1158 |
|
| 1159 |
var editor = ace.edit(jQuery(this).get(0)); |
| 1160 |
var textarea = jQuery(this).prev(); |
| 1161 |
var options = jQuery(this).getDatas(); |
| 1162 |
|
| 1163 |
options = vp.parseOpt(options.opt); |
| 1164 |
|
| 1165 |
editor.setTheme("ace/theme/" + options.theme); |
| 1166 |
editor.getSession().setMode("ace/mode/" + options.mode); |
| 1167 |
editor.getSession().setUseWrapMode( true ); |
| 1168 |
editor.setShowPrintMargin( false ); |
| 1169 |
|
| 1170 |
editor.getSession().setValue(textarea.val()); |
| 1171 |
editor.getSession().on('change', function(){ |
| 1172 |
textarea.val(editor.getSession().getValue()); |
| 1173 |
}); |
| 1174 |
textarea.on('change', function(){ |
| 1175 |
editor.getSession().setValue(textarea.val()); |
| 1176 |
}); |
| 1177 |
|
| 1178 |
}); |
| 1179 |
} |
| 1180 |
}; |
| 1181 |
|
| 1182 |
// Init WP TinyMCE Editor |
| 1183 |
if(typeof window.KIA_metabox !== 'undefined') |
| 1184 |
{ |
| 1185 |
KIA_metabox.mediaButtons(); |
| 1186 |
} |
| 1187 |
vp.init_wpeditor = function($elements) |
| 1188 |
{ |
| 1189 |
if(typeof window.KIA_metabox !== 'undefined') |
| 1190 |
{ |
| 1191 |
if($elements.length <= 0) |
| 1192 |
return; |
| 1193 |
KIA_metabox.runTinyMCE($elements); |
| 1194 |
} |
| 1195 |
}; |
| 1196 |
vp.tinyMCE_save = function() |
| 1197 |
{ |
| 1198 |
if(typeof window.tinyMCE !== 'undefined') |
| 1199 |
{ |
| 1200 |
tinyMCE.triggerSave(false, true); |
| 1201 |
} |
| 1202 |
}; |