define(["jquery"],function(a){var b;return b={CSS:{SELECTALLPOST:'button[name="oublog-export-select-all"]',SELECTNONE:'button[name="oublog-export-select-none"]',CHECKBOXS:'.oublog-posts-table input[type="checkbox"]',EXPORTSELECTED:'button[name="oublog-export-selected"]',EXPORTTYPE:"#oublog-export-type"},mconfig:null,contentIds:[],init:function(c){b.mconfig=c,null!==sessionStorage.getItem("contentIds")&&b.mconfig.newsession!==!0&&(b.contentIds=JSON.parse(sessionStorage.getItem("contentIds"))),a(b.CSS.SELECTALLPOST).on("click",b.selectAll.bind(b)),a(b.CSS.SELECTNONE).on("click",b.selectNone.bind(b)),a(b.CSS.CHECKBOXS).on("click",b.selectPost.bind(b)),a(b.CSS.EXPORTSELECTED).on("click",b.exportSelected.bind(b)),b.initSelectedPost(),b.initButtonState()},selectAll:function(){a(b.CSS.CHECKBOXS).prop("checked",!0),a(b.CSS.SELECTALLPOST).prop("disabled",!0),a(b.CSS.SELECTALLPOST).blur(),a(b.CSS.SELECTNONE).prop("disabled",!1),a(b.CSS.EXPORTSELECTED).prop("disabled",!1),a(b.CSS.CHECKBOXS).each(function(){a(this).prop("checked")&&b.addPost(a(this).val())})},selectNone:function(){a(b.CSS.CHECKBOXS).prop("checked",!1),a(b.CSS.SELECTALLPOST).prop("disabled",!1),a(b.CSS.SELECTNONE).prop("disabled",!0),a(b.CSS.SELECTNONE).blur(),a(b.CSS.EXPORTSELECTED).prop("disabled",!0),a(b.CSS.CHECKBOXS).each(function(){a(this).prop("checked")||b.removePost(a(this).val())})},selectPost:function(a){1==a.target.checked?b.addPost(a.target.value):b.removePost(a.target.value),b.initButtonState()},initSelectedPost:function(){a(b.CSS.CHECKBOXS).each(function(){var c=b.contentIds.indexOf(a(this).val());c!==-1&&a(this).prop("checked",!0)})},exportSelected:function(){if(b.contentIds.length>0){var c=a(b.CSS.EXPORTSELECTED).data("url"),d=a(b.CSS.EXPORTTYPE).val();c=this.updateQueryStringParameter(c,"instance",String(d)),c=this.updateQueryStringParameter(c,"ca_postids",b.contentIds.join("|")),sessionStorage.removeItem("contentIds"),b.contentIds=[],window.location.href=c}},removePost:function(a){var c=b.contentIds.indexOf(a);c!==-1&&(b.contentIds.splice(c,1),sessionStorage.setItem("contentIds",JSON.stringify(b.contentIds)))},addPost:function(a){var c=b.contentIds.indexOf(a);c===-1&&(b.contentIds.push(a),sessionStorage.setItem("contentIds",JSON.stringify(b.contentIds)))},initButtonState:function(){var c=0,d=0;a(b.CSS.CHECKBOXS).each(function(){0==a(this).prop("checked")&&c++,d++}),a(b.CSS.SELECTALLPOST).prop("disabled",0==c),a(b.CSS.SELECTNONE).prop("disabled",c==d),a(b.CSS.EXPORTSELECTED).prop("disabled",0==b.contentIds.length)},updateQueryStringParameter:function(a,b,c){var d=new RegExp("([?&])"+b+"=.*?(&|$)","i"),e=a.indexOf("?")!==-1?"&":"?";return a.match(d)?a.replace(d,"$1"+b+"="+c+"$2"):a+e+b+"="+c}}});
