1/** 2 * @namespace WPGMZA 3 * @module PersistentAdminNotice 4 * @requires WPGMZA.EventDispatcher 5 */ 6jQuery(function($) { 7 WPGMZA.PersistentAdminNotice = function(element, options){ 8 if(!(element instanceof HTMLElement)) 9 throw new Error("Element is not an instance of HTMLInputElement"); 10 11 this.element = $(element); 12 this.dismissButton = this.element.find('.notice-dismiss'); 13 14 this.ajaxActionButton = this.element.find('a[data-ajax]'); 15 16 this.bindEvents(); 17 } 18 19 WPGMZA.extend(WPGMZA.PersistentAdminNotice, WPGMZA.EventDispatcher); 20 21 WPGMZA.PersistentAdminNotice.createInstance = function(element) { 22 return new WPGMZA.PersistentAdminNotice(element); 23 } 24 25 WPGMZA.PersistentAdminNotice.prototype.bindEvents = function(){ 26 let self = this; 27 this.dismissButton.on('click', function(event) { 28 self.onDismiss($(this)); 29 }); 30 31 this.ajaxActionButton.on('click', function(event) { 32 event.preventDefault(); 33 self.onAjaxAction($(this)); 34 }); 35 } 36 37 WPGMZA.PersistentAdminNotice.prototype.onDismiss = function(item){ 38 const noticeSlug = this.element.data('slug'); 39 40 const data = { 41 action : 'wpgmza_dismiss_persistent_notice', 42 slug : noticeSlug, 43 wpgmza_security : WPGMZA.ajaxnonce 44 }; 45 46 $.ajax(WPGMZA.ajaxurl, { 47 method: "POST", 48 data: data, 49 success: function(response, status, xhr) { 50 // Nothing to do 51 }, 52 error : function(){} 53 }); 54 } 55 56 WPGMZA.PersistentAdminNotice.prototype.onAjaxAction = function(item){ 57 if(item.data('disabled')){ 58 return; 59 } 60 61 const action = item.data('ajax-action'); 62 const noticeSlug = this.element.data('slug'); 63 64 item.attr('data-disabled', 'true'); 65 item.css('opacity', "0.5"); 66 67 if(action){ 68 const data = { 69 action : 'wpgmza_persisten_notice_quick_action', 70 relay : action, 71 slug : noticeSlug, 72 wpgmza_security : WPGMZA.ajaxnonce 73 }; 74 75 $.ajax(WPGMZA.ajaxurl, { 76 method: "POST", 77 data : data, 78 success : function(response){ 79 window.location.reload(); 80 }, 81 error: function(){} 82 }); 83 } 84 } 85 86 $(document.body).ready(function(){ 87 $(".wpgmza-persistent-notice").each(function(index, el) { 88 el.wpgmzaPersistentAdminNotice = WPGMZA.PersistentAdminNotice.createInstance(el); 89 }); 90 }); 91});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.