").text(e.text);return void 0!==e.icon&&e.icon&&(t.prepend(a('

')),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=a("
").text(e.text);return a.isNumeric(e.id)&&e.text.indexOf("icon-users")<0&&t.append(a('')),t},allowClear:!0,placeholder:s.data("placeholder")}).on("change",function(){var e=a(this).select2("data");a(this).data("selected-id",e.id),a(this).data("selected-text",e.text)})}),a("select.select2-select.ip_address",e).each(function(e,t){var s=a(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&&a.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=a.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(){a(this).prev(".select2-container").find("input.select2-input").blur()}),a("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=a(this).closest(".select2-container"),t=e.find("input.select2-input");if(1<=e.select2("data").length)return t.blur(),!1}),a(".exclude_rules_remove_rule_row",e).on("click",function(e){a(this).closest("tr").remove(),i(),n(),e.preventDefault()})}var e=a(".stream-exclude-list tbody tr:not(.hidden)"),s=a(".stream-exclude-list tr.helper");function n(){var e=a("table.stream-exclude-list tbody tr:not( .hidden ) input.cb-select:checked"),t=a("#exclude_rules_remove_rules");0===e.length?t.prop("disabled",!0):t.prop("disabled",!1)}function i(){var e=a("table.stream-exclude-list tbody tr:not( .hidden )"),t=a("table.stream-exclude-list tbody tr.no-items"),s=a(".check-column.manage-column input.cb-select"),n=a("#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),a("select.select2-select.author_or_role",e).each(function(){var e=a("").val(a(this).data("selected-id"));a(this).append(e).trigger("change")}),a("select.select2-select.connector_or_context",e).each(function(){var e=[a(this).siblings(".connector").val(),a(this).siblings(".context").val()];""===e[1]&&e.splice(1,1),a(this).val(e.join("-")).trigger("change")}),a("#exclude_rules_new_rule").on("click",function(){var e=s.clone();e.removeAttr("class"),e.insertBefore(s),t(e),i(),n()}),a("#exclude_rules_remove_rules").on("click",function(){var e=a("table.stream-exclude-list"),t=a("tbody input.cb-select:checked",e).closest("tr");2<=a("tbody tr",e).length-t.length?t.remove():(a(":input",t).val(""),a(t).not(":first").remove(),a(".select2-select",t).select2("val","")),e.find("input.cb-select").prop("checked",!1),i(),n()}),a(".stream-exclude-list").closest("form").submit(function(){a(".stream-exclude-list tbody tr.hidden",this).each(function(){a(this).find(":input").removeAttr("name")}),a(".stream-exclude-list tbody tr:not(.hidden) select.select2-select.connector_or_context",this).each(function(){var e=a(this).val().split("-");a(this).siblings(".connector").val(e[0]),a(this).siblings(".context").val(e[1]),a(this).removeAttr("name")}),a(".stream-exclude-list tbody tr:not(.hidden) select.select2-select.ip_address",this).each(function(){var e=a("option:selected",this).first();e.length||a(this).append(''),a("option:selected:not(:first)",this).each(function(){e.attr("value",e.attr("value")+","+a(this).attr("value")),a(this).removeAttr("selected")})})}),a(".stream-exclude-list").closest("td").prev("th").hide(),a("table.stream-exclude-list").on("click","input.cb-select",function(){n()}),a(document).ready(function(){i(),n()})});