ace
3 years ago
delete-confirm.js
3 years ago
editor.js
3 years ago
library.js
3 years ago
manager.js
2 years ago
plugin.js
3 years ago
library.js
451 lines
| 1 | //IntellyWP |
| 2 | var TCMP={}; |
| 3 | TCMP.startsWith=function(str, prefix) { |
| 4 | return str.indexOf(prefix) === 0; |
| 5 | } |
| 6 | TCMP.endsWith=function(str, suffix) { |
| 7 | var result=false; |
| 8 | var pos=str.lastIndexOf(suffix); |
| 9 | if(pos===(str.length-suffix.length+1)) { |
| 10 | result=true; |
| 11 | } |
| 12 | return result; |
| 13 | } |
| 14 | TCMP.stripos=function(haystack, needle, offset) { |
| 15 | var haystack=(haystack + '').toLowerCase(); |
| 16 | var needle=(needle + '').toLowerCase(); |
| 17 | var index=0; |
| 18 | |
| 19 | if ((index=haystack.indexOf(needle, offset))!==-1) { |
| 20 | return index; |
| 21 | } |
| 22 | return false; |
| 23 | }; |
| 24 | TCMP.strpos=function(haystack, needle, offset) { |
| 25 | var haystack=(haystack + ''); |
| 26 | var needle=(needle + ''); |
| 27 | var index=0; |
| 28 | |
| 29 | if ((index=haystack.indexOf(needle, offset))!==-1) { |
| 30 | return index; |
| 31 | } |
| 32 | return false; |
| 33 | }; |
| 34 | TCMP.val=function(name, defaults) { |
| 35 | defaults=(defaults || ''); |
| 36 | |
| 37 | var result=[]; |
| 38 | var $self=TCMP.jQuery(name); |
| 39 | if($self!==false) { |
| 40 | $self.each(function(i,v) { |
| 41 | var $this=jQuery(this); |
| 42 | var type=TCMP.attr($this, 'type', ''); |
| 43 | if(type=='checkbox') { |
| 44 | v=TCMP.check($this); |
| 45 | } else if(type=='radio') { |
| 46 | v=TCMP.radio($this); |
| 47 | } else { |
| 48 | v=$this.val(); |
| 49 | } |
| 50 | result.push(v); |
| 51 | }); |
| 52 | } |
| 53 | if(result.length==0 || (result.length==1 && result[0]===null)) { |
| 54 | result=defaults; |
| 55 | } else { |
| 56 | result=result.join('|'); |
| 57 | } |
| 58 | return result; |
| 59 | }; |
| 60 | TCMP.check=function(name) { |
| 61 | var $self=TCMP.jQuery(name); |
| 62 | return ($self.is(':checked') ? 1 : 0); |
| 63 | }; |
| 64 | TCMP.radio=function(name) { |
| 65 | var $self=TCMP.jQuery(name); |
| 66 | return ($self.filter(':checked').val()); |
| 67 | }; |
| 68 | TCMP.visible=function(name, visible) { |
| 69 | if(visible) { |
| 70 | jQuery(name).hide(); |
| 71 | } else { |
| 72 | jQuery(name).show(); |
| 73 | } |
| 74 | }; |
| 75 | TCMP.aval=function(name) { |
| 76 | var data={}; |
| 77 | jQuery("[name^='"+name+"']").each(function(i,v) { |
| 78 | var $this=jQuery(this); |
| 79 | var k=$this.attr('name'); |
| 80 | var v=$this.val(); |
| 81 | if($this.attr('type')=='checkbox') { |
| 82 | v=TCMP.check(k); |
| 83 | } else if($this.attr('type')=='radio') { |
| 84 | v=TCMP.radio(k); |
| 85 | } |
| 86 | data[k]=v; |
| 87 | }); |
| 88 | //console.log(data); |
| 89 | return data; |
| 90 | }; |
| 91 | TCMP.formatColorOption=function(option) { |
| 92 | if (!option.id) { |
| 93 | return option.text; |
| 94 | } |
| 95 | |
| 96 | var color=jQuery(option.element).css('background-color'); |
| 97 | var font=jQuery(option.element).css('color'); |
| 98 | var $option=jQuery('<div></div>') |
| 99 | .html(option.text) |
| 100 | .css('background-color', color) |
| 101 | .css('color', font) |
| 102 | .addClass('lbColorSelectItem'); |
| 103 | return $option; |
| 104 | }; |
| 105 | TCMP.hideShow=function(name) { |
| 106 | var $source=TCMP.jQuery(name); |
| 107 | if ($source.attr('ipfm-hideIfTrue') && $source.attr('ipfm-hideShow')) { |
| 108 | var $destination=jQuery('[name=' + $source.attr('ipfm-hideShow') + ']'); |
| 109 | if ($destination.length == 0) { |
| 110 | $destination=jQuery('#' + $source.attr('ipfm-hideShow')); |
| 111 | } |
| 112 | if ($destination.length > 0) { |
| 113 | var isChecked=$source.is(":checked"); |
| 114 | var hideIfTrue=($source.attr('ipfm-hideIfTrue').toLowerCase() == 'true'); |
| 115 | |
| 116 | if (isChecked) { |
| 117 | if (hideIfTrue) { |
| 118 | $destination.hide(); |
| 119 | } else { |
| 120 | $destination.show(); |
| 121 | } |
| 122 | } else { |
| 123 | if (hideIfTrue) { |
| 124 | $destination.show(); |
| 125 | } else { |
| 126 | $destination.hide(); |
| 127 | } |
| 128 | } |
| 129 | } |
| 130 | } |
| 131 | }; |
| 132 | TCMP.jQuery=function(name) { |
| 133 | var $self=name; |
| 134 | if(jQuery.type(name)=='string' || jQuery.type(name)=='array') { |
| 135 | $self=false; |
| 136 | var array=[]; |
| 137 | var names=[]; |
| 138 | switch (jQuery.type(name)) { |
| 139 | case 'string': |
| 140 | names=name.split('|'); |
| 141 | break; |
| 142 | case 'array': |
| 143 | names=name; |
| 144 | break; |
| 145 | } |
| 146 | jQuery.each(names, function(i,v) { |
| 147 | var selector='[name='+v+']'; |
| 148 | if(jQuery(selector).length>0) { |
| 149 | array.push(selector); |
| 150 | } else { |
| 151 | selector='#'+v; |
| 152 | if(jQuery(selector).length>0) { |
| 153 | array.push(selector); |
| 154 | } |
| 155 | } |
| 156 | }); |
| 157 | if(array.length>0) { |
| 158 | array=array.join(','); |
| 159 | $self=jQuery(array); |
| 160 | } |
| 161 | } |
| 162 | return $self; |
| 163 | } |
| 164 | TCMP.attr=function($self, name, v) { |
| 165 | $self=TCMP.jQuery($self); |
| 166 | var result=v; |
| 167 | if($self.length>0) { |
| 168 | result=$self.attr(name); |
| 169 | } |
| 170 | if ((typeof result === typeof undefined) || (result===false)) { |
| 171 | result=v; |
| 172 | } |
| 173 | return result; |
| 174 | }; |
| 175 | TCMP.select2=function($self, options) { |
| 176 | TCMP.destroy($self); |
| 177 | |
| 178 | var $self=TCMP.jQuery($self); |
| 179 | var name=$self.attr('name'); |
| 180 | var multiple=TCMP.attr($self, 'multiple', false); |
| 181 | if (multiple!==false) { |
| 182 | multiple=true; |
| 183 | } |
| 184 | |
| 185 | hasSelection=false; |
| 186 | if($self.html().indexOf('selected')>0) { |
| 187 | //jQuery fails if you dont have any selected item return the first |
| 188 | $self.find("option").each(function() { |
| 189 | var $option=jQuery(this); |
| 190 | if(TCMP.attr($option, 'selected', '')!='') { |
| 191 | hasSelection=true; |
| 192 | } |
| 193 | }); |
| 194 | } |
| 195 | |
| 196 | var help=TCMP.attr($self, 'ipfm-help', ''); |
| 197 | var ajax=TCMP.attr($self, 'ipfm-ajax', false); |
| 198 | var parent=TCMP.attr($self, 'ipfm-master', ''); |
| 199 | var settings={}; |
| 200 | if(ajax===false || ajax==='') { |
| 201 | settings={ |
| 202 | placeholder: help |
| 203 | , width: '100%' |
| 204 | , allowClear: true |
| 205 | } |
| 206 | } else { |
| 207 | settings={ |
| 208 | placeholder: help |
| 209 | , width: '100%' |
| 210 | , allowClear: true |
| 211 | , ajax: { |
| 212 | type: 'POST' |
| 213 | , dataType: 'json' |
| 214 | , delay: 250 |
| 215 | , data: function (params) { |
| 216 | var result={ |
| 217 | q: params.term |
| 218 | , page: params.page |
| 219 | , action: 'lb_ajax_ll' |
| 220 | , lb_action: ajax |
| 221 | }; |
| 222 | if(parent!='') { |
| 223 | result['parentId']=TCMP.val(parent); |
| 224 | } |
| 225 | return result; |
| 226 | } |
| 227 | , processResults: function (data, page) { |
| 228 | return {results: data}; |
| 229 | } |
| 230 | , cache: true |
| 231 | } |
| 232 | , minimumInputLength: 2 |
| 233 | } |
| 234 | } |
| 235 | settings=jQuery.extend(settings, options); |
| 236 | $self.select2(settings); |
| 237 | $self.hide(); |
| 238 | if(!hasSelection) { |
| 239 | $self.val(null).trigger('change'); |
| 240 | } |
| 241 | }; |
| 242 | TCMP.destroy=function($self) { |
| 243 | var name=$self.attr('name'); |
| 244 | try { |
| 245 | if($self.data('select2') != null) { |
| 246 | //TCMP.log('[%s] DESTROY SELECT2', name); |
| 247 | $self.select2("destroy"); |
| 248 | $self.html("<option><option>"); |
| 249 | $self.val('').trigger('change'); |
| 250 | } |
| 251 | } catch(ex) {} |
| 252 | }; |
| 253 | TCMP.inArray=function(v, array) { |
| 254 | var result=false; |
| 255 | if(!array || !jQuery.isArray(array) || array.length==0) { |
| 256 | if(jQuery.type(array)=='string' && v==array) { |
| 257 | result=true; |
| 258 | } |
| 259 | } else { |
| 260 | for(i=0; i<array.length; i++) { |
| 261 | c=array[i]; |
| 262 | if(v==c) { |
| 263 | result=true; |
| 264 | break; |
| 265 | } |
| 266 | } |
| 267 | } |
| 268 | return result; |
| 269 | } |
| 270 | TCMP.changeShowOptions=function($self) { |
| 271 | var selection=$self.val(); |
| 272 | var name=TCMP.attr($self, 'name', ''); |
| 273 | var $options=$self.children('option'); |
| 274 | //console.log('NAME=[%s] OPTIONS=N.%s', name, $options.length); |
| 275 | var toShow={}; |
| 276 | var toHide={}; |
| 277 | $options.each(function(i,v) { |
| 278 | $option=jQuery(v); |
| 279 | var text=TCMP.attr($option, 'show', ''); |
| 280 | if(text!='') { |
| 281 | text=text.split('|'); |
| 282 | var j=0; |
| 283 | for(j=0; j<text.length; j++) { |
| 284 | var show=text[j]; |
| 285 | var $show=jQuery('#'+show); |
| 286 | if($show.length>0) { |
| 287 | var value=TCMP.attr($option, 'value', ''); |
| 288 | if(TCMP.inArray(value, selection)) { |
| 289 | toShow[show]=show; |
| 290 | } else { |
| 291 | toHide[show]=show; |
| 292 | } |
| 293 | } else { |
| 294 | console.log('changeShowOptions ID=[%s] NOT FOUND', show); |
| 295 | } |
| 296 | } |
| 297 | } |
| 298 | }); |
| 299 | |
| 300 | jQuery.each(toShow, function(k,v) { |
| 301 | delete toHide[k]; |
| 302 | var $w=jQuery('#'+k); |
| 303 | $w.show(); |
| 304 | }); |
| 305 | jQuery.each(toHide, function(k,v) { |
| 306 | var $w=jQuery('#'+k); |
| 307 | $w.hide(); |
| 308 | }); |
| 309 | } |
| 310 | TCMP.setCookie=function(name,value,days) { |
| 311 | name='TCMP_'+name; |
| 312 | if (days) { |
| 313 | var date = new Date(); |
| 314 | date.setTime(date.getTime()+(days*24*60*60*1000)); |
| 315 | var expires = "; expires="+date.toGMTString(); |
| 316 | } |
| 317 | else var expires = ""; |
| 318 | document.cookie = name+"="+value+expires+"; path=/"; |
| 319 | } |
| 320 | TCMP.getCookie=function(name) { |
| 321 | name='TCMP_'+name; |
| 322 | var nameEQ = name + "="; |
| 323 | var ca = document.cookie.split(';'); |
| 324 | for(var i=0;i < ca.length;i++) { |
| 325 | var c = ca[i]; |
| 326 | while (c.charAt(0)==' ') c = c.substring(1,c.length); |
| 327 | if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); |
| 328 | } |
| 329 | return null; |
| 330 | } |
| 331 | TCMP.removeCookie=function(name) { |
| 332 | createCookie(name,"",-1); |
| 333 | } |
| 334 | TCMP.getDateCookie=function(name) { |
| 335 | var result=TCMP.getCookie(name); |
| 336 | if(result!==null) { |
| 337 | //console.log('getDateCookie RESULT=%s', result); |
| 338 | result=moment(result).toDate(); |
| 339 | //console.log('getDateCookie MOMENT=%s', result); |
| 340 | } |
| 341 | return result; |
| 342 | } |
| 343 | TCMP.setDateCookie=function(name, value, days) { |
| 344 | if(value!==null && value!=='') { |
| 345 | //console.log('setDateCookie RESULT=%s', value); |
| 346 | value=moment(value).format(); |
| 347 | //console.log('setDateCookie MOMENT=%s', value); |
| 348 | } |
| 349 | TCMP.setCookie(name, value, days); |
| 350 | } |
| 351 | TCMP.formatTimer=function(time) { |
| 352 | if(!(time+'').match(/^\d+$/)) { |
| 353 | if(jQuery.type(time)=='string') { |
| 354 | time=time.replace(' ', ':'); |
| 355 | time=time.replace('.', ':'); |
| 356 | time=time.replace('/', ':'); |
| 357 | time=time.split(':'); |
| 358 | |
| 359 | days=0; |
| 360 | hours=0; |
| 361 | minutes=0; |
| 362 | var length=time.length; |
| 363 | secs=parseInt(time[length-1]); |
| 364 | if(length>1) { |
| 365 | minutes=parseInt(time[length-2]); |
| 366 | if(length>2) { |
| 367 | hours=parseInt(time[length-3]); |
| 368 | if(length>3) { |
| 369 | days=parseInt(time[length-4]); |
| 370 | } |
| 371 | } |
| 372 | } |
| 373 | days=(isNaN(days) ? 0 : days); |
| 374 | hours=(isNaN(hours) ? 0 : hours); |
| 375 | minutes=(isNaN(minutes) ? 0 : minutes); |
| 376 | secs=(isNaN(secs) ? 0 : secs); |
| 377 | time=days*86400+hours*3600+minutes*60+secs; |
| 378 | } else { |
| 379 | time=0; |
| 380 | } |
| 381 | } else { |
| 382 | time=parseInt(time); |
| 383 | } |
| 384 | |
| 385 | secs=time%60; |
| 386 | time=(time-secs)/60; |
| 387 | minutes=time%60; |
| 388 | time=(time-minutes)/60; |
| 389 | hours=time%24; |
| 390 | days=(time-hours)/24; |
| 391 | |
| 392 | result=[]; |
| 393 | result.push(days); |
| 394 | result.push((hours<10 ? '0' : '')+hours); |
| 395 | result.push((minutes<10 ? '0' : '')+minutes); |
| 396 | result.push((secs<10 ? '0' : '')+secs); |
| 397 | result=result.join(':'); |
| 398 | return result; |
| 399 | } |
| 400 | TCMP.parseTimer=function(time) { |
| 401 | time=TCMP.formatTimer(time); |
| 402 | time=time.split(':'); |
| 403 | result=parseInt(time[0])*86400+parseInt(time[1])*3600+parseInt(time[2])*60+parseInt(time[3]); |
| 404 | return result; |
| 405 | } |
| 406 | TCMP.isTrue=function(value) { |
| 407 | var result=false; |
| 408 | if(value===true) { |
| 409 | result=true; |
| 410 | } else if(value===false) { |
| 411 | result=false; |
| 412 | } else { |
| 413 | value=(value+'').toLowerCase(); |
| 414 | result=(value=='yes' || value=='true' || value=='1'); |
| 415 | } |
| 416 | return result; |
| 417 | } |
| 418 | TCMP.getFixedHeaders=function(value) { |
| 419 | //if we can't find it with selectors, the loop through every element |
| 420 | //in <body> - stopping once we find a position:fixed element and return that. |
| 421 | var $headers=[]; |
| 422 | var $this; |
| 423 | jQuery('html div').each(function() { |
| 424 | $this=jQuery(this); |
| 425 | if($this.css('position')=='fixed') { |
| 426 | $headers.push($this); |
| 427 | } |
| 428 | }); |
| 429 | /*if(jQuery('#blackbox-web-debug').length>0) { |
| 430 | $this=jQuery('#blackbox-web-debug'); |
| 431 | $headers.push($this); |
| 432 | }*/ |
| 433 | return $headers; |
| 434 | } |
| 435 | TCMP.parseInt=function(value, defaultValue) { |
| 436 | defaultValue=(defaultValue || 0); |
| 437 | value=parseInt(value); |
| 438 | if(isNaN(value)) { |
| 439 | value=defaultValue; |
| 440 | } |
| 441 | return value; |
| 442 | } |
| 443 | TCMP.replace=function(target, search, replacement) { |
| 444 | try { |
| 445 | return target.split(search).join(replacement); |
| 446 | } catch (e) { |
| 447 | if (e) { |
| 448 | return target; |
| 449 | } |
| 450 | } |
| 451 | } |