(function (){ var TemplateManager = (function (){ var _convertStringToNode = function (string){ var temp = _AN_Call_createelement('createElement', document, "div"); _AN_Write_innerhtml("innerHTML", temp, false , string); var fragment = document.createDocumentFragment(); while (temp.firstChild){ _AN_Call_appendchild("appendChild", fragment, temp.firstChild); } return fragment; } ; var _createTemplateFn = function (replaceVars, template){ return function (data){ if (_AN_Read_length("length", replaceVars) && data !== null ) { var templateClone = template; for (var i = 0, len = _AN_Read_length("length", replaceVars); i < len; i++ ){ var key = _AN_Call_replace("replace", _AN_Call_replace("replace", replaceVars[i], "{{", ""), "}}", ""); if (data[key]) { var pattern = new RegExp(replaceVars[i], "g"); templateClone = _AN_Call_replace("replace", templateClone, pattern, data[key]); } } } return _convertStringToNode(templateClone); } ; } ; return { compile: function (template){ if (typeof template !== "string") { throw new TypeError("Invalid templateString type. Expected 'String', got " + typeof templateString) } var replaceVars = template.match(/{{[\w_-]*}}/g); return _createTemplateFn(replaceVars, template); } } ; } )(); var BugzillaTracker = (function (){ var _cache = { } , _config = { bugSearchURL: "https://www.w3.org/Bugs/Public/buglist.cgi", scriptId: "BugzillaTracker", onSearch: _onSearch} , _queryParams = { product: "CSS", component: "Regions", ctype: "js"} ; function _getScript(url){ var script = _AN_Call_createelement("createElement", document, "script"), oldScript = document.getElementById(_config.scriptId), target = _AN_Call_getelementsbytagname("getElementsByTagName", document, "script")[0]; if (oldScript) { oldScript.parentNode.removeChild(oldScript); } script.type = "text/javascript"; _AN_Write_src("src", script, false , url); script.id = _config.scriptId; return target.parentNode.insertBefore(script, target); } function _extend(object){ var sources = Array.prototype.slice.call(arguments, 1); if (sources && _AN_Read_length("length", sources)) { sources.forEach(function (source){ for (var property in source){ object[property] = source[property]; } } ); } return object; } function _serialize(object){ var pairs = [] ; for (var key in object){ pairs.push(key + "=" + encodeURIComponent(object[key])); } return pairs.join("&"); } function _createBugObject(array){ if (_AN_Read_length("length", array) !== 7) { throw new Error("Invalid bug data. Expected array of 7 values.") } return { "bug_severity": array[0], "priority": array[1], "op_sys": array[2], "assigned_to": array[3], "bug_status": array[4], "resolution": array[5], "short_desc": array[6]} ; } function _onSearch(bugList){ } function _getCallbackFn(){ return function (bugList){ if (!bugList || !_AN_Read_length("length", bugList)) { return ; } var bugObj, bugs = { } ; bugList.forEach(function (bug, index){ var bugObj = _createBugObject(bug, index); if (bugObj) { bugObj.bug_id = index; bugs[index] = bugObj; } } ); _config.onSearch.call(BugzillaTracker, bugs); if (typeof _cache.buglistCallback == "function") { window.buglistCallback = _cache.buglistCallback; } } ; } return { search: function (queryParams, callbackFn){ var params = _extend({ } , _queryParams, queryParams), queryString = _serialize(params), url = _config.bugSearchURL + "?" + queryString; if (typeof callbackFn == "function") { _config.onSearch = callbackFn; } if (typeof window.buglistCallback == "function") { _cache.buglistCallback = window.buglistCallback; } window.buglistCallback = _getCallbackFn(); _getScript(url); } , setOptions: function (options){ _config = _extend({ } , _config, options); } } ; } )(); window.BugzillaTracker = BugzillaTracker; window.TemplateManager = TemplateManager; } )();