-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestPlugin.js
More file actions
executable file
·149 lines (149 loc) · 6.75 KB
/
TestPlugin.js
File metadata and controls
executable file
·149 lines (149 loc) · 6.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/// <reference types="jquery" />
(function (factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(require, exports);
if (v !== undefined) module.exports = v;
}
else if (typeof define === "function" && define.amd) {
define(["require", "exports", "jquery", "./Classes/GlobalWPPluginData", "./Classes/WPAjaxPayload", "./Classes/WPAjaxResponse", "./Classes/AJAX", "./Classes/Helper", "./Classes/TypeChecker", "./Classes/IndicatorUIHelper", "./Classes/LoaderUIHelper", "./Classes/ContextHelper", "./Classes/ElementGeneratorHelper", "./Classes/BrowserDetect", "./Contexts/admin/testplugin_Context"], factory);
}
})(function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var jQueryModule = require("jquery");
var GlobalWPPluginData_1 = require("./Classes/GlobalWPPluginData");
var WPAjaxPayload_1 = require("./Classes/WPAjaxPayload");
var WPAjaxResponse_1 = require("./Classes/WPAjaxResponse");
var AJAX_1 = require("./Classes/AJAX");
var Helper_1 = require("./Classes/Helper");
var TypeChecker_1 = require("./Classes/TypeChecker");
var IndicatorUIHelper_1 = require("./Classes/IndicatorUIHelper");
var LoaderUIHelper_1 = require("./Classes/LoaderUIHelper");
var ContextHelper_1 = require("./Classes/ContextHelper");
var ElementGeneratorHelper_1 = require("./Classes/ElementGeneratorHelper");
var BrowserDetect_1 = require("./Classes/BrowserDetect");
var testplugin_Context_1 = require("./Contexts/admin/testplugin_Context");
var TestPlugin;
(function (TestPlugin) {
TestPlugin.GlobalWPPluginData = GlobalWPPluginData_1.GlobalWPPluginData;
TestPlugin.PluginData = null;
TestPlugin.WPAjaxPayload = WPAjaxPayload_1.WPAjaxPayload;
TestPlugin.WPAjaxResponse = WPAjaxResponse_1.WPAjaxResponse;
TestPlugin.ContextHelper = ContextHelper_1.ContextHelper;
var Utilities = /** @class */ (function () {
function Utilities() {
}
return Utilities;
}());
TestPlugin.Utilities = Utilities;
(function (Utilities) {
Utilities.AJAX = AJAX_1.AJAX;
Utilities.Helper = Helper_1.Helper;
Utilities.TypeChecker = TypeChecker_1.TypeChecker;
Utilities.BrowserDetect = BrowserDetect_1.BrowserDetect;
Utilities.LoaderUIHelper = LoaderUIHelper_1.LoaderUIHelper;
Utilities.IndicatorUIHelper = IndicatorUIHelper_1.IndicatorUIHelper;
Utilities.ElementGeneratorHelper = ElementGeneratorHelper_1.ElementGeneratorHelper;
})(Utilities = TestPlugin.Utilities || (TestPlugin.Utilities = {}));
/* Use these on pages when grouping data to be loaded for that page. Strongly types some fields / data to help prevent runtime issues. */
var Contexts = /** @class */ (function () {
function Contexts() {
}
return Contexts;
}());
TestPlugin.Contexts = Contexts;
(function (Contexts) {
var admin = /** @class */ (function () {
function admin() {
}
return admin;
}());
Contexts.admin = admin;
(function (admin) {
admin.testplugin_Context = testplugin_Context_1.testplugin_Context;
})(admin = Contexts.admin || (Contexts.admin = {}));
var user = /** @class */ (function () {
function user() {
}
return user;
}());
Contexts.user = user;
})(Contexts = TestPlugin.Contexts || (TestPlugin.Contexts = {}));
var Extensions = /** @class */ (function () {
function Extensions() {
}
return Extensions;
}());
TestPlugin.Extensions = Extensions;
/* Any custom events to help trigger customized functionality, but have some common method for triggering them */
var Events = /** @class */ (function () {
function Events() {
}
return Events;
}());
TestPlugin.Events = Events;
(function (Events) {
Events.MyEvent = new CustomEvent('customEvent', {
bubbles: true
});
})(Events = TestPlugin.Events || (TestPlugin.Events = {}));
function init(pluginData) {
if (!pluginData) {
throw new TypeError("The pluginData parameter was invalid.");
}
else {
TestPlugin.PluginData = TestPlugin.GlobalWPPluginData.fromRawObj(pluginData);
}
setJQueryDefaults(jQueryModule);
}
TestPlugin.init = init;
function attachHandlers() {
var body = jQuery("body");
//body.on("click",".testClass",function(){});
body.on("click", ".linkButton", function () {
var $this = jQuery(this);
var urlToOpen = $this.data('link-to-open');
var urlTarget = $this.data('open-target');
if (TestPlugin.Utilities.TypeChecker.isEmpty(urlToOpen)) {
return;
}
if (TestPlugin.Utilities.TypeChecker.isEmpty(urlTarget)) {
urlTarget = "current";
}
switch (urlTarget) {
case "new":
TestPlugin.Utilities.Helper.openInNewTab(urlToOpen);
break;
default:
window.location.href = urlToOpen;
}
});
}
TestPlugin.attachHandlers = attachHandlers;
function setJQueryDefaults(jq) {
//set ajax defaults
var jsonMimeType = "application/json;charset=UTF-8";
jq.ajaxSetup({
type: "POST",
url: TestPlugin.PluginData.ajaxurl,
dataType: "json",
traditional: true,
error: TestPlugin.Utilities.AJAX.standardAjaxError,
beforeSend: function (x) {
if (x && x.overrideMimeType) {
x.overrideMimeType(jsonMimeType);
}
},
});
jq(this).ajaxSuccess(function (event, request) {
var data = request.responseJSON;
if (!TestPlugin.Utilities.TypeChecker.isUndefined(data.newNonce)) {
TestPlugin.PluginData.nonce = data.newNonce;
}
});
TestPlugin.Utilities.Helper.addCustomValidators(jQuery);
}
TestPlugin.setJQueryDefaults = setJQueryDefaults;
})(TestPlugin = exports.TestPlugin || (exports.TestPlugin = {}));
});
//# sourceMappingURL=TestPlugin.js.map