From cefcaabd4b305291167df558db39674b60f13755 Mon Sep 17 00:00:00 2001 From: Argo-MacBookPro Date: Thu, 6 Sep 2018 15:47:07 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=E4=BB=A3=E7=A0=81=EF=BC=9A?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=B6=88=E6=81=AF=E6=8B=89=E5=8F=96=E9=80=BB?= =?UTF-8?q?=E8=BE=91=EF=BC=8CresetWidget=E6=A0=B9=E6=8D=AE=E6=96=B0dropdow?= =?UTF-8?q?n-menu=E7=BB=93=E6=9E=84=E9=87=8D=E5=86=99=EF=BC=8C=E6=94=B9?= =?UTF-8?q?=E5=90=8D=E4=B8=BAclearWidgetItems?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Bootstrap.Admin/wwwroot/js/common-scripts.js | 37 ++++++++------------ 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/Bootstrap.Admin/wwwroot/js/common-scripts.js b/Bootstrap.Admin/wwwroot/js/common-scripts.js index a1491b56..bdc749b8 100644 --- a/Bootstrap.Admin/wwwroot/js/common-scripts.js +++ b/Bootstrap.Admin/wwwroot/js/common-scripts.js @@ -34,24 +34,16 @@ } }); }, - resetWidget: function () { - var widgets = $(this).children('li'); - widgets.each(function () { - var widget = $(this).children('ul'); - if (widget.children().length === 3) return; - var last = widget.children(':last'); - while (widget.children().length > 3) { - widget.children(':eq(2)').remove(); - } + clearWidgetItems: function () { + this.children('.dropdown').each(function () { + $(this).children('.dropdown-menu').each(function () { + $(this).children('a').remove(); + }); }); - return $(this); - } - }); - - $.extend({ - pullNotification: function (nav) { - if (nav.length === 0) return; - + return this; + }, + pullNotification: function () { + var that = this; var uri = "ws://" + window.location.host + $.formatUrl("WS"); var socket = new WebSocket(uri); socket.onmessage = function (e) { @@ -68,11 +60,10 @@ break; } } - if (result.length > 0) nav.reloadWidget(); + if (result.length > 0) that.reloadWidget(); }; - } - }); - $.fn.extend({ + return this; + }, reloadWidget: function () { if (this.length === 0) return this; var that = this; @@ -82,7 +73,7 @@ method: 'GET', callback: function (result) { $('#logoutNoti').text(result.NewUsersCount === 0 ? "" : result.NewUsersCount); - that.resetWidget(); + that.clearWidgetItems(); // tasks $('#msgHeaderTask').text(result.TasksCount); $('#msgHeaderTaskBadge').text(result.TasksCount === 0 ? "" : result.TasksCount); @@ -203,5 +194,5 @@ $(function () { $('[data-toggle="dropdown"].dropdown-select').dropdown('select'); // load widget data - $.pullNotification($('.header .nav').reloadWidget()); + $('.header .nav').reloadWidget().pullNotification(); }); \ No newline at end of file