PageSourceSearch

https://www.hfes.org/DesktopModules/DnnSharp/Common/static/dnnsf/dnnsf.js?cdv=54

js hfes.org collected 2026-09-24 08:41:30 UTC 35,532 bytes, 881 lines download raw bytes

1;
2/*
3 * DnnSF (DNN Sharp Foundation)
4 */
5(function (window) {
6    try {
7        new MouseEvent('test');
8        return false; // No need to polyfill
9    } catch (e) {
10        // Need to polyfill - fall through
11        var MouseEvent = function (eventType, params) {
12            params = params || { bubbles: false, cancelable: false };
13            var mouseEvent = document.createEvent('MouseEvent');
14            mouseEvent.initMouseEvent(eventType, params.bubbles, params.cancelable, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
15            return mouseEvent;
16        }
17        MouseEvent.prototype = Event.prototype;
18        window.MouseEvent = MouseEvent;
19    }
20    // Polyfills DOM4 MouseEvent
21})(window);
22
23if (typeof (dnnsfjQuery) == 'undefined') dnnsfjQuery = jQuery || $;
24
25/*yepnope1.5.x|WTFPL*/
26(function (a, b, c) { function d(a) { return "[object Function]" == o.call(a) } function e(a) { return "string" == typeof a } function f() { } function g(a) { return !a || "loaded" == a || "complete" == a || "uninitialized" == a } function h() { var a = p.shift(); q = 1, a ? a.t ? m(function () { ("c" == a.t ? B.injectCss : B.injectJs)(a.s, 0, a.a, a.x, a.e, 1) }, 0) : (a(), h()) : q = 0 } function i(a, c, d, e, f, i, j) { function k(b) { if (!o && g(l.readyState) && (u.r = o = 1, !q && h(), l.onload = l.onreadystatechange = null, b)) { "img" != a && m(function () { t.removeChild(l) }, 50); for (var d in y[c]) y[c].hasOwnProperty(d) && y[c][d].onload() } } var j = j || B.errorTimeout, l = b.createElement(a), o = 0, r = 0, u = { t: d, s: c, e: f, a: i, x: j }; 1 === y[c] && (r = 1, y[c] = []), "object" == a ? l.data = c : (l.src = c, l.type = a), l.width = l.height = "0", l.onerror = l.onload = l.onreadystatechange = function () { k.call(this, r) }, p.splice(e, 0, u), "img" != a && (r || 2 === y[c] ? (t.insertBefore(l, s ? null : n), m(k, j)) : y[c].push(l)) } function j(a, b, c, d, f) { return q = 0, b = b || "j", e(a) ? i("c" == b ? v : u, a, b, this.i++, c, d, f) : (p.splice(this.i++, 0, a), 1 == p.length && h()), this } function k() { var a = B; return a.loader = { load: j, i: 0 }, a } var l = b.documentElement, m = a.setTimeout, n = b.getElementsByTagName("script")[0], o = {}.toString, p = [], q = 0, r = "MozAppearance" in l.style, s = r && !!b.createRange().compareNode, t = s ? l : n.parentNode, l = a.opera && "[object Opera]" == o.call(a.opera), l = !!b.attachEvent && !l, u = r ? "object" : l ? "script" : "img", v = l ? "script" : u, w = Array.isArray || function (a) { return "[object Array]" == o.call(a) }, x = [], y = {}, z = { timeout: function (a, b) { return b.length && (a.timeout = b[0]), a } }, A, B; B = function (a) { function b(a) { var a = a.split("!"), b = x.length, c = a.pop(), d = a.length, c = { url: c, origUrl: c, prefixes: a }, e, f, g; for (f = 0; f < d; f++) g = a[f].split("="), (e = z[g.shift()]) && (c = e(c, g)); for (f = 0; f < b; f++) c = x[f](c); return c } function g(a, e, f, g, h) { var i = b(a), j = i.autoCallback; i.url.split(".").pop().split("?").shift(), i.bypass || (e && (e = d(e) ? e : e[a] || e[g] || e[a.split("/").pop().split("?")[0]]), i.instead ? i.instead(a, e, f, g, h) : (y[i.url] ? i.noexec = !0 : y[i.url] = 1, f.load(i.url, i.forceCSS || !i.forceJS && "css" == i.url.split(".").pop().split("?").shift() ? "c" : c, i.noexec, i.attrs, i.timeout), (d(e) || d(j)) && f.load(function () { k(), e && e(i.origUrl, h, g), j && j(i.origUrl, h, g), y[i.url] = 2 }))) } function h(a, b) { function c(a, c) { if (a) { if (e(a)) c || (j = function () { var a = [].slice.call(arguments); k.apply(this, a), l() }), g(a, j, b, 0, h); else if (Object(a) === a) for (n in m = function () { var b = 0, c; for (c in a) a.hasOwnProperty(c) && b++; return b }(), a) a.hasOwnProperty(n) && (!c && !--m && (d(j) ? j = function () { var a = [].slice.call(arguments); k.apply(this, a), l() } : j[n] = function (a) { return function () { var b = [].slice.call(arguments); a && a.apply(this, b), l() } }(k[n])), g(a[n], j, b, n, h)) } else !c && l() } var h = !!a.test, i = a.load || a.both, j = a.callback || f, k = j, l = a.complete || f, m, n; c(h ? a.yep : a.nope, !!i), i && c(i) } var i, j, l = this.yepnope.loader; if (e(a)) g(a, 0, l, 0); else if (w(a)) for (i = 0; i < a.length; i++) j = a[i], e(j) ? g(j, 0, l, 0) : w(j) ? B(j) : Object(j) === j && h(j, l); else Object(a) === a && h(a, l) }, B.addPrefix = function (a, b) { z[a] = b }, B.addFilter = function (a) { x.push(a) }, B.errorTimeout = 1e4, null == b.readyState && b.addEventListener && (b.readyState = "loading", b.addEventListener("DOMContentLoaded", A = function () { b.removeEventListener("DOMContentLoaded", A, 0), b.readyState = "complete" }, 0)), a.yepnope = k(), a.yepnope.executeStack = h, a.yepnope.injectJs = function (a, c, d, e, i, j) { var k = b.createElement("script"), l, o, e = e || B.errorTimeout; k.src = a; for (o in d) k.setAttribute(o, d[o]); c = j ? h : c || f, k.onreadystatechange = k.onload = function () { !l && g(k.readyState) && (l = 1, c(), k.onload = k.onreadystatechange = null) }, m(function () { l || (l = 1, c(1)) }, e), i ? k.onload() : n.parentNode.insertBefore(k, n) }, a.yepnope.injectCss = function (a, c, d, e, g, i) { var e = b.createElement("link"), j, c = i ? h : c || f; e.href = a, e.rel = "stylesheet", e.type = "text/css"; for (j in d) e.setAttribute(j, d[j]); g || (n.parentNode.insertBefore(e, n), m(c, 0)) } })(this, document);
27
28// fix IE console issues
29if (!window.console) window.console = {};
30if (!window.console.log) window.console.log = function () { };
31
32var dnnsf = dnnsf || {};
33
34// copy state into dnnsf
35if (typeof g_dnnsfState != 'undefined')
36    for (var key in g_dnnsfState)
37        dnnsf[key] = g_dnnsfState[key];
38
39// extend with common functions
40dnnsf.init = function ($, appState) {
41    // save dnnsfjQuery object for future use
42    dnnsf.$ = $;
43    if (!window.dnnsfjQuery)
44        window.dnnsfjQuery = $;
45    if (!window.jQuery)
46        window.jQuery = $;
47
48    // execute the initialization code when done loading
49    (function (fn) {
50        if ($.isReady) fn(); else $(fn);
51    })(function () {
52
53        // if we're in an iframe, hide the scrollbar of current window and rely on auto-height featre
54        if (window.top != window && window.location.href.indexOf('isAdminIframe=true') != -1) {
55            $('body').css('overflow', 'hidden').attr('scroll', 'no');
56        }
57
58    });
59};
60
61// returns a query string parameter by name
62dnnsf.urlParam = function (name) {
63    var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(decodeURIComponent(window.location.href));
64    if (!results) { return 0; }
65    return results[1] || 0;
66};
67
68dnnsf.parseQueryString = function (queryString) {
69    var qs = {},
70        match,
71        pl = /\+/g, // Regex for replacing addition symbol with a space
72        search = /([^&=]+)=?([^&]*)/g,
73        decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); },
74        query = (queryString.indexOf('?') == 0 ? queryString.substring(1) : queryString);
75
76    if (query.indexOf('#') != -1)
77        query = query.substring(0, query.indexOf('#'));
78	
79    while (match = search.exec(query))
80        qs[decode(match[1])] = decode(match[2]);
81	
82    return qs;
83};
84
85dnnsf.updateQueryStringParam = function (key, value) {
86    var baseUrl = location.protocol + '//' + location.host + location.pathname,
87        urlQueryString = document.location.search,
88        newParam = key + '=' + encodeURIComponent(value),
89        params = '?' + newParam;
90
91    // If the "search" string exists, then build params from it
92    if (urlQueryString) {
93        keyRegex = new RegExp('([\?&])' + key + '[^&]*');
94
95        // If param exists already, update it
96        if (urlQueryString.match(keyRegex) !== null) {
97            params = urlQueryString.replace(keyRegex, "$1" + newParam);
98        } else { // Otherwise, add it to end of query string
99            params = urlQueryString + '&' + newParam;
100        }
101    }
102    history.pushState({}, "", baseUrl + params + location.hash);
103};
104
105dnnsf.urlParams = {};
106(window.onpopstate = function () {
107    dnnsf.urlParams = dnnsf.parseQueryString(window.location.search);
108})();
109
110dnnsf.getUrlParts = function (url) {
111    var a = document.createElement('a');
112    a.href = url;
113    var path = a.pathname || '/';
114    if (path[0] != '/')
115        path = '/' + path;
116
117    return {
118        href: a.href,
119        host: a.host,
120        hostname: a.hostname,
121        port: a.port,
122        pathname: path,
123        protocol: a.protocol,
124        hash: a.hash,
125        search: a.search,
126        query: dnnsf.parseQueryString(a.search),
127        relativeUrl: path + a.search + a.hash,
128
129        getUrl: function () {
130            return this.pathname + ($.isEmptyObject(this.query) ? '' : '?' + $.param(this.query)) + this.hash;
131        }
132    };
133}
134
135// this scrolls the page to given scroll, taking into account offset and iframe communication when applicable
136dnnsf.scrollTo = function (scroll) {
137
138    if (isNaN(parseInt(scroll)))
139        return;
140
141    if (window.top != window) {
142        // post to top window
143        window.top.postMessage(JSON.stringify({
144            type: dnnsf.urlParam('comm-prefix') + "-scroll",
145            offset: scroll
146        }), "*");
147    } else {
148        // scroll this window
149        $('html, body').animate({
150            scrollTop: scroll
151        }, 500);
152    }
153
154};
155
156dnnsf.initStickyLoading = function (mid) {
157    var context = {
158        timeOutVar: null,
159        parent: $('#' + mid),
160        el: $('#' + mid + ' .common-data-loading'),
161        el2: $('#' + mid + ' .common-loading-text')
162    };
163
164    var elOffset = 0;
165    if (context.el.parent().height() <= 270) {
166        // put the loading animation in the middle of the container if it's height is small.
167        elOffset = context.el.parent().height() / 2 - context.el.height() / 2;
168    } else {
169        // put the loading animation 200px from the top of the container if it's height can accommodate the loader.
170        elOffset = 200;
171    }
172    var el2Offset = elOffset + 50;
173    context.el.css("top", elOffset + 'px');
174    context.el2.css("top", el2Offset + 'px');
175
176    $(window).off('scroll', onWindowScroll).on('scroll', context, onWindowScroll);
177}
178
179function onWindowScroll(event) {
180    var context = event.data;
181
182    clearTimeout(context.timeOutVar);
183    context.timeOutVar = setTimeout(function () {
184        if (context.parent.offset && window.pageYOffset > context.parent.offset().top) {
185            var top = window.pageYOffset - context.parent.offset().top + 200;
186            context.el.fadeOut(0)
187                .css({ "top": top + "px" })
188                .fadeIn(300);
189            context.el2.fadeOut(0)
190                .css({ "top": 50 + top + "px" })
191                .fadeIn(300);
192        }
193        else {
194            context.el.css({ "top": '200px' });
195            context.el2.css({ "top": "250px" });
196        }
197    }, 500);
198};
199
200// always use this logging function since it will take care of disabling the logging on production 
201//   and also it measures execution time (not very precisely though)
202dnnsf.log = function () {
203    if (!this.isDebug || !window.console || !console.log)
204        return;
205
206    // append timestamp to list of arguments
207    var args = Array.prototype.slice.call(arguments);
208    args.push(new Date().getTime() - this.start);
209
210    // call the broser logging function
211    // TODO: in IE objects are no expanded, instead IE will show [Object object] string
212    // it would be useful to do a JSON.stringify on IE
213    Function.apply.call(console.log, console, args);
214};
215
216dnnsf.canAccessIFrame = function (ifr) {
217    var key = (+new Date) + "" + Math.random();
218
219    try {
220        var global = ifr.contentWindow;
221        global[key] = "check";
222        return global[key] === "check";
223    }
224    catch (e) {
225        return false;
226    }
227}
228
229/**
230 * Provide controllerName and actionName as string with no slashes
231 * @param {string} controllerName
232 * @param {string} actionName
233 * @param {object} args
234 */
235dnnsf.getWebApiEndpoint = function (controllerName, actionName, args) {
236    if (!args) args = {};
237
238    delete args.$$_q;
239
240    var url = dnnsf.webApiServiceRoot + controllerName + '/' + actionName;
241    var queryString = "";
242
243    for (var name in args) {
244        if (args.hasOwnProperty(name))
245            queryString += '&' + name + '=' + encodeURIComponent(args[name]);
246    }
247    if (queryString) {
248        url += "?" + queryString.substr(1); // remove first '&' character
249    }
250    return url;
251}
252
253dnnsf.adminApi = function (method, args, options, isWebApi) {
254    options = options || {};
255    options.apiUrl = options.apiUrl || g_dnnsfState.adminApi;
256    options.moduleId = options.moduleId || g_dnnsfState.moduleId || -1;
257    options.tabId = options.tabId || g_dnnsfState.tabId;
258    options.apiVersion = options.apiVersion || g_dnnsfState.apiVersion;
259    options.alias = options.alias || dnnsf.alias || g_dnnsfState.alias;
260    options.aliasid = options.aliasid || dnnsf.aliasid || g_dnnsfState.aliasid;
261    // if webApi is true then it builds the url for webApi with slahes, else it builds the normal URL
262    if (isWebApi) {
263        var webApiRootUrl = g_dnnsfState.siteRoot; // this contains both the virtual path and portal name and ensures WebAPI calls are okay.
264        var webApiUrl = webApiRootUrl + options.apiUrl.replace(/^\/|\/$/g, '');
265        url = webApiUrl + "/" + method + '?_aliasid=' + options.aliasid // options here is the URL string (e.g. Api/Admin)
266    }
267    else {
268        url = options.apiUrl + '?method=' + method +
269            (options.apiVersion == '2.0'
270                ?
271                ('&_aliasid=' + options.aliasid + '&_mid=' + options.moduleId + '&_tabid=' + options.tabId)
272                :
273                ('&_aliasid=' + options.aliasid + '&mid=' + options.moduleId + '&tabid=' + options.tabId))
274    }
275
276    if (!args)
277        return url;
278
279    for (var name in args) {
280        if (name === "$$_q")
281            continue;
282        if (args.hasOwnProperty(name))
283            url += '&' + name + '=' + encodeURIComponent(args[name]);
284    }
285    return url;
286};
287
288dnnsf.parseCssBlock = function (styleContent) {
289
290    var rules = {};
291    dnnsf.$.each(styleContent.split(';'), function (i, part) {
292        var isep = part.indexOf(':');
293        if (isep == -1)
294            return; // ?
295        rules[dnnsf.$.trim(part.substr(0, isep))] = dnnsf.$.trim(part.substr(isep + 1));
296    });
297
298    return rules;
299};
300
301dnnsf.createClass = function (name, rules) {
302    var style = document.createElement('style');
303    style.type = 'text/css';
304    document.getElementsByTagName('head')[0].appendChild(style);
305    if (!(style.sheet || {}).insertRule) {
306        (style.styleSheet || style.sheet).addRule(name, rules);
307    }
308    else {
309        style.innerHTML = name + "{" + rules + "}";
310    }
311};
312
313dnnsf.stackTrace = function () {
314
315    //return '';
316    //var e = new Error('dummy');
317    //var stack = e.stack.replace(/^[^\(]+?[\n$]/gm, '')
318    //    .replace(/^\s+at\s+/gm, '')
319    //    .replace(/^Object.<anonymous>\s*\(/gm, '{anonymous}()@')
320    //    .split('\n');
321    //// remove the call to this function
322    //stack.splice(0, 1);
323    //return stack;
324};
325
326// this function tries to guess if a string is an object or array
327dnnsf.eval = function (obj) {
328
329    if (typeof (obj) != 'string')
330        return obj;
331
332    if (!isNaN(parseInt(obj)))
333        return parseInt(obj);
334
335    if (!isNaN(parseFloat(obj)))
336        return parseFloat(obj);
337
338    // TODO: find a better way to determine json arrays and objects - for example with a regex
339    if (obj[0] == '[' || obj[0] == '{')
340        return eval(obj);
341
342    if (obj == "false")
343        return false;
344
345    if (obj == "true")
346        return true;
347
348    // just return it as string
349    return obj;
350};
351
352// if object is array, return it, otheriwse return a new array with only this item
353dnnsf.toArray = function (obj) {
354    if (!obj) return [];
355    if (!$.isArray(obj))
356        obj = [obj];
357    return obj;
358};
359
360dnnsf.tryParseBool = function (o) {
361    //  JSON values aren't necessary strings
362    if (typeof (o) !== 'string')
363        return o;
364
365    if (o.toLowerCase() == 'true')
366        return true;
367
368    if (o.toLowerCase() == 'false')
369        return false;
370
371    return o;
372};
373
374dnnsf.stringToBool = function (input) {
375    return typeof input === 'boolean' && input || (input ? JSON.parse(input.toLowerCase()) : false);
376}
377
378// returns baseId + altId if altId exists, otherwise generates an unique string
379dnnsf.uniqueId = function (baseId, altId) {
380    if (!altId || altId == -1)
381        return baseId + new Date().getTime() + Math.floor(Math.random() * 10000);
382    return baseId + altId;
383}
384
385dnnsf.generateUuid = function () {
386    return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, function (c) {
387        return (c ^ (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))).toString(16);
388    });
389}
390
391dnnsf.randomString = function (length) {
392    var chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
393    var result = '';
394    for (var i = length; i > 0; --i) result += chars[Math.round(Math.random() * (chars.length - 1))];
395    return result;
396}
397
398dnnsf.initParameters = function (def, field, ensureItSupportsExpressions) {
399    if (!def || def.Parameters == undefined || !field)
400        return;
401
402    for (var i = 0; i < def.Parameters.length; i++) {
403
404        var p = def.Parameters[i];
405        if (ensureItSupportsExpressions && (p.Type == 'Select' || p.Type == 'FieldSelect')
406            && ($.type(field.Parameters[p.Id]) != "object" || (!field.Parameters[p.Id].hasOwnProperty('Value') && !field.Parameters[p.Id].hasOwnProperty('IsExpression'))))
407            field.Parameters[p.Id] = { Value: field.Parameters[p.Id], IsExpression: false, Expression: '' };
408
409        // action list need to be initialized to empty arrays
410        if (p.Type == 'ActionList' && !field.Parameters[p.Id]) {
411            field.Parameters[p.Id] = [];
412        } else if (p.Type == 'ActionList' && field.Parameters[p.Id]) {
413            field.Parameters[p.Id] = $.grep(field.Parameters[p.Id], function (e) { return !e.IsDeleted });
414        }
415
416        // check either this parameter already has a value
417        if (typeof field.Parameters[p.Id] != 'undefined')
418            continue;
419        if (p.Id != 'DataSource') {
420            if (typeof field.Parameters[p.Id] != 'undefined')
421                continue;
422            if (p.Type == 'Select' || p.Type == 'FieldSelect' || p.Type == 'MultipleFieldSelect')
423                field.Parameters[p.Id] = {
424                    Expression: '',
425                    Value: p.DefaultValue ? g_localizeMaybeJson(p.DefaultValue) : '',
426                    IsExpression: false
427                };
428            else field.Parameters[p.Id] = p.DefaultValue ? g_localizeMaybeJson(p.DefaultValue) : '';
429        } else {
430            // check either this parameter already has a value
431            if (typeof field.Parameters[p.Id] != 'undefined') {
432                // try to convert to object format
433                if (!field.Parameters[p.Id].hasOwnProperty('SupportsExpressions')) {
434                    // if already an object with IsExpression
435                    if (field.Parameters[p.Id].hasOwnProperty('IsExpression')) {
436                        field.Parameters[p.Id].SupportsExpressions = true;
437                    }
438                    else {
439                        field.Parameters[p.Id] = {
440                            SupportsExpressions: false,
441                            Expression: '',
442                            Value: field.Parameters[p.Id],
443                            IsExpression: false,
444                            Parameters: {}
445                        }
446
447                    }
448                }
449                continue;
450            }
451
452            field.Parameters[p.Id] = p.DefaultValue ? g_localizeMaybeJson(p.DefaultValue) : ({
453                SupportsExpressions: p.Settings && p.Settings['SupportsExpressions'] == 'true',
454                Expression: '',
455                Value: '',
456                IsExpression: false,
457                Parameters: {}
458            });
459        }
460        //  maybe we have non-localized default settings
461        if (!field.Parameters[p.Id] && !p.DefaultValue && p.Settings && p.Settings['Defaults']) {
462            var val = p.Settings['Defaults'];
463            //  also see g_localizeMaybeJson; it will throw exception if not json
464            if (val && (val[0] == '[' || val[0] == '{')) {
465                var processBool = (val[0] != '[');
466                val = $.parseJSON(val);
467                //  we only can have arrays of bools ?
468                if (!processBool) {
469                    field.Parameters[p.Id] = {};
470                    for (var j = 0; val.length > j; ++j)
471                        field.Parameters[p.Id][val[j]] = true;
472                    return;
473                }
474            }
475            field.Parameters[p.Id] = val;
476        }
477
478        // booleans will come as strings, convert them to true bool
479        if (typeof (field.Parameters[p.Id]) === 'object') {
480            $.each(field.Parameters[p.Id], function (key, value) {
481                field.Parameters[p.Id][key] = dnnsf.tryParseBool(value);
482            });
483        } else {
484            field.Parameters[p.Id] = dnnsf.tryParseBool(field.Parameters[p.Id]);
485        }
486
487    }
488
489}
490
491dnnsf.includeJs = function (window, file, callback) {
492    var head = window.document.getElementsByTagName('head')[0];
493    var script = window.document.createElement('script');
494    script.type = 'text/javascript';
495    script.src = file;
496    script.onload = script.onreadystatechange = function () {
497        // execute dependent code
498        if (callback) callback();
499        // prevent memory leak in IE
500        head.removeChild(script);
501        script.onload = null;
502    };
503    head.appendChild(script);
504}
505
506dnnsf.includeCss = function (path) {
507    $('<link>')
508        .appendTo('head')
509        .attr({
510            type: 'text/css',
511            rel: 'stylesheet',
512            href: path
513        });
514}
515
516dnnsf.asQueryString = function (obj) {
517    var qs = '';
518    for (var k in obj) {
519        if (!obj.hasOwnProperty(k))
520            continue;
521        qs += encodeURIComponent(k) + '=' + encodeURIComponent(obj[k]) + '&';
522    }
523    if (qs.length)
524        qs = qs.substring(0, qs.length - 1)
525    return qs;
526}
527
528dnnsf.appendQueryToUrl = function (url, query) {
529    if (url[url.length - 1] == '?' || url[url.length - 1] == '&')
530        url = url.substr(0, url.length - 1);
531
532    var sep = url.indexOf('?') == -1 ? '?' : '&';
533
534    if ("string" == typeof query)
535        url += sep + query;
536    else for (var k in query) {
537        if (!query.hasOwnProperty(k))
538            continue;
539        url += sep + encodeURIComponent(k) + '=' + encodeURIComponent(query[k]);
540        sep = '&';
541    }
542
543    return url;
544};
545
546dnnsf.getTimezoneOffset = function (date) {
547    function pad(num) {
548        var norm = Math.floor(Math.abs(num));
549        return (norm < 10 ? '0' : '') + norm;
550    }
551
552    var local = date || new Date();
553    var tzo = -local.getTimezoneOffset();
554    var sign = tzo >= 0 ? '+' : '-';
555
556    return sign + pad(tzo / 60)
557        + ':' + pad(tzo % 60);
558};
559
560dnnsf.loadJsFromHtml = function (html) {
561    var scripts = $(html).find('script');
562    if (scripts.length <= 0)
563        return;
564    var filesToLoad = [];
565    $.each(scripts, function (i, v) {
566        if ($(v).attr('src') != undefined)
567            filesToLoad.push({ src: $(v).attr('src') })
568        else
569            filesToLoad.push({ toEval: $(v).text() })
570    });
571    loadJs(filesToLoad[0]);
572
573    function loadJs(js) {
574        if (js.toEval) {
575            eval(js.toEval)
576            filesToLoad.shift();
577            filesToLoad.length && loadJs(filesToLoad[0]);
578        } else {
579            filesToLoad.shift();
580            $.ajax({
581                cache: true,
582                url: js.src,
583                dataType: "script",
584                success: function () {
585                    if (filesToLoad.length && filesToLoad[0].toEval) {
586                        eval(filesToLoad[0].toEval);
587                        filesToLoad.shift();
588                    }
589                    filesToLoad.length && loadJs(filesToLoad[0]);
590                }
591            });
592        }
593    }
594}
595
596dnnsf.events = {
597
598    _listeners: {},
599
600    listen: function (messageType, mid, fn) {
601        if (!dnnsf.events._listeners[messageType])
602            dnnsf.events._listeners[messageType] = {};
603        dnnsf.events._listeners[messageType]['mid' + mid] = fn;
604    },
605
606    broadcast: function (messageType, data, fnDone) {
607        if (!dnnsf.events._listeners[messageType]) {
608            fnDone && fnDone();
609            return;
610        }
611        var listenerCount = Object.keys(dnnsf.events._listeners[messageType]).length;
612        var listenerResponses = [];
613        $.each(dnnsf.events._listeners[messageType], function (i, fn) {
614            var fnHandleResponse = function (response) {
615                response && listenerResponses.push(response);
616                listenerCount--;
617                if (listenerCount == 0)
618                    fnDone(listenerResponses);
619            };
620
621            fn(data, fnHandleResponse);
622        });
623
624    },
625    emittedEvents: [],
626    on: function (event, fn) {
627        if (this.emittedEvents[event] == null) {
628            this.emittedEvents[event] = [];
629        }
630        var id = dnnsf.uniqueId('event');
631        this.emittedEvents[event][id] = {
632            id: id,
633            callback: typeof fn === "function" ? fn : function () { console.log(this); console.error('dnnsfEvents: ' + event + ': Check the callBack function') }
634        }
635        return id;
636    },
637    emit: function (event, data) {
638        if (this.emittedEvents[event] != null) {
639            for (id in this.emittedEvents[event]) {
640                if (this.emittedEvents[event].hasOwnProperty(id))
641                    this.emittedEvents[event][id].callback.call(data || {});
642            }
643        }
644    },
645    unbind: function (event, id) {
646        if (this.emittedEvents[event] != null && this.emittedEvents[event][id] != null) {
647            delete this.emittedEvents[event][id];
648        }
649    }
650    /*
651    var eventId = dnnsf.events.on('aaa', function () { console.log(this //will log {date:11111}) })
652    dnnsf.events.emit('aaa', { date: 11111 })
653    dnnsf.events.unbind('aaa', eventId);
654    */
655}
656
657dnnsf.configUtils = {
658
659    groupDefinitions: function (defs, fnInclude) {
660        var defGroups = {};
661        $.each(defs, function (i, o) {
662            if (fnInclude && !fnInclude(o))
663                return;
664            if (o.Groups.length === 0 && o.Settings['Group'] === '')
665                return;
666
667            o.Groups && $.each(o.Groups, function (ig, group) {
668                if (!defGroups[group])
669                    defGroups[group] = [];
670                defGroups[group].push(o);
671            });
672
673            if (!defGroups[o.Settings['Group']])
674                defGroups[o.Settings['Group']] = [];
675            defGroups[o.Settings['Group']].push(o);
676        });
677        return defGroups;
678    }
679}
680
681dnnsf.hasProps = function (obj) {
682    for (var k in obj)
683        if (obj.hasOwnProperty(k))
684            return true;
685    return false;
686};
687
688dnnsf.copyToClipboard = function (val) {
689    var $temp = $("<textarea>");
690    $("body").append($temp);
691    $temp.css({
692        'position': 'absolute',
693        'top': '0',
694        'z-index': '-9999999'
695    });
696    $temp.val(val).select();
697    $temp.focus();
698
699    var result = document.execCommand("copy");
700    $temp.remove();
701    return result;
702
703}
704
705dnnsf.promiseResponse = function (method, url, getSvcFramework) {
706    return new Promise(function (resolve, reject) {
707        var xhr = new XMLHttpRequest();
708        xhr.open(method, url);
709
710        if (getSvcFramework) {
711            var svcFramework = getSvcFramework(dnnsf.moduleId);
712            xhr.setRequestHeader("RequestVerificationToken", svcFramework.getAntiForgeryValue());
713        }
714
715        xhr.onload = function () {
716            if (this.status >= 200 && this.status < 300) {
717                resolve(xhr);
718            }
719        };
720        xhr.onerror = function () {
721            reject(xhr);
722        };
723        xhr.send();
724    });
725};
726
727// Goes through the noConflict chain to identify all loaded bootstrap instances and retrieves their version. 
728// The result can contain duplicate version numbers if the same BS version is loaded multiple times from different files (e.g. DNN Skin and our modules).
729// return type: undefined | string[]
730dnnsf.getBootstrapVersions = function () {
731    if (!$ || !$.fn.tooltip || !$.fn.tooltip.Constructor) {
732        return undefined;
733    }
734
735    // noConflict overrides the $.fn.tooltip, so we need to make sure we preserve the latest version.
736    var latestPlugin;
737    var result = [$.fn.tooltip.Constructor.VERSION];
738    var noConflict = $.fn.tooltip.noConflict;
739    if (noConflict) {
740        noConflict = noConflict.bind($.fn.tooltip); // function relies on `this` so we need to properly bind it.
741        latestPlugin = noConflict();
742        $.fn.tooltip = latestPlugin;
743    }
744
745    while (noConflict) {
746        noConflict();
747        var oldPlugin = $.fn.tooltip;
748        $.fn.tooltip = latestPlugin;
749
750        // Check if we still have a reference to a bootstrap object. $.fn.tooltip is also used by jQuery UI tooltip.
751        if (!oldPlugin || !oldPlugin.Constructor) {
752            break;
753        }
754
755        result.push(oldPlugin.Constructor.VERSION);
756        noConflict = oldPlugin.noConflict;
757        if (noConflict) {
758            noConflict = noConflict.bind(oldPlugin); // function relies on `this` so we need to properly bind it.
759        }
760    }
761
762    return result;
763};
764
765dnnsf.bootstrap3Loaded = function () {
766    var versionList = dnnsf.getBootstrapVersions();
767    return versionList && versionList.some(function(versionStr) { return parseInt(versionStr[0]) === 3; });
768}
769
770dnnsf.bootstrap5Loaded = function () {
771    var versionList = dnnsf.getBootstrapVersions();
772    return versionList && versionList.some(function(versionStr) { return parseInt(versionStr[0]) === 5; });
773}
774
775dnnsf.api = dnnsf.api || {};
776
777var initDnnsf = function (angular) {
778    angular.module('dnnsf', [])
779        .service('dnnsf', ['$timeout', function ($timeout) {
780
781            this.env = dnnsf;
782            this.start = new Date().getTime();
783
784            // copy everything in dnnsf
785            for (var key in dnnsf)
786                this[key] = dnnsf[key];
787        }])
788        .factory('dnnsfHttp', ['$http', function ($http) {
789            function createShortMethods(httpSvc, names) {
790                $.each(arguments, function (idx, name) {
791                    if (typeof name != 'string')
792                        return;
793
794                    httpSvc[name] = function (moduleId, url, config, withAntiForgery) {
795                        return httpSvc(moduleId, $.extend({}, config || {}, {
796                            method: name,
797                            url: url
798                        }), withAntiForgery);
799                    };
800                });
801            }
802
803            function createShortMethodsWithData(httpSvc, names) {
804                $.each(arguments, function (idx, name) {
805                    if (typeof name != 'string')
806                        return;
807
808                    httpSvc[name] = function (moduleId, url, data, config, withAntiForgery) {
809                        return httpSvc(moduleId, $.extend({}, config || {}, {
810                            method: name,
811                            url: url,
812                            data: data
813                        }), withAntiForgery);
814                    };
815                });
816            }
817
818            var dnnsfHttp = function (moduleId, options, withAntiForgery) {
819                if (withAntiForgery == undefined) {
820                    withAntiForgery = true;
821                }
822                options = options || {};
823
824                if (withAntiForgery && !dnnsfjQuery.ServicesFramework) {
825                    console.error('Could not initialize DNN ServicesFramework to inject authorization headers. The request will be made without authorization. Make sure that the IServicesFramework.RequestAjaxScriptSupport and RequestAjaxAntiForgerySupport methods are called when rendering the page on the server side.');
826                }
827
828                if (withAntiForgery && dnnsfjQuery.ServicesFramework) {
829                    var svcFramework = dnnsfjQuery.ServicesFramework(moduleId);
830                    var stubXhr = {
831                        headers: {},
832                        setRequestHeader: function (key, value) {
833                            stubXhr.headers[key] = value;
834                        }
835                    };
836                    svcFramework.setModuleHeaders(stubXhr);
837
838                    options.headers = $.extend({}, options.headers || {}, stubXhr.headers);
839                }
840
841                return $http(options);
842            };
843
844            createShortMethods(dnnsfHttp, 'get', 'delete', 'head', 'jsonp');
845            createShortMethodsWithData(dnnsfHttp, 'post', 'put', 'patch');
846
847            return dnnsfHttp;
848        }])
849        .factory('myInterceptor', ['$log', '$q', function ($log, $q) {
850            var myInterceptor = {
851                'response': function (response) {
852                    if (response.status == 200 && response.data && response.data.error) {
853                        console.log("App HTTP error", response);
854                        // if (response.data.redirect) {
855                        //     window.top.location = response.data.redirect;
856                        //     return;
857                        // }
858                        // alert('Error getting response from ' + response.config.url + '.\n\nError: ' + response.data.error);
859                    }
860                    return response;
861                },
862                'responseError': function (rejection) {
863                    if (rejection.status && rejection.status != 404 && !rejection.config.ignoreInterceptor) {
864                        // status:0 means an unitialized ajax request, 
865                        // it happens for example the page is refreshed before the ajax request gets the chance to make connection
866                        console.log("HTTP error", rejection);
867                        // alert('error' + rejection);
868                    }
869                    return $q.reject(rejection);
870                }
871            };
872
873            return myInterceptor;
874        }])
875        .config(['$httpProvider', function ($httpProvider) {
876            $httpProvider.interceptors.push('myInterceptor');
877        }]);
878}
879window.angular ? initDnnsf(angular) : '';
880window.dnnsfAngular15 ? initDnnsf(dnnsfAngular15) : '';
881

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.