| 1 |
jQuery(function(r){function t(e){var s;r("select.select2-select.connector_or_context",e).each(function(e,t){r(t).select2({allowClear:!0,templateResult:function(e){return void 0===e.id?e.text:-1===e.id.indexOf("-")?r('<span class="parent">'+e.text+"</span>"):r('<span class="child">'+e.text+"</span>")},matcher:function(e,t){var s=r.extend(!0,{},t);if(null===e.term||""===r.trim(e.term))return s;var n=e.term.toLowerCase();if(s.id=s.id.replace("blogs","sites"),0<=s.id.toLowerCase().indexOf(n))return s;if(s.children){for(var i=s.children.length-1;0<=i;i--)-1===s.children[i].id.toLowerCase().indexOf(n)&&s.children.splice(i,1);if(0<s.children.length)return s}return null}}).on("change",function(){var e=r(this).closest("tr"),t=r(this).val();!function(e,t){var l=r(".select2-select.action",e),c=l.val();l.empty(),l.prop("disabled",!0);e=r("<option/>",{value:"",text:""});l.append(e);t={action:"get_actions",connector:t};r.post(window.ajaxurl,t,function(e){var t,s=e.success,n=e.data;if(s){for(var i in n)n.hasOwnProperty(i)&&(t=n[i],t=r("<option/>",{value:i,text:t}),l.append(t));l.val(c),l.prop("disabled",!1),r(document).trigger("alert-actions-updated")}})}(e,t=t&&0<t.indexOf("-")?t.split("-")[0]:t)})}),r("select.select2-select.action",e).each(function(e,t){r(t).select2({allowClear:!0})}),r("select.select2-select.author_or_role",e).each(function(e,t){(s=r(t)).select2({ajax:{type:"POST",url:ajaxurl,dataType:"json",quietMillis:500,data:function(e,t){return{find:e,limit:10,pager:t,action:"stream_get_users",nonce:s.data("nonce")}},processResults:function(e){var t={results:[{text:"",id:""},{text:"Roles",children:[]},{text:"Users",children:[]}]};if(!0!==e.success||void 0===e.data||!0!==e.data.status)return t;if(void 0===e.data.users||void 0===e.data.roles)return t;var s=[];return r.each(e.data.roles,function(e,t){s.push({id:e,text:t})}),t.results[1].children=s,t.results[2].children=e.data.users,t}},templateResult:function(e){var t=r("<div>").text(e.text);return void 0!==e.icon&&e.icon&&(t.prepend(r('<img src="'+e.icon+'" class="wp-stream-select2-icon">')),t.attr("title",e.tooltip)),void 0!==e.tooltip?t.attr("title",e.tooltip):void 0!==e.user_count&&t.attr("title",e.user_count),t},templateSelection:function(e){var t=r("<div>").text(e.text);return r.isNumeric(e.id)&&e.text.indexOf("icon-users")<0&&t.append(r('<i class="icon16 icon-users"></i>')),t},allowClear:!0,placeholder:s.data("placeholder")}).on("change",function(){var e=r(this).select2("data");r(this).data("selected-id",e.id),r(this).data("selected-text",e.text)})}),r("select.select2-select.ip_address",e).each(function(e,t){var s=r(t),n="";s.select2({ajax:{type:"POST",url:ajaxurl,dataType:"json",quietMillis:500,data:function(e){return n=e.term,{find:e,limit:10,action:"stream_get_ips",nonce:s.data("nonce")}},processResults:function(e){var s={results:[]},t=[];return!0===e.success&&void 0!==e.data&&r.each(e.data,function(e,t){s.results.push({id:t,text:t})}),void 0===n||null===(t=n.match(/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/))||(t.shift(),4<=(t=r.grep(t,function(e){var t=parseInt(e,10);return t<=255&&t.toString()===e})).length&&s.results.push({id:n,text:n})),s}},allowClear:!1,multiple:!0,maximumSelectionSize:1,placeholder:s.data("placeholder"),tags:!0})}).on("change",function(){r(this).prev(".select2-container").find("input.select2-input").blur()}),r("ul.select2-choices, ul.select2-choices li, input.select2-input",".stream-exclude-list tr:not(.hidden) .ip_address").on("mousedown click focus",function(){var e=r(this).closest(".select2-container"),t=e.find("input.select2-input");if(1<=e.select2("data").length)return t.blur(),!1}),r(".exclude_rules_remove_rule_row",e).on("click",function(e){r(this).closest("tr").remove(),i(),n(),e.preventDefault()})}var e=r(".stream-exclude-list tbody tr:not(.hidden)"),s=r(".stream-exclude-list tr.helper");function n(){var e=r("table.stream-exclude-list tbody tr:not( .hidden ) input.cb-select:checked"),t=r("#exclude_rules_remove_rules");0===e.length?t.prop("disabled",!0):t.prop("disabled",!1)}function i(){var e=r("table.stream-exclude-list tbody tr:not( .hidden )"),t=r("table.stream-exclude-list tbody tr.no-items"),s=r(".check-column.manage-column input.cb-select"),n=r("#exclude_rules_remove_rules");0===e.length?(t.show(),s.prop("disabled",!0),n.prop("disabled",!0)):(t.hide(),s.prop("disabled",!1)),wp_stream_regenerate_alt_rows(e)}t(e),r("select.select2-select.author_or_role",e).each(function(){var e=r("<option selected>"+r(this).data("selected-text")+"</option>").val(r(this).data("selected-id"));r(this).append(e).trigger("change")}),r("select.select2-select.connector_or_context",e).each(function(){var e=[r(this).siblings(".connector").val(),r(this).siblings(".context").val()];""===e[1]&&e.splice(1,1),r(this).val(e.join("-")).trigger("change")}),r("#exclude_rules_new_rule").on("click",function(){var e=s.clone();e.removeAttr("class"),e.insertBefore(s),t(e),i(),n()}),r("#exclude_rules_remove_rules").on("click",function(){var e=r("table.stream-exclude-list"),t=r("tbody input.cb-select:checked",e).closest("tr");2<=r("tbody tr",e).length-t.length?t.remove():(r(":input",t).val(""),r(t).not(":first").remove(),r(".select2-select",t).select2("val","")),e.find("input.cb-select").prop("checked",!1),i(),n()}),r(".stream-exclude-list").closest("form").submit(function(){r(".stream-exclude-list tbody tr.hidden",this).each(function(){r(this).find(":input").removeAttr("name")}),r(".stream-exclude-list tbody tr:not(.hidden) select.select2-select.connector_or_context",this).each(function(){var e=r(this).val().split("-");r(this).siblings(".connector").val(e[0]),r(this).siblings(".context").val(e.slice(1).join("-")),r(this).removeAttr("name")}),r(".stream-exclude-list tbody tr:not(.hidden) select.select2-select.ip_address",this).each(function(){var e=r("option:selected",this).first();e.length||r(this).append('<option selected="selected"></option>'),r("option:selected:not(:first)",this).each(function(){e.attr("value",e.attr("value")+","+r(this).attr("value")),r(this).removeAttr("selected")})})}),r(".stream-exclude-list").closest("td").prev("th").hide(),r("table.stream-exclude-list").on("click","input.cb-select",function(){n()}),r(document).ready(function(){i(),n()})}); |