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