From cc68ab15219d77f20b8257e483bf4b0e76c49b43 Mon Sep 17 00:00:00 2001 From: Boris Gulay Date: Sat, 10 Nov 2018 18:32:44 +0300 Subject: [PATCH] JS optimizations. --- ident_switch-form.js | 31 +++++++++++++++++++++++++++++ ident_switch-form.min.js | 2 +- ident_switch-switch.js | 40 +++----------------------------------- ident_switch-switch.min.js | 16 +-------------- 4 files changed, 36 insertions(+), 53 deletions(-) diff --git a/ident_switch-form.js b/ident_switch-form.js index 874ca60..abad3a8 100644 --- a/ident_switch-form.js +++ b/ident_switch-form.js @@ -8,3 +8,34 @@ $(function() { plugin_switchIdent_processPreconfig(); }); +function plugin_switchIdent_processPreconfig() { + var disFld = $("INPUT[name='_ident_switch.form.readonly']"); + disFld.parentsUntil("TABLE", "TR").hide(); + + var disVal = disFld.val(); + if (disVal > 0) { + $("INPUT[name='_ident_switch.form.host']").prop("disabled", true); + $("SELECT[name='_ident_switch.form.secure']").prop("disabled", true); + $("INPUT[name='_ident_switch.form.port']").prop("disabled", true); + } + if (2 == disVal) { + $("INPUT[name='_ident_switch.form.username']").prop("disabled", true); + } + +} + +function plugin_switchIdent_enabled_onChange(e) { + var $enFld = $("INPUT[name='_ident_switch.form.enabled']"); + $("INPUT[name!='_ident_switch.form.enabled'], SELECT", $enFld.parents("FIELDSET")).prop("disabled", !$enFld.is(":checked")); + plugin_switchIdent_processPreconfig(); +} + +function plugin_switchIdent_secure_onChange(e) { + var $secSel = $("SELECT[name='_ident_switch.form.secure']"); + var $portFld = $("INPUT[name='_ident_switch.form.port']"); + + if ('SSL' === $secSel.val().toUpperCase()) + $portFld.attr("placeholder", 993); + else + $portFld.attr("placeholder", 143); +} \ No newline at end of file diff --git a/ident_switch-form.min.js b/ident_switch-form.min.js index 5715279..5f76dbe 100644 --- a/ident_switch-form.min.js +++ b/ident_switch-form.min.js @@ -1 +1 @@ -$(function(){$("INPUT[name='_ident_switch.form.enabled']").change();$("SELECT[name='_ident_switch.form.secure']").change();plugin_switchIdent_processPreconfig();}); \ No newline at end of file +$(function(){$("INPUT[name='_ident_switch.form.enabled']").change();$("SELECT[name='_ident_switch.form.secure']").change();plugin_switchIdent_processPreconfig()});function plugin_switchIdent_processPreconfig(){var a=$("INPUT[name='_ident_switch.form.readonly']");a.parentsUntil("TABLE","TR").hide();var b=a.val();if(b>0){$("INPUT[name='_ident_switch.form.host']").prop("disabled",true);$("SELECT[name='_ident_switch.form.secure']").prop("disabled",true);$("INPUT[name='_ident_switch.form.port']").prop("disabled",true)}if(2==b){$("INPUT[name='_ident_switch.form.username']").prop("disabled",true)}}function plugin_switchIdent_enabled_onChange(a){var b=$("INPUT[name='_ident_switch.form.enabled']");$("INPUT[name!='_ident_switch.form.enabled'], SELECT",b.parents("FIELDSET")).prop("disabled",!b.is(":checked"));plugin_switchIdent_processPreconfig()}function plugin_switchIdent_secure_onChange(c){var b=$("SELECT[name='_ident_switch.form.secure']");var a=$("INPUT[name='_ident_switch.form.port']");if("SSL"===b.val().toUpperCase()){a.attr("placeholder",993)}else{a.attr("placeholder",143)}}; \ No newline at end of file diff --git a/ident_switch-switch.js b/ident_switch-switch.js index debd9c7..2a1af64 100644 --- a/ident_switch-switch.js +++ b/ident_switch-switch.js @@ -16,11 +16,7 @@ $(function() { } if (isOk) - $sw.show(); - - $("INPUT[name='_ident_switch.form.enabled']").change(); - $("SELECT[name='_ident_switch.form.secure']").change(); - plugin_switchIdent_processPreconfig(); + $sw.show(); }); function plugin_switchIdent_addCbLarry($sw) { @@ -47,39 +43,9 @@ function plugin_switchIdent_addCbClassic($sw) { return false; } -function plugin_switchIdent_processPreconfig() { - var disFld = $("INPUT[name='_ident_switch.form.readonly']"); - disFld.parentsUntil("TABLE", "TR").hide(); - - var disVal = disFld.val(); - if (disVal > 0) { - $("INPUT[name='_ident_switch.form.host']").prop("disabled", true); - $("SELECT[name='_ident_switch.form.secure']").prop("disabled", true); - $("INPUT[name='_ident_switch.form.port']").prop("disabled", true); - } - if (2 == disVal) { - $("INPUT[name='_ident_switch.form.username']").prop("disabled", true); - } - -} - -function plugin_switchIdent_enabled_onChange(e) { - var $enFld = $("INPUT[name='_ident_switch.form.enabled']"); - $("INPUT[name!='_ident_switch.form.enabled'], SELECT", $enFld.parents("FIELDSET")).prop("disabled", !$enFld.is(":checked")); - plugin_switchIdent_processPreconfig(); -} - -function plugin_switchIdent_secure_onChange(e) { - var $secSel = $("SELECT[name='_ident_switch.form.secure']"); - var $portFld = $("INPUT[name='_ident_switch.form.port']"); - - if ('SSL' === $secSel.val().toUpperCase()) - $portFld.attr("placeholder", 993); - else - $portFld.attr("placeholder", 143); -} - function plugin_switchIdent_switch(val) { + rcmail.env.unread_counts = {}; + console.log(rcmail.env.unread_counts); rcmail.http_post('plugin.ident_switch.switch', { '_ident-id': val, '_mbox': rcmail.env.mailbox }); } diff --git a/ident_switch-switch.min.js b/ident_switch-switch.min.js index 047df9c..fb03679 100644 --- a/ident_switch-switch.min.js +++ b/ident_switch-switch.min.js @@ -1,15 +1 @@ -$(function(){$sw=$('#plugin-ident_switch-account');isOk=false;switch(rcmail.env['skin']){case'larry':isOk=plugin_switchIdent_addCbLarry($sw);break;case'classic':isOk=plugin_switchIdent_addCbClassic($sw);break;} -if(isOk) -$sw.show();$("INPUT[name='_ident_switch.form.enabled']").change();$("SELECT[name='_ident_switch.form.secure']").change();plugin_switchIdent_processPreconfig();});function plugin_switchIdent_addCbLarry($sw){var $truName=$('.topright .username');if($truName.length>0){if($sw.length>0){$sw.prependTo('.topright');$truName.hide();return true;}} -return false;} -function plugin_switchIdent_addCbClassic($sw){var $taskBar=$('#taskbar');if($taskBar.length>0){$taskBar.prepend($sw);return true;} -return false;} -function plugin_switchIdent_processPreconfig(){var disFld=$("INPUT[name='_ident_switch.form.readonly']");disFld.parentsUntil("TABLE","TR").hide();var disVal=disFld.val();if(disVal>0){$("INPUT[name='_ident_switch.form.host']").prop("disabled",true);$("SELECT[name='_ident_switch.form.secure']").prop("disabled",true);$("INPUT[name='_ident_switch.form.port']").prop("disabled",true);} -if(2==disVal){$("INPUT[name='_ident_switch.form.username']").prop("disabled",true);}} -function plugin_switchIdent_enabled_onChange(e){var $enFld=$("INPUT[name='_ident_switch.form.enabled']");$("INPUT[name!='_ident_switch.form.enabled'], SELECT",$enFld.parents("FIELDSET")).prop("disabled",!$enFld.is(":checked"));plugin_switchIdent_processPreconfig();} -function plugin_switchIdent_secure_onChange(e){var $secSel=$("SELECT[name='_ident_switch.form.secure']");var $portFld=$("INPUT[name='_ident_switch.form.port']");if('SSL'===$secSel.val().toUpperCase()) -$portFld.attr("placeholder",993);else -$portFld.attr("placeholder",143);} -function plugin_switchIdent_switch(val){rcmail.http_post('plugin.ident_switch.switch',{'_ident-id':val,'_mbox':rcmail.env.mailbox});} -function plugin_switchIdent_fixIdent(iid){if(parseInt(iid)>0) -$("#_from").val(iid);} \ No newline at end of file +$(function(){$sw=$("#plugin-ident_switch-account");isOk=false;switch(rcmail.env.skin){case"larry":isOk=plugin_switchIdent_addCbLarry($sw);break;case"classic":isOk=plugin_switchIdent_addCbClassic($sw);break}if(isOk){$sw.show()}});function plugin_switchIdent_addCbLarry(b){var a=$(".topright .username");if(a.length>0){if(b.length>0){b.prependTo(".topright");a.hide();return true}}return false}function plugin_switchIdent_addCbClassic(b){var a=$("#taskbar");if(a.length>0){a.prepend(b);return true}return false}function plugin_switchIdent_switch(a){rcmail.env.unread_counts={};console.log(rcmail.env.unread_counts);rcmail.http_post("plugin.ident_switch.switch",{"_ident-id":a,_mbox:rcmail.env.mailbox})}function plugin_switchIdent_fixIdent(a){if(parseInt(a)>0){$("#_from").val(a)}}; \ No newline at end of file