| 1 |
function gamipress_selector($this){if($this.closest('#available-widgets').length) |
| 2 |
return;var select2_args={theme:'default gamipress-select2',placeholder:($this.data('placeholder')?$this.data('placeholder'):gamipress_admin_functions.selector_placeholder),allowClear:!0,multiple:($this[0].hasAttribute('multiple')),matcher:gamipress_select2_words_matcher,};$this.gamipress_select2(select2_args)} |
| 3 |
function gamipress_post_selector($this){if($this.closest('#available-widgets').length) |
| 4 |
return;var select2_args={ajax:{url:ajaxurl,dataType:'json',delay:250,type:'POST',data:function(params){return{q:params.term,page:params.page||1,action:($this.data('action')?$this.data('action'):'gamipress_get_posts'),nonce:gamipress_admin_functions.nonce,post_type:$this.data('post-type').split(','),}},processResults:gamipress_select2_posts_process_results},escapeMarkup:function(markup){return markup},templateResult:gamipress_select2_posts_template_result,theme:'default gamipress-select2',placeholder:($this.data('placeholder')?$this.data('placeholder'):gamipress_admin_functions.post_selector_placeholder),allowClear:!0,multiple:($this[0].hasAttribute('multiple')),matcher:gamipress_select2_words_matcher,};$this.gamipress_select2(select2_args)} |
| 5 |
function gamipress_user_selector($this){if($this.closest('#available-widgets').length) |
| 6 |
return;var select2_args={ajax:{url:ajaxurl,dataType:'json',delay:250,type:'POST',data:function(params){return{q:params.term,page:params.page||1,action:'gamipress_get_users',nonce:gamipress_admin_functions.nonce,}},processResults:gamipress_select2_users_process_results},escapeMarkup:function(markup){return markup},templateResult:gamipress_select2_users_template_result,theme:'default gamipress-select2',placeholder:($this.data('placeholder')?$this.data('placeholder'):gamipress_admin_functions.user_selector_placeholder),allowClear:!0,multiple:($this[0].hasAttribute('multiple')),matcher:gamipress_select2_words_matcher,};$this.gamipress_select2(select2_args)} |
| 7 |
function gamipress_select2_destroy($this,clear_options=!1){$this.removeAttr('data-select2-id');$this.removeData('data-hash');$this.next('.select2').remove();if(clear_options){$this.find('option').remove()}} |
| 8 |
function gamipress_select2_posts_template_result(item){if(item.post_parent_title!==undefined){return gamipress_select2_post_parent_template_result(item)} |
| 9 |
if(item.post_type!==undefined){var post_type_label=item.post_type;if(gamipress_post_type_exists(item.post_type)){post_type_label=gamipress_get_post_type_label(item.post_type)} |
| 10 |
return '<strong>'+item.post_title+'</strong>'+'<span class="result-description">'+'ID: '+item.ID+'<span class="align-right">'+post_type_label+'</span>'+(item.site_name!==undefined?' ('+item.site_name+')':'')+'</span>'} |
| 11 |
return item.text} |
| 12 |
function gamipress_select2_post_parent_template_result(item){if(item.post_parent_type!==undefined){var post_type_label=item.post_parent_type;if(item.post_parent_type==='points-type'){post_type_label=''}else if(gamipress_post_type_exists(item.post_parent_type)){post_type_label=gamipress_get_post_type_label(item.post_parent_type);post_type_label+=':'} |
| 13 |
return '<strong>'+item.post_title+'</strong>'+'<span class="result-description">'+'ID: '+item.ID+'<span class="align-right">'+post_type_label+' '+item.post_parent_title+'</span>'+(item.site_name!==undefined?' ('+item.site_name+')':'')+'</span>'} |
| 14 |
return item.text} |
| 15 |
function gamipress_select2_posts_process_results(response,params){if(response===null){return{results:[]}} |
| 16 |
var formatted_results=[];var results=(response.data.results!==undefined?response.data.results:response.data);results.forEach(function(item){formatted_results.push(jQuery.extend({id:item.ID,text:item.post_title+' (#'+item.ID+')',},item))});return{results:formatted_results,pagination:{more:(response.data.more_results!==undefined?response.data.more_results:!1)}}} |
| 17 |
function gamipress_select2_users_template_result(item){if(item.display_name!==undefined){return '<strong>'+item.display_name+'</strong>'+'<span class="result-description">'+'ID: '+item.ID+' - '+item.user_email+' ('+item.user_login+')'+'</span>'} |
| 18 |
return item.text} |
| 19 |
function gamipress_select2_users_process_results(response,params){if(response===null){return{results:[]}} |
| 20 |
var formatted_results=[];var results=(response.data.results!==undefined?response.data.results:response.data);results.forEach(function(item){formatted_results.push(jQuery.extend({id:item.ID,text:item.user_login+' (#'+item.ID+')',},item))});return{results:formatted_results,pagination:{more:(response.data.more_results!==undefined?response.data.more_results:!1)}}} |
| 21 |
function gamipress_matches_by_word(text,term){text=text.toUpperCase();var words=term.toUpperCase().split(" ");var found=!0;for(var i=0;i<words.length;i++) |
| 22 |
found=(found&&text.indexOf(words[i])>=0);return found} |
| 23 |
function gamipress_select2_words_matcher(params,data){if(params.term===undefined||params.term.trim()==='')return data;if(gamipress_matches_by_word(data.text,params.term))return data;return null} |
| 24 |
function gamipress_select2_optgroup_matcher(params,data){data.parentText=data.parentText||'';if(params.term===undefined||params.term.trim()==='')return data;if(data.children&&data.children.length>0){var match=jQuery.extend(!0,{},data);for(var c=data.children.length-1;c>=0;c--){var child=data.children[c];child.parentText+=data.parentText+" "+data.text;var matches=gamipress_select2_optgroup_matcher(params,child);if(matches==null){match.children.splice(c,1)}} |
| 25 |
if(match.children.length>0){return match} |
| 26 |
return gamipress_select2_optgroup_matcher(params,match)} |
| 27 |
if(gamipress_matches_by_word((data.parentText+' '+data.text),params.term))return data;return null} |
| 28 |
function gamipress_post_type_exists(post_type){return(gamipress_admin_functions.post_type_labels[post_type]!==undefined)} |
| 29 |
function gamipress_get_post_type_label(post_type){var label='';if(gamipress_post_type_exists(post_type)){label=gamipress_admin_functions.post_type_labels[post_type]} |
| 30 |
return label} |
| 31 |
function gamipress_is_reserved_term(term){return(gamipress_admin_functions.reserved_terms.indexOf(term)!==-1)} |
| 32 |
function gamipress_get_slug_error(slug,current_slug){if(/[^a-zA-Z0-9\-_]/.test(slug)) |
| 33 |
return gamipress_admin_functions.slug_error_special_char;if(slug.length>20) |
| 34 |
return gamipress_admin_functions.slug_error_max_length;if(gamipress_post_type_exists(slug)&&slug!==current_slug) |
| 35 |
return gamipress_admin_functions.slug_error_post_type.replace('%s',gamipress_get_post_type_label(slug));if(gamipress_is_reserved_term(slug)) |
| 36 |
return gamipress_admin_functions.slug_error_reserved_term;return ''} |
| 37 |
function gamipress_download_csv(data,filename){var csv=gamipress_object_to_csv(data);gamipress_download_file(csv,filename,'csv')} |
| 38 |
function gamipress_download_file(content,filename,extension,mime_type='',charset=''){if(mime_type===undefined||mime_type==='') |
| 39 |
mime_type='text/'+extension;if(charset===undefined||charset==='') |
| 40 |
charset='utf-8';var file=(filename.length?filename+'.'+extension:'file.'+extension);var blob=new Blob([content],{type:mime_type+';charset='+charset+';'});if(navigator.msSaveBlob){navigator.msSaveBlob(blob,file)}else{var link=document.createElement("a");link.style.visibility='hidden';if(link.download!==undefined){var url=URL.createObjectURL(blob);link.setAttribute("href",url);link.setAttribute("download",file);document.body.appendChild(link);link.click();document.body.removeChild(link)}}} |
| 41 |
function gamipress_object_to_csv(obj){var array=typeof obj!=='object'?JSON.parse(obj):obj;var str='';for(var i=0;i<array.length;i++){var line='';for(var index in array[i]){if(line!==''){line+=','} |
| 42 |
line+='"'+array[i][index]+'"'} |
| 43 |
str+=line+'\r\n'} |
| 44 |
return str} |
| 45 |
function gamipress_get_url_param(url,param,default_value=!1){var results=new RegExp('[\?&]'+param+'=([^&#]*)').exec(url);return results[1]||default_value} |
| 46 |
function gamipress_is_valid_url(url){var result=url.match(/(http(s)?:\/\/.)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/g);return(result!==null)} |
| 47 |
function gamipress_strip_scripts(s){var div=document.createElement('div');div.innerHTML=s;var scripts=div.getElementsByTagName('script');var i=scripts.length;while(i--){scripts[i].parentNode.removeChild(scripts[i])} |
| 48 |
return div.innerHTML} |