Commit 9f3e75625ee65978cdad4fdcf8db8cfb08cae085
Committed by
Daniela Feitosa
1 parent
f2aeb9ee
Exists in
stable-spb-1.4
and in
8 other branches
Scoping environment_notification plugin's javascript functions
(cherry picked from commit 603ea7017cf4cfc41644976b694f1280d69db9e5)
Showing
1 changed file
with
77 additions
and
73 deletions
Show diff stats
plugins/environment_notification/public/environment_notification_plugin.js
1 | (function($) { | 1 | (function($) { |
2 | "use strict"; | 2 | "use strict"; |
3 | 3 | ||
4 | - function notificationBar() { | ||
5 | - var completeMessage = $(".notification-bar").remove(); | ||
6 | - $("#content-inner").before(completeMessage); | ||
7 | - } | ||
8 | - | ||
9 | - function closeNotification(){ | ||
10 | - var notification = $(this).parent(); | ||
11 | - var id = notification.attr("data-notification"); | ||
12 | - | ||
13 | - $.ajax({ | ||
14 | - url: noosfero_root()+"/admin/plugin/environment_notification/close_notification", | ||
15 | - type: "POST", | ||
16 | - data: {notification_id: id}, | ||
17 | - success: function(response) { | ||
18 | - notification.fadeOut(); | ||
19 | - } | ||
20 | - }); | ||
21 | - } | ||
22 | - | ||
23 | - function hideNotification(){ | ||
24 | - var notification = $(this).parent(); | ||
25 | - var id = notification.attr("data-notification"); | ||
26 | - | ||
27 | - $.ajax({ | ||
28 | - url: noosfero_root()+"/admin/plugin/environment_notification/hide_notification", | ||
29 | - type: "POST", | ||
30 | - data: {notification_id: id}, | ||
31 | - success: function(response) { | ||
32 | - notification.fadeOut(); | ||
33 | - } | ||
34 | - }); | ||
35 | - } | 4 | + var environment_notification_plugin = { |
36 | 5 | ||
37 | - function hideUserNotification(){ | ||
38 | - var ids = $.cookie('hide_notifications'); | ||
39 | - if(ids === null) { | ||
40 | - return null; | ||
41 | - } | ||
42 | 6 | ||
43 | - if(ids.startsWith('[') && ids.endsWith(']')){ | ||
44 | - ids = ids.substring(1, ids.length - 1); | ||
45 | - ids = ids.split(","); | 7 | + notificationBar: function() { |
8 | + var completeMessage = $(".notification-bar").remove(); | ||
9 | + $("#content-inner").before(completeMessage); | ||
10 | + }, | ||
46 | 11 | ||
47 | - for(var i = 0; i < ids.length; i++) { | ||
48 | - $('[data-notification="' + ids[i] + '"]').fadeOut(); | ||
49 | - } | ||
50 | - } | ||
51 | - } | ||
52 | - | ||
53 | - function mceRestrict() { | ||
54 | - tinyMCE.init({ | ||
55 | - menubar : false, | ||
56 | - selector: "textarea", | ||
57 | - plugins: [ | ||
58 | - "autolink link" | ||
59 | - ], | ||
60 | - toolbar: "bold italic underline | link" | ||
61 | - }); | ||
62 | - } | ||
63 | - | ||
64 | - function showPopup() { | ||
65 | - if($('.action-home-index').length > 0) { | ||
66 | - jQuery(function($){ | ||
67 | - $.colorbox({href: noosfero_root()+'/plugin/environment_notification/public/notifications_with_popup?previous_path=home'}); | 12 | + closeNotification: function(){ |
13 | + var notification = $(this).parent(); | ||
14 | + var id = notification.attr("data-notification"); | ||
15 | + | ||
16 | + $.ajax({ | ||
17 | + url: noosfero_root()+"/admin/plugin/environment_notification/close_notification", | ||
18 | + type: "POST", | ||
19 | + data: {notification_id: id}, | ||
20 | + success: function(response) { | ||
21 | + notification.fadeOut(); | ||
22 | + } | ||
68 | }); | 23 | }); |
69 | - } | ||
70 | - else { | ||
71 | - jQuery(function($){ | ||
72 | - $.colorbox({href: noosfero_root()+'/plugin/environment_notification/public/notifications_with_popup'}); | 24 | + }, |
25 | + | ||
26 | + hideNotification: function(){ | ||
27 | + var notification = $(this).parent(); | ||
28 | + var id = notification.attr("data-notification"); | ||
29 | + | ||
30 | + $.ajax({ | ||
31 | + url: noosfero_root()+"/admin/plugin/environment_notification/hide_notification", | ||
32 | + type: "POST", | ||
33 | + data: {notification_id: id}, | ||
34 | + success: function(response) { | ||
35 | + notification.fadeOut(); | ||
36 | + } | ||
73 | }); | 37 | }); |
74 | - } | ||
75 | - } | 38 | + }, |
39 | + | ||
40 | + hideUserNotification: function(){ | ||
41 | + var ids = $.cookie('hide_notifications'); | ||
42 | + if(ids === null) { | ||
43 | + return null; | ||
44 | + } | ||
45 | + | ||
46 | + if(ids.startsWith('[') && ids.endsWith(']')){ | ||
47 | + ids = ids.substring(1, ids.length - 1); | ||
48 | + ids = ids.split(","); | ||
49 | + | ||
50 | + for(var i = 0; i < ids.length; i++) { | ||
51 | + $('[data-notification="' + ids[i] + '"]').fadeOut(); | ||
52 | + } | ||
53 | + } | ||
54 | + }, | ||
55 | + | ||
56 | + mceRestrict: function() { | ||
57 | + tinyMCE.init({ | ||
58 | + menubar : false, | ||
59 | + selector: "textarea", | ||
60 | + plugins: [ | ||
61 | + "autolink link" | ||
62 | + ], | ||
63 | + toolbar: "bold italic underline | link" | ||
64 | + }); | ||
65 | + }, | ||
66 | + | ||
67 | + showPopup: function() { | ||
68 | + if($('.action-home-index').length > 0) { | ||
69 | + jQuery(function($){ | ||
70 | + $.colorbox({href: noosfero_root()+'/plugin/environment_notification/public/notifications_with_popup?previous_path=home'}); | ||
71 | + }); | ||
72 | + } | ||
73 | + else { | ||
74 | + jQuery(function($){ | ||
75 | + $.colorbox({href: noosfero_root()+'/plugin/environment_notification/public/notifications_with_popup'}); | ||
76 | + }); | ||
77 | + } | ||
78 | + }, | ||
79 | + }; | ||
76 | 80 | ||
77 | $(document).ready(function(){ | 81 | $(document).ready(function(){ |
78 | - notificationBar(); | ||
79 | - $(".notification-close").on("click", closeNotification); | ||
80 | - $(".notification-hide").on("click", hideNotification); | 82 | + environment_notification_plugin.notificationBar(); |
83 | + $(".notification-close").on("click", environment_notification_plugin.closeNotification); | ||
84 | + $(".notification-hide").on("click", environment_notification_plugin.hideNotification); | ||
81 | 85 | ||
82 | if($('.environment-notification-plugin-message').length > 0){ | 86 | if($('.environment-notification-plugin-message').length > 0){ |
83 | - mceRestrict(); | 87 | + environment_notification_plugin.mceRestrict(); |
84 | } | 88 | } |
85 | 89 | ||
86 | if($('.notification-bar').length > 0){ | 90 | if($('.notification-bar').length > 0){ |
87 | - hideUserNotification(); | 91 | + environment_notification_plugin.hideUserNotification(); |
88 | } | 92 | } |
89 | 93 | ||
90 | if($('[notification-display-popup="true"]').length > 0){ | 94 | if($('[notification-display-popup="true"]').length > 0){ |
91 | - showPopup(); | 95 | + environment_notification_plugin.showPopup(); |
92 | } | 96 | } |
93 | }); | 97 | }); |
94 | 98 |