### Dojo XHR GET Request Source: https://github.com/tritondigital/player-sdk/blob/master/src/lib/dojo/tests/request/xhr.html Demonstrates a basic GET request using dojo/request/xhr. It checks for the presence of the `then` and `cancel` methods on the deferred object and verifies the response's ready state. ```javascript var tests = [ function xhrGet(t) { var d = new doh.Deferred(); var td = xhr.get("xhr.html", { preventCache: true }); t.t(!!(td.then && td.cancel)); td.response.then(function(response) { t.is(4, response.xhr.readyState); return response; }); td.then(lang.hitch(d, "callback")); return d; } ]; ``` -------------------------------- ### Dojo XHR GET Request with Query Parameters and JSON Handling Source: https://github.com/tritondigital/player-sdk/blob/master/src/lib/dojo/tests/request/xhr.html Shows how to send GET requests with complex query parameters and specifies 'json' as the handling format. It asserts the structure and values of the parsed JSON response and verifies the final URL. ```javascript function xhrGetQuery(t) { var d = new doh.Deferred(); var td = xhr.get("xhrDummyMethod.php?color=blue", { query: { foo: ["bar", "baz"], thud: "thonk", xyzzy: 3 }, handleAs: "json" }); td.then(d.getTestErrback(function(data) { var query = data.query; t.t(!!(query.color && query.foo && query.foo.length && query.thud && query.xyzzy)); t.is("blue", query.color); t.is(2, query.foo.length); t.is("thonk", query.thud); t.is(3, query.xyzzy); td.response.then(d.getTestCallback(function(response) { t.is("xhrDummyMethod.php?color=blue&foo=bar&foo=baz&thud=thonk&xyzzy=3", response.url); })); })); return d; } ``` -------------------------------- ### Dojo Parser Example Source: https://github.com/tritondigital/player-sdk/blob/master/src/lib/dojo/tests/html/test_set.html An example demonstrating the dojo parser's functionality, specifically how it handles content parsing and event handling. It includes assertions for parser invocation and inherited properties. ```javascript var cont = '
'; var parserCalled, inherited; handle = aspect.after(parser, "parse", function(args){ parserCalled = true; inherited = args.inherited; }, true); html.set( dom.byId("pane1"), cont, { parseContent: true } ); doh.t(parserCalled, "parser was called"); doh.f("dir" in inherited, "no dir specified"); doh.f("lang" in inherited, "no lang specified"); ``` -------------------------------- ### Set and Get Element Opacity using dojo.style Source: https://github.com/tritondigital/player-sdk/blob/master/src/lib/dojo/tests/_base/html.html This snippet demonstrates how to set and get the opacity of an HTML element using `dojo.style`. It shows setting opacity to a specific value and then retrieving it, including handling floating-point comparisons. Dependencies include the dojo toolkit. ```javascript doh.is(1, dojo.style('sq100nopos', 'opacity')); // never compare floating numbers directly! doh.is((0.1).toFixed(4), Number(dojo.style('sq100nopos', 'opacity', 0.1)).toFixed(4)); doh.is((0.8).toFixed(4), Number(dojo.style('sq100nopos', 'opacity', 0.8)).toFixed(4)); ``` ```javascript dojo.style('sq100nopos', { 'opacity': 0.1 }); doh.is((0.1).toFixed(4), Number(dojo.style('sq100nopos', 'opacity')).toFixed(4)); dojo.style('sq100nopos', { 'opacity': 0.8 }); doh.is((0.8).toFixed(4), Number(dojo.style('sq100nopos', 'opacity')).toFixed(4)); ``` -------------------------------- ### Dojo CSS Styling Examples Source: https://github.com/tritondigital/player-sdk/blob/master/src/lib/dojo/tests/html/test_set.html Provides CSS class definitions for styling elements within a Dojo application. Includes styles for borders, dimensions, lists, and text appearance. ```css .box { border: 1px solid black; height: 190px; width: 80%; overflow: auto; } .zork { width: 200px; margin: 10px; list-style-type: none; } .notdone { color: #999; background-color: #ccc; } .done { color: #fff; background-color: #090; } .done li { border: 1px; background-color: orange; width: 180px; } .red { color: red; } ``` -------------------------------- ### Dojo XHR PUT Request with Query and JSON Data Source: https://github.com/tritondigital/player-sdk/blob/master/src/lib/dojo/tests/request/xhr.html Shows how to perform a PUT request, including query parameters and JSON data. It checks if the server correctly processed the 'color' parameter. ```javascript function xhrPut(t) { var d = new doh.Deferred(); var td = xhr.put("xhrDummyMethod.php", { query: { foo: "bar" }, data: { color: "blue" }, handleAs: "json" }).then(d.getTestCallback(function(data) { t.t(!!data); var put = data.put; t.t(!!(put && put.color)); t.is("blue", put.color); }), function(error) { d.errback(error); }); // t.t(td instanceof dojo.Deferred); return d; } ``` -------------------------------- ### Dojo Synchronous XHR GET Request Source: https://github.com/tritondigital/player-sdk/blob/master/src/lib/dojo/tests/request/xhr.html Shows how to make a synchronous GET request using dojo/request/xhr. It checks if a callback function is executed immediately after the request completes. ```javascript function xhrSync(t) { var called = false; xhr.get("xhr.html", { sync: true }).then(function() { called = true; }); t.t(called, "'called' should be set to true"); } ``` -------------------------------- ### Initialize Triton Digital Player SDK (JavaScript) Source: https://context7.com/tritondigital/player-sdk/llms.txt Demonstrates how to create a new instance of the Triton Digital Player SDK. The configuration object includes settings for analytics, core modules like MediaPlayer and NowPlayingApi, and event callbacks for player readiness and errors. ```javascript var tdSdkConfig = { analytics: { active: true, debug: false, appInstallerId: 'myapp', trackingId: null, trackingEvents: ['play', 'stop', 'pause', 'resume'], sampleRate: 5, platformId: 'prod01' }, coreModules: [ { id: 'MediaPlayer', playerId: 'player_container', platformId: 'prod01', techPriority: ['Html5', 'Flash'], hls: true, audioAdaptive: false, sbm: { active: true, aSyncCuePointFallback: true }, geoTargeting: { desktop: { isActive: true }, iOS: { isActive: true }, android: { isActive: true } }, idSync: { station: 'TRITONRADIOMUSIC', gender: 'm', age: 25 } }, { id: 'NowPlayingApi', platformId: 'prod01' }, { id: 'Npe' }, { id: 'PlayerWebAdmin' }, { id: 'SyncBanners', elements: [ { id: 'td_synced_bigbox', width: 300, height: 250 }, { id: 'td_synced_leaderboard', width: 728, height: 90 } ], vastCompanionPriority: ['static', 'iframe', 'html'] } ], playerReady: function() { console.log('Player is ready'); }, configurationError: function(e) { console.error('Configuration error:', e); }, moduleError: function(e) { console.error('Module error:', e); }, adBlockerDetected: function(e) { console.warn('Ad blocker detected:', e.data.message); } }; var player = new TDSdk(tdSdkConfig); ``` -------------------------------- ### AMD Module Loading and Instantiation (JavaScript) Source: https://github.com/tritondigital/player-sdk/blob/master/src/lib/dojo/tests/parser/parser.html Illustrates loading and instantiating AMD modules using Dojo. It defines aliases for modules like 'AMDWidget', 'AMDWidget2', 'AMDWidget3', and 'amdmodule', and shows how to return an array containing an instance of 'amdmodule'. ```javascript AMDWidget: "dojo/tests/resources/AMDWidget", AMDWidget2: "dojo/tests/resources/AMDWidget2" AMDWidget3: "dojo/tests/resources/AMDWidget3" amdmodule: "dojo/tests/resources/amdmodule" return [amdmodule(value)]; ``` -------------------------------- ### Dojo Ready and Require Initialization Source: https://github.com/tritondigital/player-sdk/blob/master/src/lib/dojo/tests/_base/loader/ready.html This snippet shows how to use the dojo/ready module to execute functions after the DOM is ready. It demonstrates different ways to call ready, including with a context object and a method name. It also integrates with the require system to run tests using doh. ```javascript require(["dojo/ready"], function(ready){ var check1, check2, check3, someObject = {}, someInstance = { someMethod:function() { check3 = 2;} }; ready(function() { check1= 1; }); ready(someObject, function() { check2= this; }); ready(someInstance, "someMethod"); require(["dojo", "doh"], function(dojo, doh) { dojo.ready(function() { doh.register("t", [ function(t){ t.is(check1, 1); t.is(check2, someObject); t.is(check3, 2); } ]); doh.runOnLoad(); }); }); }); ``` -------------------------------- ### Configure and Initialize Coolio Calendar with Dojo Source: https://github.com/tritondigital/player-sdk/blob/master/src/lib/dojo/tests/_base/loader/coolio/coolio-dev-legacy-async-with-packageMap.html This JavaScript code configures Dojo's asynchronous loading and package mapping to use the Coolio Calendar. It sets up custom package locations and scope names for Dojo, Dijit, and Coolio, then initializes the calendar and parses the DOM. ```javascript var startTime = (new Date()).getTime(); var dojoConfig = { // this is an example of developing with synchronous modules async: 0, // set baseUrl === to the page URL; this overrides dojo's desire to be the center of the world baseUrl: ".", packages: [ { // the dojo package for non-coolio use name: "dojo", location: "../../../.." }, { // the dijit package for non-coolio use name: "dijit", location: "../../../../../dijit" }, { // the dojox package which is always mapped when rescoping name: "dojox", location: "../../../../../dojox" }, { // sandboxed, separate instance dojo package for coolio use; notice it uses the same code as the non-coolie dojo package // all "dojo*" modules ids are mapped to "cdojo*" within this package name: "cdojo", location: "../../../..", packageMap: { dojo: "cdojo", dijit: "cdijit" } }, { // sandboxed, separate instance dijit package for coolio use; notice it uses the same code as the non-coolie dijit package // all "dojo*" modules ids are mapped to "cdojo*" within this package // all "dijit*" modules ids are mapped to "cdijit*" within this package name: "cdijit", location: "../../../../../dijit", packageMap: { dojo: "cdojo", dijit: "cdijit" } }, { // all "dojo*" modules ids are mapped to "cdojo*" within this package // all "dijit*" modules ids are mapped to "cdijit*" within this package name: "coolio", location: ".", packageMap: { dojo: "cdojo", dijit: "cdijit" } } ] }; dojo.require("cdojo"); require({async: "legacyAsync"}); // the next two dojo.requires load the dojo and dijit instances dojo.require("dijit.Calendar"); dojo.require("dojo.parser"); // coolio calendars load and are built on top of the cdojo and cdijit instances dojo.require("coolio.calendar"); dojo.ready(function() { coolio.calendar("c1"); dojo.parser.parse(); console.log("total load time: " + ((new Date()).getTime() - startTime) / 1000 + "s"); console.log(dojo); console.log(dijit); console.log(cdojo); console.log(cdijit); console.log("dojo._scopeName=" + dojo._scopeName); console.log("cdojo._scopeName=" + cdojo._scopeName); console.log("dijit._scopeName=" + dijit._scopeName); console.log("cdijit._scopeName=" + cdijit._scopeName); }); ``` -------------------------------- ### Dojo XHR GET Request for 404 Source: https://github.com/tritondigital/player-sdk/blob/master/src/lib/dojo/tests/request/xhr.html Tests how dojo/request/xhr handles a 404 Not Found error. It expects the response status to be 404 and ensures the error is caught correctly. ```javascript function xhrGet404(t) { var d = new doh.Deferred(); var td = xhr.get("xhr_blarg.html").response.then( function(response) { d.errback(false); }, d.getTestCallback(function(error) { t.is(404, error.response.status); return error; }) ); return d; } ``` -------------------------------- ### Test Animation Property with Function Start Value Source: https://github.com/tritondigital/player-sdk/blob/master/src/lib/dojo/tests/_base/fx.html Tests the `animateProperty` function where the `start` value for a property is a function. This function receives the node as an argument and returns the start value. It verifies that the node reference is correctly passed to the `start` function. ```javascript baseFx.animateProperty({ node: "thud", properties:{ width: { start: function(node){ d.getTestErrback(function(){ doh.is("thud", node.id); }); return 100; }, end: 200 } }, duration:50, onEnd: d.getTestCallback(function(){}) }).play(); ``` -------------------------------- ### Configure and Load Coolio Calendar with Dojo AMD Source: https://github.com/tritondigital/player-sdk/blob/master/src/lib/dojo/tests/_base/loader/coolio/coolio-dev-async.html This JavaScript code configures Dojo's AMD loader with custom package mappings for the Coolio and sandboxed 'cdojo'/'cdijit' modules. It then loads the 'coolio/calendar-amd' module, along with 'dojo/parser', 'dijit/Calendar', and 'dojo/domReady!', to initialize and display a calendar. The code also logs the scope names of the loaded modules and the total loading time. ```javascript var startTime = (new Date()).getTime(); var dojoConfig = { async: 1, baseUrl: ".", packages: [ { name: "dojo", location: "../../../.." }, { name: "dijit", location: "../../../../../dijit" }, { name: "cdojo", location: "../../../.." }, { name: "cdijit", location: "../../../../../dijit" }, { name: "coolio", location: "." } ], map: { cdojo: { dojo: "cdojo", dijit: "cdijit" }, cdijit: { dojo: "cdojo", dijit: "cdijit" }, coolio: { dojo: "cdojo", dijit: "cdijit" } } }; require(["coolio/calendar-amd", "dojo/parser", "dijit/Calendar", "dojo/domReady!"], function(calendar, parser) { calendar("c1"); parser.parse(); console.log("total load time: " + ((new Date()).getTime() - startTime) / 1000 + "s"); console.log(dojo); console.log(dijit); console.log(cdojo); console.log(cdijit); console.log("dojo._scopeName=" + dojo._scopeName); console.log("cdojo._scopeName=" + cdojo._scopeName); console.log("dijit._scopeName=" + dijit._scopeName); console.log("cdijit._scopeName=" + cdijit._scopeName); }); ``` -------------------------------- ### Dojo XHR Response Header Check Source: https://github.com/tritondigital/player-sdk/blob/master/src/lib/dojo/tests/request/xhr.html Verifies that response headers are accessible. This example specifically checks for the presence of the 'Content-Type' header in the response. ```javascript function xhrHeaders(t) { var d = new doh.Deferred(); xhr.get('xhr.html').response.then(d.getTestCallback(function(response){ t.isNot(null, response.getHeader('Content-Type')); }),function(error){ d.errback(error); }); return d; } ``` -------------------------------- ### Create DOM Elements with Dojo Source: https://github.com/tritondigital/player-sdk/blob/master/src/lib/dojo/tests/_base/html_element.html Demonstrates creating DOM elements using `dojo.create`. It covers basic creation, creation with attributes (like class, title, style), and placement within the document. It also shows how to create elements with innerHTML and how to insert elements relative to existing nodes. ```javascript var n = dojo.create("div"); dojo.byId("holder1").appendChild(n); dojo.addClass(n, "testing"); var q = dojo.query(".testing"); doh.is(1, q.length); doh.is("div", n.nodeName.toLowerCase()); ``` ```javascript var n = dojo.create('div', { "class":"hasClass", title:"foo", style:"border:2px solid #ededed; padding:3px" }); // plain placement: dojo.byId("holder1").appendChild(n); doh.t(dojo.hasClass(n, "hasClass")); doh.is("foo", dojo.attr(n, "title")); ``` ```javascript var n = dojo.create("div", null, dojo.body()); n.innerHTML = "

a

"; var q = dojo.query("p", n); doh.is(1, q.length); doh.t(dojo.hasClass(q[0], "bar")); ``` ```javascript var n = dojo.create("div", { innerHTML: "

a

" }, dojo.body()); var q = dojo.query("p", n); doh.is(1, q.length); doh.t(dojo.hasClass(q[0], "bar2")); ``` ```javascript var ref = dojo.query("#holder2 > li.last")[0]; var n = dojo.create("li", { innerHTML:"middle", "class":"middleNode" }, ref, "before"); doh.is(3, dojo.query("#holder2 li").length); var nn = dojo.create("li", { innerHTML:"afterLast", "class":"afterLast" }, ref, "after"); var classes = ["first", "middleNode", "last", "afterLast"]; var q = dojo.query("#holder2 li"); doh.is(4, q.length); q.forEach(function(n, i){ doh.is(classes[i], n.className); }); ``` ```javascript var es = ["div", "a", "span", "br", "table", "ul", "dd", "img", "h2"]; dojo.forEach(es, function(el){ dojo.create(el, null, "holder3"); }); var q = dojo.query(">", "holder3"); doh.is(q.length, es.length); // destroy this list: q.forEach(dojo.destroy); // q = dojo.query(">", "holder3"); // doh.is(q.length, 0); ``` ```javascript var n = dojo.create("h2", { "class":"restored", innerHTML:"The End" }, dojo.body()); doh.is(1, dojo.query(".restored").length); dojo.destroy(n); ``` -------------------------------- ### Dojo Cross-Domain Loading Test Setup (JavaScript) Source: https://github.com/tritondigital/player-sdk/blob/master/src/lib/dojo/tests/_base/loader/xdomain/xdomain.html Sets up arrays for logging and execution sequences related to cross-domain loading tests. It configures `require.isXdUrl` to identify URLs that should be treated as cross-domain and initiates the test runner. ```javascript var xdomainLog= []; var xdomainExecSequence= []; require(["dojo", "doh", "dojo/has"], function(dojo, doh, has){ if(!("legacyMode" in require)){ doh.register("xdomain", function(t){ t.is("dojotoolkit.org", define.vendor); t.is(true, "legacyMode" in require); }); doh.runOnLoad(); return; } // pretend that everything except the stuff in dojo/tests/_base/loader/xdomain is xdomain require.isXdUrl = function(url){ return !/loader\/xdomain/.test(url) && !/syncBundle/.test(url); }; // each of these dojo.requires a xdomain module which puts the loader in xdomain loading mode, // then dojo.requires a local tree of modules with various loading challenges. Many of the loading // challenges are in local1; therefore we test when that module causes the xdomain shift and when // the loader is already in xdomain when that module is demanded if(dohArgs.variation==1){ dojo.require("dojo.tests._base.loader.xdomain.local1"); //>>excludeStart("srcVersion", kwArgs.copyTests=="build"); if(dohArgs.async==0){ // can't stop the local module from completely executing... xdomainLog.push(11, dojo.tests._base.loader.xdomain.local1==="stepOnLocal1"); xdomainLog.push(12, dojo.require("dojo.tests._base.loader.xdomain.local1")==="stepOnLocal1"); xdomainLog.push(13, require("dojo/tests/_base/loader/xdomain/local1")==="stepOnLocal1"); }else{ xdomainLog.push(11, dojo.getObject("dojo.tests._base.loader.xdomain.local1")===undefined); } //>>excludeEnd("srcVersion"); }else{ dojo.require("dojo.tests._base.loader.xdomain.local2"); //>>excludeStart("srcVersion", kwArgs.copyTests=="build"); if(dohArgs.async==0){ // can't stop the local module from completely executing... xdom ``` -------------------------------- ### Get and Set CSS Styles with NodeList Source: https://github.com/tritondigital/player-sdk/blob/master/src/lib/dojo/tests/_base/NodeList.html Demonstrates how to get and set CSS properties for elements within a NodeList. It includes tests for individual property retrieval and batch setting, as well as resetting styles. ```javascript function styleGet(){ // test getting var tnl = new NodeList(s); doh.is(1, tnl.style("opacity")[0]); tnl.push(t); dojo.style(t, "opacity", 0.5); doh.is(0.5, tnl.style("opacity").slice(-1)[0]); tnl.style("opacity", 1); }, function styleSet(){ // test setting var tnl = new NodeList(s, t); tnl.style("opacity", 0.5); doh.is(0.5, dojo.style(tnl[0], "opacity")); doh.is(0.5, dojo.style(tnl[1], "opacity")); // reset tnl.style("opacity", 1); }, function style(){ var tnl = new NodeList(s, t); tnl.style("opacity", 1); doh.is(1, tnl.style("opacity")[0]); dojo.style(t, "opacity", 0.5); doh.is(1.0, tnl.style("opacity")[0]); doh.is(0.5, tnl.style("opacity")[1]); // reset things tnl.style("opacity", 1); } ``` -------------------------------- ### Configure and Load Dojo 0.4.3 and 1.0 Source: https://github.com/tritondigital/player-sdk/blob/master/src/lib/dojo/tests/_base/loader/scope04.html This snippet configures Dojo 0.4.3 and Dojo 1.0 for multiversion loading. It sets up djConfig, including scope maps for Dojo 1.0, and uses dojo.require and dojo10.require to load specific modules. It also includes event handlers and a timeout function to demonstrate functionality. ```javascript djConfig = { isDebug: true }; djConfig.parseOnLoad = true; djConfig.baseUrl = "../../../\n"; djConfig.scopeMap = [ ["dojo", "dojo10"], ["dijit", "dijit10"], ["dojox", "dojox10"] ]; do.require("dojo.widget.DropdownDatePicker"); dojo10.require("dijit.Calendar"); dojo10.require("dojo.date.locale"); dojo10.require("dojo.parser"); // scan page for widgets do.addOnLoad(function(){ dojo.byId("output043").innerHTML = dojo.version.toString(); }); dojo10.addOnLoad(function(){ dojo.byId("output10").innerHTML = dojo10.version.toString(); }); function myHandler(id,newValue){ console.debug("onChange for id = " + id + ", value: " + newValue); } function foobar(){ dojo.byId("typeOut").innerHTML = (typeof dojo.addClass); } setTimeout(foobar, 2000); ``` -------------------------------- ### Dojo iframe GET Text Request Source: https://github.com/tritondigital/player-sdk/blob/master/src/lib/dojo/tests/request/iframe.html Tests sending a GET request using dojo/request/iframe to retrieve text data. It verifies the response data and the success of the iframe operation. The `preventCache` option is enabled. ```javascript function ioIframeGetText(t){ var d = new doh.Deferred(); var td = iframe.get("iframeDummyMethod.php?type=text", { preventCache: true }); td.then(d.getTestErrback(function(data){ t.is("iframe succeeded", data); return td.response.then(d.getTestCallback(function(response){ t.is("iframe succeeded", response.data); })); })); return d; } ``` -------------------------------- ### Dojo Iframe Utilities Setup (JavaScript) Source: https://github.com/tritondigital/player-sdk/blob/master/src/lib/dojo/tests/window/test_scroll.html Sets up essential iframe utility functions using Dojo's module system. It defines functions for scrolling elements into view, handling click events within iframes, and calculating visible element sizes, including browser-specific workarounds. ```javascript require([ "doh", "dojo/dom", "dojo/dom-attr", "dojo/dom-geometry", "dojo/dom-style", "dojo/query", "dojo/sniff", "dojo/_base/window", "dojo/window", "dojo/_base/array", "dojo/domReady!" ], function(doh, dom, domAttr, domGeom, domStyle, query, has, baseWin, winUtils, array) { // More global methods accessed by iframes _scrollIntoView = function(win,x,y,w,h){ var n = _findInput(win); var pos; if(typeof x == "number" && typeof y == "number"){ var p = baseWin.withGlobal(win, 'position', domGeom, [ n ]); pos = { x: p.x + x, y: p.y + y, w: isNaN(w) ? 1 : w, h: isNaN(h) ? 1 : h }; } baseWin.withGlobal(win, 'scrollIntoView', winUtils, [ n, pos ]); }; _onClick = function(win){ _scrollIntoView(win); }; _getVisibleSize = function(win,n){ var html = win.document.documentElement, body = win.document.body, rect = n.getBoundingClientRect(), width = Math.min(body.clientWidth || html.clientWidth, html.clientWidth || body.clientWidth), height = Math.min(body.clientHeight || html.clientHeight, html.clientHeight || body.clientHeight), pos = baseWin.withGlobal(win, 'position', domGeom, [ n ]); // adjust width and height for IE nonsense width += Math.round(rect.left - pos.x); height += Math.round(rect.top - pos.y); if(has('ie')){ width += outerScrollBarSize; } // IE10 bug for(y = 0; y < height; y++){ for(x = 0; x < width; x++){ var pointElement = win.document.elementFromPoint(x,y); if(pointElement == n){ // work around browser bugs // Opera 12.12 says the element is showing beyond the browser edge // IE 10 says for(var w = 1; (x+w) < width && win.document.elementFromPoint(x+w,y) == n; w++); for(var h = 1; (y+h) < height && win.document.elementFromPoint(x,y+h) == n; h++); return { w: w, h: h }; } } } return { w: 0, h: 0 }; }; // Below is the magic code that creates the iframes from the given template. // This should be generalized for other files to include. function getIframeSrc(id, content, doctype, rtl){ content = content.replace(/"/g/*balance"*/,"'").replace(/iframe.javascript/g,"text/javascript").replace(/' ); document.write('' ); require( // the set up script sets the base URL ["require", "simple", "dimple", "func", "doh"], function(require, simple, dimple, func) { doh.register( "simple", [ function colors(t){ t.is("blue", simple.color); t.is("dimple-blue", dimple.color); t.is("You called a function", func()); } ] ); doh.run(); } ); //This test is only in the HTML since it uses an URL for a require //argument. It will not work well in say, the Rhino tests. var path = location.href.replace(/simple-badbase\.html$/, "foo"), index = path.indexOf(":"), noProtocolPath = path.substring(index + 1, path.length).replace(/foo/, "bar"); require([path, noProtocolPath, "doh"], function() { doh.register( "fooBar", [ function fooBar(t){ t.is("foo", foo.name); t.is("bar", bar.name); } ] ); doh.run(); }); ``` -------------------------------- ### Send Text via GET using dojo.io.iframe Source: https://github.com/tritondigital/player-sdk/blob/master/src/lib/dojo/tests/io/iframe.html Tests sending a GET request to retrieve text content. It checks if the response is successful and matches the expected text. Dependencies include dojo, doh, and dojo/topic. ```javascript function ioIframeGetText(t){ var d = new doh.Deferred(); var td = dojo.io.iframe.send({ url: "../request/iframeDummyMethod.php?type=text", method: "GET", timeoutSeconds: 5, preventCache: true, handle: function(res, ioArgs){ if(!(res instanceof Error) && t.is("iframe succeeded", res)){ d.callback(true); }else{ d.errback(false); } } }); return d; } ``` -------------------------------- ### Adapting Methods for Dojo NodeList with _adaptAsForEach Source: https://github.com/tritondigital/player-sdk/blob/master/src/lib/dojo/tests/_base/NodeList.html This example shows how to adapt an existing function to work with Dojo's NodeList using the `_adaptAsForEach` utility. This allows methods defined on an object to be applied to each node within a NodeList. ```javascript var passes = false; var count = 0; var i = { setTrue: function(node){ count++; passes = true; } }; // Adapt the setTrue method to work with NodeList // The first argument is the function to adapt, the second is the object context // The third argument is optional, if true, it will pass the node as the first argument to the function dojo.NodeList.prototype.setTrue = dojo.NodeList._adaptAsForEach(i.setTrue, i); var divs = query("div").setTrue(); doh.t(passes); doh.is(count, divs.length); ``` -------------------------------- ### Dojo AMD Module Configuration and Loading (JavaScript) Source: https://github.com/tritondigital/player-sdk/blob/master/src/lib/dojo/tests/_base/loader/coolio/coolio-dev-async-with-packageMap.html Configures Dojo's AMD loader with multiple packages, including a sandboxed 'coolio' package that maps 'dojo' and 'dijit' to 'cdojo' and 'cdijit' respectively. It then loads 'coolio/calendar-amd', 'dojo/parser', 'dijit/Calendar', and 'dojo/domReady!', parses the DOM, and logs module scope names and load time. ```javascript var startTime = (new Date()).getTime(); var dojoConfig = { async: 1, baseUrl: ".", packages: [ { name: "dojo", location: "../../../.." }, { name: "dijit", location: "../../../../../dijit" }, { name: "cdojo", location: "../../../..", packageMap: { dojo: "cdojo", dijit: "cdijit" } }, { name: "cdijit", location: "../../../../../dijit", packageMap: { dojo: "cdojo", dijit: "cdijit" } }, { name: "coolio", location: ".", packageMap: { dojo: "cdojo", dijit: "cdijit" } } ] }; require(["coolio/calendar-amd", "dojo/parser", "dijit/Calendar", "dojo/domReady!"], function(calendar, parser) { calendar("c1"); parser.parse(); console.log("total load time: " + ((new Date()).getTime() - startTime) / 1000 + "s"); console.log(dojo); console.log(dijit); console.log(cdojo); console.log(cdijit); console.log("dojo._scopeName=" + dojo._scopeName); console.log("cdojo._scopeName=" + cdojo._scopeName); console.log("dijit._scopeName=" + dijit._scopeName); console.log("cdijit._scopeName=" + cdijit._scopeName); }); ``` -------------------------------- ### Set and Get Readonly Attribute with Dojo Source: https://github.com/tritondigital/player-sdk/blob/master/src/lib/dojo/tests/_base/html.html Tests setting and getting the 'readonly' attribute on an input element using dojo.attr. It verifies that the attribute can be set to true and false, and that its state is correctly reflected. ```javascript function setReadonlyInput(t){ var input = document.createElement("input"); doh.f(dojo.attr(input, "readonly")); dojo.attr(input, "readonly", true); doh.is(true, dojo.attr(input, "readonly")); dojo.attr(input, "readonly", false); doh.is(false, dojo.attr(input, "readonly")); } ``` -------------------------------- ### Set and Get Disabled Attribute with Dojo Source: https://github.com/tritondigital/player-sdk/blob/master/src/lib/dojo/tests/_base/html.html Tests setting and getting the 'disabled' attribute on an input element using dojo.attr and dojo.removeAttr. It verifies that the attribute can be set to true and false, and removed correctly. ```javascript function removeDisabledFromInput(t){ var input = document.createElement("input"); dojo.attr(input, "disabled", true); doh.t(dojo.attr(input, "disabled")); dojo.removeAttr(input, "disabled"); doh.f(dojo.attr(input, "disabled")); } ``` -------------------------------- ### Define User Configuration Callback and Dependencies (JavaScript) Source: https://github.com/tritondigital/player-sdk/blob/master/src/lib/dojo/tests/_base/loader/boot-userConfig.html This snippet demonstrates how to define a user configuration callback function and specify dependencies for the player SDK using Dojo's configuration object. The callback `userConfigCallback` is executed after dependencies are loaded, logging whether the user configuration was honored. It attempts to require `dojo/AdapterRegistry` to signify successful configuration loading. ```javascript function userConfigCallback(){ console.log("honored user config callback"); try{ require("dojo/AdapterRegistry"); console.log("honored user config"); }catch(e){ console.log("DID NOT honor user config"); } } var require = { deps:["dojo/AdapterRegistry"], callback:userConfigCallback }; ``` -------------------------------- ### DOH Test Setup for Iframe Loading (JavaScript) Source: https://github.com/tritondigital/player-sdk/blob/master/src/lib/dojo/tests/window/test_scroll.html Sets up a test case using the DOH (dojo.testing) framework to create multiple iframes and wait for them to load. It iterates through specified test elements, generating iframes in different doctype and RTL modes. Includes a timeout for the test. ```javascript doh.register("dojo.window.scroll", [ { name: "create iframes and wait for them to load", timeout: 20000, runTest: function() { loading = new doh.Deferred(); var testIframes = query('DIV[type="testIframe"]'); count = testIframes.length * 4; console.log("count is " + count); for (var i = 0; i < testIframes.length; i++) { var srcNode = testIframes[i]; var content = srcNode.innerHTML || ''; var id = srcNode.id || ""; var style = srcNode.getAttribute('style') || ""; var className = srcNode.getAttribute('class') || srcNode.className || ""; if (typeof style == "object") { style = style.cssText || ""; } srcNode.innerHTML = ""; srcNode.removeAttribute('style'); srcNode.className = ""; makeIframe(id, className, style, content, "strict", false, srcNode); makeIframe(id, className, style, content, "quirks", false, srcNode); makeIframe(id, className, style, content, "loose", true, srcNode); makeIframe(id, className, style, content, "quirks", true, srcNode); } return loading; } }, function checkAttrs() { var body = baseWin.body(); winUtils.scrollIntoView(body); doh.f(domAttr.has(body, '_offsetParent')); doh.f(domAttr.has(body, '_parent')); } ]); ``` -------------------------------- ### Dojo iframe GET JSON Request Source: https://github.com/tritondigital/player-sdk/blob/master/src/lib/dojo/tests/request/iframe.html Tests sending a GET request with JSON data using dojo/request/iframe. It verifies that the server returns JSON data as expected, including query parameters. The `handleAs` option is set to 'json'. ```javascript function ioIframeGetJson(t){ var d = new doh.Deferred(); var td = iframe.get("iframeDummyMethod.php?type=json", { preventCache: true, data: { color: "blue" }, handleAs: "json" }); td.then(d.getTestCallback(function(data){ t.is("json", data.query.type); t.is("blue", data.query.color); })); return d; } ``` -------------------------------- ### Initialize Triton Player SDK with Dojo Source: https://github.com/tritondigital/player-sdk/blob/master/src/lib/dojo/tests/_base/loader/traceApi.html Initializes the Triton Digital Player SDK using Dojo's `dojo.ready` and `require` functions. It sets up module loading tracing and loads 'doh' and 'dijit' modules. This ensures the SDK is ready to be used after the DOM is loaded and necessary modules are defined. ```javascript dojo.ready(function(){ console.log("in ready"); require.trace.set("loader-run-factory", 0); require.trace.set("loader-define", 1); require(["doh"], function(){ console.log("done loading DOH; turn tracing all off"); require.trace.set({"loader-define":0}); require(["dijit"], function(){ console.log("done loading dijit"); }); }); }); ``` -------------------------------- ### Load HTML via GET using dojo.io.iframe Source: https://github.com/tritondigital/player-sdk/blob/master/src/lib/dojo/tests/io/iframe.html Tests loading HTML content via a GET request. It checks if the loaded HTML contains an H1 tag with specific innerHTML. Dependencies include dojo, doh, and dojo/topic. ```javascript function ioIframeGetHtml(t){ var d = new doh.Deferred(); var td = dojo.io.iframe.send({ url: "iframeResponse.html", method: "GET", timeoutSeconds: 5, preventCache: true, handleAs: "html", handle: function(res, ioArgs){ if(!(res instanceof Error) && t.is("SUCCESSFUL HTML response", res.getElementsByTagName("h1")[0].innerHTML)){ d.callback(true); }else{ d.errback(false); } } }); return d; } ``` -------------------------------- ### Load JavaScript via GET using dojo.io.iframe Source: https://github.com/tritondigital/player-sdk/blob/master/src/lib/dojo/tests/io/iframe.html Tests loading and executing JavaScript from a remote URL using a GET request. It verifies that a global function is called with the expected value. Dependencies include dojo, doh, and dojo/topic. ```javascript function ioIframeGetJavascript(t){ var d = new doh.Deferred(); var form = dojo.byId("contentArrayTest"); form.getAttributeNode("method").value = "get"; var td = dojo.io.iframe.send({ url: "iframeResponse.js.html", method: "GET", timeoutSeconds: 5, preventCache: true, handleAs: "javascript", handle: function(res, ioArgs){ console.log("RES: ", res); if(!(res instanceof Error) && t.is(42, window.iframeTestingFunction())){ d.callback(true); }else{ d.errback(false); } } }); return d; } ``` -------------------------------- ### Dojo Ready and Test Execution Source: https://github.com/tritondigital/player-sdk/blob/master/src/lib/dojo/tests/_base/loader/config.html This snippet initializes Dojo, sets up aliases for `dojo` and `has`, registers the test function with `doh`, and runs the tests. It ensures the tests are executed after the DOM is ready. ```javascript require(["dojo", "doh", "dojo/has"], function(dojo, doh, has) { dojo.ready(function() { dojoAlias= dojo; hasAlias= has; doh.register("dojoConfig-test", [expect]); doh.runOnLoad(); }); }); ``` -------------------------------- ### Require Modules and Run Tests with Doh Source: https://github.com/tritondigital/player-sdk/blob/master/src/lib/dojo/tests/_base/loader/paths.html This code snippet demonstrates how to load multiple modules, including those configured with aliases and paths, using `require`. It then uses the 'doh' testing utility to register and run tests, verifying that the aliased modules and path-defined modules are loaded and resolved correctly. The `runOnLoad()` function ensures tests execute after all modules are loaded. ```javascript require(["myTopLevelModule", "doh", "myModule1", "myModule2", "yourModule", "yourOtherModule", "yourOtherModule/stuff/special"], function(myModule, doh, myModule1, myModule2, myModule1_1, myModule1_2, myModule2_1){ doh.register("aliases", [ function(t){ t.is(myModule1Value, myModule1); t.is(myModule1Value, myModule1_1); t.is(myModule1Value, myModule1_2); t.is(myModule2Value, myModule2); t.is(myModule2Value, myModule2_1); } ]); doh.register("top-level-module-via-paths", [ function(t){ t.is(myTopLevelModule.name, "myTopLevelModule"); t.is(myTopLevelModule.myModule.name, "myTopLevelModule.myModule"); } ]); doh.runOnLoad(); }); ```