From c4d99a012aaf18c49d7d33f16120721cef004318 Mon Sep 17 00:00:00 2001 From: Jared Hancock <jared@osticket.com> Date: Fri, 19 Jul 2013 13:27:32 -0500 Subject: [PATCH] Only fetch client and scp config on pages with file upload The client and scp config ajax request only contain the settings for the multi-file upload widget. So it doesn't need to be fetched unless the widget exists on the page --- js/osticket.js | 50 +++++++++++++++++++++++++++++++------------------- scp/js/scp.js | 40 ++++++++++++++++++++++++++-------------- 2 files changed, 57 insertions(+), 33 deletions(-) diff --git a/js/osticket.js b/js/osticket.js index 4a0e87b03..7ee8d00a6 100644 --- a/js/osticket.js +++ b/js/osticket.js @@ -1,4 +1,4 @@ -/* +/* osticket.js Copyright (c) osTicket.com */ @@ -18,7 +18,7 @@ $(document).ready(function(){ /* loading ... */ $("#loading").css({ top : ($(window).height() / 3), - left : ($(window).width() / 2 - 160) + left : ($(window).width() / 2 - 160) }); $("form :input").change(function() { @@ -49,22 +49,34 @@ $(document).ready(function(){ return true; }); - /* Get config settings from the backend */ - var $config = null; - $.ajax({ - url: "ajax.php/config/client", - dataType: 'json', - async: false, - success: function (config) { - $config = config; - } - }); - + jQuery.fn.exists = function() { return this.length>0; }; + + var getConfig = (function() { + var dfd = $.Deferred(); + return function() { + if (!dfd.isResolved()) + $.ajax({ + url: "ajax.php/config/client", + dataType: 'json', + success: function (json_config) { + dfd.resolve(json_config); + } + }); + return dfd; + } + })(); + /* Multifile uploads */ - $('.multifile').multifile({ - container: '.uploads', - max_uploads: ($config && $config.max_file_uploads)?$config.max_file_uploads:1, - file_types: ($config && $config.file_types)?$config.file_types:".*", - max_file_size: ($config && $config.max_file_size)?$config.max_file_size:0 - }); + var elems = $('.multifile'); + if (elems.exists()) { + /* Get config settings from the backend */ + getConfig().then(function(c) { + elems.multifile({ + container: '.uploads', + max_uploads: c.max_file_uploads || 1, + file_types: c.file_types || ".*", + max_file_size: c.max_file_size || 0 + }); + }); + } }); diff --git a/scp/js/scp.js b/scp/js/scp.js index 0f1505a18..ec2daf542 100644 --- a/scp/js/scp.js +++ b/scp/js/scp.js @@ -247,23 +247,35 @@ $(document).ready(function(){ }); /* Get config settings from the backend */ - var $config = null; - $.ajax({ - url: "ajax.php/config/scp", - dataType: 'json', - async: false, - success: function (config) { - $config = config; - } - }); + jQuery.fn.exists = function() { return this.length>0; }; + var getConfig = (function() { + var dfd = $.Deferred(); + return function() { + if (!dfd.isResolved()) + $.ajax({ + url: "ajax.php/config/scp", + dataType: 'json', + success: function (json_config) { + dfd.resolve(json_config); + } + }); + return dfd; + } + })(); /* Multifile uploads */ - $('.multifile').multifile({ - container: '.uploads', - max_uploads: ($config && $config.max_file_uploads)?$config.max_file_uploads:1, - file_types: ($config && $config.file_types)?$config.file_types:".*", - max_file_size: ($config && $config.max_file_size)?$config.max_file_size:0 + var elems = $('.multifile'); + if (elems.exists()) { + /* Get config settings from the backend */ + getConfig().then(function(c) { + elems.multifile({ + container: '.uploads', + max_uploads: c.max_file_uploads || 1, + file_types: c.file_types || ".*", + max_file_size: c.max_file_size || 0 + }); }); + } /* Datepicker */ $('.dp').datepicker({ -- GitLab