### jQuery AJAX Setup Source: https://github.com/braverock/portfolioanalytics/blob/master/sandbox/todo_notes.html Configure global AJAX settings or individual request options using ajaxSetup. Use this to set default values for all AJAX requests. ```javascript m.ajaxSetup({}, b) ``` -------------------------------- ### Setting and Getting HTML Content Source: https://github.com/braverock/portfolioanalytics/blob/master/sandbox/todo_notes.html The `html()` method is used to get the HTML content of the first element in the set of matched elements or to set the HTML content for each element in the set. It handles the creation of DOM elements from HTML strings. ```javascript html:function(a){return V(this,function(a){var b=this[0]||{},c=0,d=this.length;if(void 0===a)return 1===b.nodeType?b.innerHTML.replace(fa,"`"):void 0;if(!("string"!=typeof a||ma.test(a)||!k.htmlSerialize&&ga.test(a)||!k.leadingWhitespace&&ha.test(a)||ra[(ja.exec(a)||["",""])[1].toLowerCase()]))){a=a.replace(ia,"<$1>");try{for(;d>c;c++)b=this[c]||{},1===b.nodeType&&(m.cleanData(ua(b,!1)),b.innerHTML=a);b=0}catch(e){}}b&&this.empty().append(a)},null,a,arguments.length)} ``` -------------------------------- ### AJAX Setup for Script Transport Source: https://github.com/braverock/portfolioanalytics/blob/master/sandbox/todo_notes.html Configures jQuery to handle script requests, disabling caching and enabling cross-domain GET requests. This is used for loading external JavaScript files asynchronously. ```javascript m.ajaxSetup({accepts:{script:"text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"},contents:{script:/(?:java|ecma)script/},converters:{"text script":function(a){return m.globalEval(a),a}}}),m.ajaxPrefilter("script",function(a){void 0===a.cache&&(a.cache=!1),a.crossDomain&&(a.type="GET",a.global=!1)}),m.ajaxTransport("script",function(a){if(a.crossDomain){var b,c=y.head||m("head")\[0\]||y.documentElement;return{send:function(d,e){b=y.createElement("script"),b.async=!0,a.scriptCharset&&(b.charset=a.scriptCharset),b.src=a.url,b.onload=b.onreadystatechange=function(a,c){(c||!b.readyState||/loaded|complete/.test(b.readyState))&&(b.onload=b.onreadystatechange=null,b.parentNode&&b.parentNode.removeChild(b),b=null,c||e(200,"success"))},c.insertBefore(b,c.firstChild)},abort:function(){b&&b.onload(void 0,!0)}}}}) ``` -------------------------------- ### jQuery get Method Source: https://github.com/braverock/portfolioanalytics/blob/master/sandbox/todo_notes.html A shorthand method for making GET requests. Can fetch HTML, JSON, script, or text data. ```javascript m.get=function(a,c,d,e){return m.ajax({url:a,type:"GET",dataType:e,data:c,success:d})} ``` -------------------------------- ### jQuery CSS Height and Width Source: https://github.com/braverock/portfolioanalytics/blob/master/sandbox/todo_notes.html Handles getting and setting the height and width CSS properties, accounting for box-sizing and other factors. ```javascript m.each(["height","width"],function(a,b){m.cssHooks[b]={get:function(a,c,d){return c?Oa.test(m.css(a,"display"))&&0===a.offsetWidth?m.swap(a,Ra,function(){return Ya(a,b,d)}):Ya(a,b,d):void 0},set:function(a,c,d){var e=d&&Ia(a);return Wa(a,c,d?Xa(a,b,d,k.boxSizing&&"border-box"===m.css(a,"boxSizing",!1,e),e):0)}}}) ``` -------------------------------- ### Bootstrap Tooltip Initialization Logic Source: https://github.com/braverock/portfolioanalytics/blob/master/sandbox/todo_notes.html Handles the initialization of tooltips, including setting up event listeners for various triggers and managing options. ```javascript init: function (b, c, d) { this.enabled = !0, this.type = b, this.$element = a(c), this.options = this.getOptions(d), this.$viewport = this.options.viewport && a(a.isFunction(this.options.viewport) ? this.options.viewport.call(this, this.$element) : this.options.viewport.selector || this.options.viewport), this.inState = { click: !1, hover: !1, focus: !1 }; for (var e = this.options.trigger.split(" "), f = e.length; f--;) { var g = e[f]; if ("click" == g) this.$element.on("click." + this.type, this.options.selector, a.proxy(this.toggle, this)); else if ("manual" != g) { var h = "hover" == g ? "mouseenter" : "focusin", i = "hover" == g ? "mouseleave" : "focusout"; this.$element.on(h + "." + this.type, this.options.selector, a.proxy(this.enter, this)), this.$element.on(i + "." + this.type, this.options.selector, a.proxy(this.leave, this)) } } this.options.selector ? this._options = a.extend({}, this.options, { trigger: "manual", selector: "" }) : this.fixTitle() } ``` -------------------------------- ### Initialize Portfolio Data Structures Source: https://github.com/braverock/portfolioanalytics/blob/master/sandbox/todo_notes.html Standard boilerplate for initializing portfolio data structures. These snippets are used across multiple modules to ensure consistent data handling. ```javascript YzITI2NTcVFAYjISImNRE0NgUBFhQHAQYmJzUmDgMHPgY3NT4BAV4BaaQ0wyk7OykB9Ck7yLml/nClubkCfwFTCAj+rAcLARo5ZFRYGgouOUlARioTAQsETJI2Oyn+DCk7OymZZ6W5uaUBkKW5G/7TBxUH/s4GBAnLAQINFjAhO2JBNB0UBwHSCgUAAAAAAgAAAAAEnQRMAB0ANQAAASEyFwchIgYVERQWMyEyNj0BNxUUBiMhIiY1ETQ2CQE2Mh8BFhQHAQYiLwEmND8BNjIfARYyAV4BXjxDsv6jKTs7KQH0KTvIuaX+cKW5uQHKAYsHFQdlBwf97QcVB/gHB2UHFQdvCBQETBexOyn+DCk7OylFyNulubmlAZCluf4zAYsHB2UHFQf97AcH+AcVB2UHB28HAAAAAQAKAAoEpgSmADsAAAkBNjIXARYGKwEVMzU0NhcBFhQHAQYmPQEjFTMyFgcBBiInASY2OwE1IxUUBicBJjQ3ATYWHQEzNSMiJgE+AQgIFAgBBAcFCqrICggBCAgI/vgICsiqCgUH/vwIFAj++AgFCq/ICgj++AgIAQgICsivCgUDlgEICAj++AgKyK0KBAf+/AcVB/73BwQKrcgKCP74CAgBCAgKyK0KBAcBCQcVBwEEBwQKrcgKAAEAyAAAA4QETAAZAAATMzIWFREBNhYVERQGJwERFAYrASImNRE0NvpkFR0B0A8VFQ/+MB0VZBUdHQRMHRX+SgHFDggV/BgVCA4Bxf5KFR0dFQPoFR0AAAABAAAAAASwBEwAIwAAEzMyFhURATYWFREBNhYVERQGJwERFAYnAREUBisBIiY1ETQ2MmQVHQHQDxUB0A8VFQ/+MBUP/jAdFWQVHR0ETB0V/koBxQ4IFf5KAcUOCBX8GBUIDgHF/koVCA4Bxf5KFR0dFQPoFR0AAAABAJ0AGQSwBDMAFQAAAREUBicBERQGJwEmNDcBNhYVEQE2FgSwFQ/+MBUP/hQPDwHsDx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QFwImFR0dFf3aFxD99hACRgGrDQoV/t0dFcgVHf7dFQoNAasNJgAAAAABAAAAUwSZA/kAFQAACQEWFAcBBiY1ESEiJj0BNDYzIRE0NgJ/AgoQEP32EBf92hUdHRUCJhcD8f5VDSYN/lUNChUBIx0VyBUdASMVCgAAAAEAtwAABF0EmQAVAAAJARYGIyERFAYrASImNREhIiY3ATYyAqoBqw0KFf7dHRXIFR3+3RUKDQGrDSYEif32EBf92hUdHRUCJhcQAgoQAAAAAQC3ABcEXQSwABUAAAEzMhYVESEyFgcBBiInASY2MyERNDYCJsgVHQEjFQoN/lUNJg3+VQ0KFQEjHQSwHRX92hcQ/fYQEAIKEBcCJhUdAAABAAAAtwSZBF0AFwAACQEWFAcBBiY1EQ4DBz4ENxE0NgJ/AgoQEP32EBdesKWBJAUsW4fHfhcEVf5VDSYN/lUNChUBIwIkRHVNabGdcUYHAQYVCgACAAAAAASwBLAAFQArAAABITIWFREUBi8BBwYiLwEmND8BJyY2ASEiJjURNDYfATc2Mh8BFhQPARcWBgNSASwVHRUOXvkIFAhqBwf5Xg4I/iH+1BUdFQ5e+QgUCGoHB/leDggEsB0V/tQVCA5e+QcHaggUCPleDhX7UB0VASwVCA5e+QcHaggUCPleDhUAAAACAEkASQRnBGcAFQArAAABFxYUDwEXFgYjISImNRE0Nh8BNzYyASEyFhURFAYvAQcGIi8BJjQ/AScmNgP2agcH+V4OCBX+1BUdFQ5e+QgU/QwBLBUdFQ5e+QgUCGoHB/ ``` -------------------------------- ### GET /portfolio/analytics Source: https://github.com/braverock/portfolioanalytics/blob/master/sandbox/todo_notes.html Retrieves the analytics data for a specific portfolio. ```APIDOC ## GET /portfolio/analytics ### Description Retrieves the calculated analytics for a given portfolio ID. ### Method GET ### Endpoint /portfolio/analytics ### Parameters #### Query Parameters - **portfolio_id** (string) - Required - The unique identifier of the portfolio. ### Request Example GET /portfolio/analytics?portfolio_id=12345 ### Response #### Success Response (200) - **data** (object) - The analytics result object. #### Response Example { "portfolio_id": "12345", "metrics": { "return": 0.05, "volatility": 0.12 } } ``` -------------------------------- ### Tooltip Component Prototype Methods Source: https://github.com/braverock/portfolioanalytics/blob/master/sandbox/todo_notes.html A collection of prototype methods for managing tooltip lifecycle, positioning, and content rendering. ```javascript mentElement,this.$element[0]);if(b.isDefaultPrevented()||!d)return;var e=this,f=this.tip(),g=this.getUID(this.type);this.setContent(),f.attr("id",g),this.$element.attr("aria-describedby",g),this.options.animation&&f.addClass("fade");var h="function"==typeof this.options.placement?this.options.placement.call(this,f[0],this.$element[0]):this.options.placement,i=/\s?auto?\s?/i,j=i.test(h);j&&(h=h.replace(i,"")||"top"),f.detach().css({top:0,left:0,display:"block"}).addClass(h).data("bs."+this.type,this),this.options.container?f.appendTo(this.options.container):f.insertAfter(this.$element),this.$element.trigger("inserted.bs."+this.type);var k=this.getPosition(),l=f[0].offsetWidth,m=f[0].offsetHeight;if(j){var n=h,o=this.getPosition(this.$viewport);h="bottom"==h&&k.bottom+m>o.bottom?"top":"top"==h&&k.top-mo.width?"left":"left"==h&&k.left-lg.top+g.height&&(e.top=g.top+g.height-i)}else{var j=b.left-f,k=b.left+f+c;jg.right&&(e.left=g.left+g.width-k)}return e},c.prototype.getTitle=function(){var a,b=this.$element,c=this.options;return a=b.attr("data-original-title")||("function"==typeof c.title?c.title.call(b[0]):c.title)},c.prototype.getUID=function(a){do a+=~~(1e6*Math.random());while(document.getElementById(a));return a},c.prototype.tip=function(){if(!this.$tip&&(this.$tip=a(this.options.template),1!=this.$tip.length))throw new Error(this.type+" `template` option must consist of exactly 1 top-level element!");return this.$tip},c.prototype.arrow=function(){return this.$arrow=this.$arrow||this.tip().find(".tooltip-arrow")},c.prototype.enable=function(){this.enabled=!0},c.prototype.disable=function(){this.enabled=!1},c.prototype.toggleEnabled=function(){this.enabled=!this.enabled},c.prototype.toggle=function(b){var c=this;b&&(c=a(b.currentTarget).data("bs."+this.type),c||(c=new this.constructor(b.currentTarget,this.getDelegateOptions()),a(b.currentTarget).data("bs."+this.type,c))),b?(c.inState.click=!c.inState.click,c.isInStateTrue()?c.enter(c): ``` -------------------------------- ### Get Popover Arrow Source: https://github.com/braverock/portfolioanalytics/blob/master/sandbox/todo_notes.html Selects and returns the popover's arrow element. Initializes it if not already cached. ```javascript c.prototype.arrow=function(){return this.$arrow=this.$arrow||this.tip().find(".arrow")} ``` -------------------------------- ### Selector Engine Initialization and Testing Source: https://github.com/braverock/portfolioanalytics/blob/master/sandbox/todo_notes.html Initializes and tests various selector capabilities, populating internal arrays 'q' and 'r' with selector patterns based on browser support. ```javascript r=[],q=[],(c.qsa=$.test(g.querySelectorAll))&&(ja(function(a){o.appendChild(a).innerHTML="",a.querySelectorAll("["+msallowcapture+"^='']").length&&q.push("["+L+"*":"^$]=" + L + "*" + "(?:''|""))"),a.querySelectorAll("[selected]").length||q.push("\\[" + L + "*" + "(?:value|" + K + ")"),a.querySelectorAll("[id~="+u+"-"]").length||q.push("~="),a.querySelectorAll(":checked").length||q.push(":checked"),a.querySelectorAll("a#"+u+"+").length||q.push(".#.+[+~]")}),ja(function(a){var b=g.createElement("input");b.setAttribute("type","hidden"),a.appendChild(b).setAttribute("name","D"),a.querySelectorAll("[name=d]").length&&q.push("name"+L+"*["+L+"*^$|!~]="),a.querySelectorAll(":enabled").length||q.push(":enabled",":disabled"),a.querySelectorAll(",:x"),q.push(",.")})),(c.matchesSelector=$.test(s=o.matches||o.webkitMatchesSelector||o.mozMatchesSelector||o.oMatchesSelector||o.msMatchesSelector))&&ja(function(a){c.disconnectedMatch=s.call(a,"div"),s.call(a,"["+s+"!='' ]:x"),r.push("!=",P)}),q=q.length&&new RegExp(q.join("|")),r=r.length&&new RegExp(r.join("|")) ``` -------------------------------- ### Bootstrap Affix Plugin Implementation Source: https://github.com/braverock/portfolioanalytics/blob/master/sandbox/todo_notes.html Logic for pinning elements to the viewport during scroll events. ```javascript +function(a){ "use strict";function b(b){return this.each(function(){var d=a(this),e=d.data("bs.affix"),f="object"==typeof b&&b;e||d.data("bs.affix",e=new c(this,f)),"string"==typeof b&&e[b]()})}var c=function(b,d){this.options=a.extend({},c.DEFAULTS,d),this.$target=a(this.options.target).on("scroll.bs.affix.data-api",a.proxy(this.checkPosition,this)).on("click.bs.affix.data-api",a.proxy(this.checkPositionWithEventLoop,this)),this.$element=a(b),this.affixed=null,this.unpin=null,this.pinnedOffset=null,this.checkPosition()};c.VERSION="3.3.5",c.RESET="affix affix-top affix-bottom",c.DEFAULTS={offset:0,target:window},c.prototype.getState=function(a,b,c,d){var e=this.$target.scrollTop(),f=this.$element.offset(),g=this.$target.height();if(null!=c&&"top"==this.affixed)return c>e?"top":!1;if("bottom"==this.affixed)return null!=c?e+this.unpin<=f.top?!1:"bottom":a-d>=e+g?!1:"bottom";var h=null==this.affixed,i=h?e:f.top,j=h?g:b;return null!=c&&c>=e?"top":null!=d&&i+j>=a-d?"bottom":!1},c.prototype.getPinnedOffset=function(){if(this.pinnedOffset)return this.pinnedOffset;this.$element.removeClass(c.RESET).addClass("affix");var a=this.$target.scrollTop(),b=this.$element.offset();return this.pinnedOffset=b.top-a},c.prototype.checkPositionWithEventLoop=function(){setTimeout(a.proxy(this.checkPosition,this),1)},c.prototype.checkPosition=function(){if(this.$element.is(":visible")){var b=this.$element.height(),d=this.options.offset,e=d.top,f=d.bottom,g=Math.max(a(document).height(),a(document.body).height());"object"!=typeof d&&(f=e=d),"function"==typeof e&&(e=d.top(this.$element)),"function"==typeof f&&(f=d.bottom(this.$element));var h=this.getState(g,b,e,f);if(this.affixed!=h){null!=this.unpin&&this.$element.css("top","");var i="affix"+(h?"-"+h:""),j=a.Event(i+".bs.affix");if(this.$element.trigger(j),j.isDefaultPrevented())return;this.affixed=h,this.unpin="bottom"==h?this.getPinnedOffset():null,this.$element.removeClass(c.RESET).addClass(i).trigger(i.replace("affix","affixed")+".bs.affix")}"bottom"==h&&this.$element.offset({top:g-b-f})}};var d=a.fn.affix;a.fn.affix=b,a.fn.affix.Constructor=c,a.fn.affix.noConflict=function(){return a.fn.affix=d,this},a(window).on("load",function(){a('[data-spy="affix"]').each(function(){var c=a(this),d=c.data();d.offset=d.offset||{},null!=d.offsetBottom&&(d.offset.bottom=d.offsetBottom),null!=d.offsetTop&&(d.offset.top=d.offsetTop),b.call(c,d)})})}(jQuery); ``` -------------------------------- ### Get Popover Content Source: https://github.com/braverock/portfolioanalytics/blob/master/sandbox/todo_notes.html Retrieves the content for the popover, prioritizing data attributes, then options. Handles function-based content. ```javascript c.prototype.getContent=function(){var a=this.$element,b=this.options;return a.attr("data-content")||("function"==typeof b.content?b.content.call(a[0]):b.content)} ``` -------------------------------- ### Get Window or Document Element Source: https://github.com/braverock/portfolioanalytics/blob/master/sandbox/todo_notes.html A utility function to retrieve the window object for a given element or document, or the document element itself. ```javascript function dc(a){return m.isWindow(a)?a:9===a.nodeType?a.defaultView||a.parentWindow:!1} ``` -------------------------------- ### Respond.js Media Query Polyfill Source: https://github.com/braverock/portfolioanalytics/blob/master/sandbox/todo_notes.html Respond.js provides media query support for older browsers, specifically IE8. It requires the `matchMedia` polyfill and uses AJAX to fetch styles. This code should only run in IE8. ```javascript if (!!window.navigator.userAgent.match("MSIE 8")) { !function(a) { "use strict"; a.matchMedia = a.matchMedia || function(a) { var b, c = a.documentElement, d = c.firstElementChild || c.firstChild, e = a.createElement("body"), f = a.createElement("div"); return f.id = "mq-test-1", f.style.cssText = "position:absolute;top:-100em", e.style.background = "none", e.appendChild(f), function(a) { return f.innerHTML = '­', c.insertBefore(e, d), b = 42 === f.offsetWidth, c.removeChild(e), { matches: b, media: a } } }(a.document) }(this) } ``` ```javascript !function(a) { "use strict"; function b() { u(!0) } var c = {}; a.respond = c, c.update = function() {}; var d = [], e = function() { var b; try { b = new a.XMLHttpRequest } catch (c) { b = new a.ActiveXObject("Microsoft.XMLHTTP") } return function() { return b } }(); c.ajax = function(a, b) { var c = e(); c && (c.open("GET", a, !0), c.onreadystatechange = function() { 4 !== c.readyState || 200 !== c.status && 304 !== c.status || b(c.responseText) }, 4 !== c.readyState && c.send(null)) }, c.queue = d, c.regex = { media: /@media[^\[]*\begin\[^\{\]*\{(\S|[^\{\]*\{(\S|[^\}\]*\})*[^\}\]*\}/gi, keyframes: /@(?:\-\(?:o|moz|webkit)\-)?keyframes[^\[]*\begin\[^\{\]*\{(\S|[^\{\]*\{(\S|[^\}\]*\})*[^\}\]*\}[^\}\]*\}/gi, urls: /(url\()["']?([^"'\(\)]*)["']?(\))/g, findStyles: /@media *([^\{\}\(\)]*) \{((?:[^\{\]*\{(\S|[^\{\]*\{(\S|[^\}\]*\})*[^\}\]*\})*[^\}\]*\}) }, c.mediaQueriesSupported = a.matchMedia && null !== a.matchMedia("only all") && a.matchMedia("only all").matches; !c.mediaQueriesSupported && (function(a, b) { var c, d, e, f = a.document, g = f.documentElement, h = f.getElementsByTagName("head")[0] || g, i = f.getElementsByTagName("base")[0], j = h.getElementsByTagName("link"), k = (new Date).getTime(); if (b && c && p > k - c) return a.clearTimeout(d), d = a.setTimeout(u, p), void 0; c = k; for (var l in m) m.hasOwnProperty(l) && (m[l].hasquery && (z && A || !(z || e >= x) || !(A || y >= e))) || (o[m[l].media] || (o[m[l].media] = []), o[m[l].media].push(n[m[l].rules])), for (var q in r) r.hasOwnProperty(q) && r[q] && r[q].parentNode === h && h.removeChild(r[q]); r.length = 0; for (var s in o) o.hasOwnProperty(s) && (var t = f.createElement("style"), u = o[s].join("\n"), t.type = "text/css", t.media = s, h.insertBefore(t, i ? i.nextSibling : j[j.length - 1].nextSibling), t.styleSheet ? t.styleSheet.cssText = u : t.appendChild(f.createTextNode(u)), r.push(t)) }(a.document), u()) }(this); ``` -------------------------------- ### Bootstrap Dropdown Plugin Implementation Source: https://github.com/braverock/portfolioanalytics/blob/master/sandbox/todo_notes.html Internal logic for the dropdown component, handling toggling, keyboard navigation, and backdrop management. ```javascript +function(a){ "use strict"; function b(b){var c=b.attr("data-target");c||(c=b.attr("href"),c=c&&/#[A-Za-z]/.test(c)&&c.replace(/.*(?=#[^\s]*$)/,""));var d=c&&a(c);return d&&d.length?d:b.parent()}function c(c){c&&3===c.which||(a(e).remove(),a(f).each(function(){var d=a(this),e=b(d),f={relatedTarget:this};e.hasClass("open")&&(c&&"click"==c.type&&/input|textarea/i.test(c.target.tagName)&&a.contains(e[0],c.target)||(e.trigger(c=a.Event("hide.bs.dropdown",f)),c.isDefaultPrevented()||(d.attr("aria-expanded","false"),e.removeClass("open").trigger("hidden.bs.dropdown",f))))}))}function d(b){return this.each(function(){var c=a(this),d=c.data("bs.dropdown");d||c.data("bs.dropdown",d=new g(this)),"string"==typeof b&&d[b].call(c)})}var e=".dropdown-backdrop",f='[data-toggle="dropdown"]',g=function(b){a(b).on("click.bs.dropdown",this.toggle)};g.VERSION="3.3.5",g.prototype.toggle=function(d){var e=a(this);if(!e.is(".disabled, :disabled")){var f=b(e),g=f.hasClass("open");if(c(),!g){ "ontouchstart"in document.documentElement&&!f.closest(".navbar-nav").length&&a(document.createElement("div")).addClass("dropdown-backdrop").insertAfter(a(this)).on("click",c);var h={relatedTarget:this};if(f.trigger(d=a.Event("show.bs.dropdown",h)),d.isDefaultPrevented())return;e.trigger("focus").attr("aria-expanded","true"),f.toggleClass("open").trigger("shown.bs.dropdown",h)}return!1}},g.prototype.keydown=function(c){if(/(38|40|27|32)/.test(c.which)&&!/input|textarea/i.test(c.target.tagName)){var d=a(this);if(c.preventDefault(),c.stopPropagation(),!d.is(".disabled, :disabled")){var e=b(d),g=e.hasClass("open");if(!g&&27!=c.which||g&&27==c.which)return 27==c.which&&e.find(f).trigger("focus"),d.trigger("click");var h=" li:not(.disabled):visible a",i=e.find(".dropdown-menu"+h);if(i.length){var j=i.index(c.target);38==c.which&&j>0&&j--,40==c.which&&j .dropdown-menu > .active").removeClass("active").end().find('[data-toggle="tab"]').attr("aria-expanded",!1),b.addClass("active").find('[data-toggle="tab"]').attr("aria-expanded",!0),h?(b[0].offsetWidth,b.addClass("in")):b.removeClass("fade"),b.parent(".dropdown-menu").length&&b.closest("li.dropdown").addClass("active").end().find('[data-toggle="tab"]').attr("aria-expanded",!0),e&&e()}var g=d.find("> .active"),h=e&&a.support.transition&&(g.length&&g.hasClass("fade")||!!d.find("> .fade").length);g.length&&h?g.one("bsTransitionEnd",f).emulateTransitionEnd(c.TRANSITION_DURATION):f(),g.removeClass("in")};var d=a.fn.tab;a.fn.tab=b,a.fn.tab.Constructor=c,a.fn.tab.noConflict=function(){return a.fn.tab=d,this};var e=function(c){c.preventDefault(),b.call(a(this),"show")};a(document).on("click.bs.tab.data-api",'[data-toggle="tab"]',e).on("click.bs.tab.data-api",'[data-toggle="pill"]',e)}(jQuery), ``` -------------------------------- ### jQuery getJSON Method Source: https://github.com/braverock/portfolioanalytics/blob/master/sandbox/todo_notes.html A shorthand method for making GET requests that return JSON. Simplifies fetching JSON data from a server. ```javascript getJSON: function(a,b,c){return m.get(a,b,c,"json")} ``` -------------------------------- ### Initialize Bootstrap Tooltip Source: https://github.com/braverock/portfolioanalytics/blob/master/sandbox/todo_notes.html Initialize a Bootstrap tooltip with various options for placement, animation, and trigger events. Use this for providing additional information on hover or focus. ```javascript var tooltip = a(selector).tooltip(options) // or a(selector).tooltip('show') ``` -------------------------------- ### Get Element Position Source: https://github.com/braverock/portfolioanalytics/blob/master/sandbox/todo_notes.html Calculates the position of the first element in the set of matched elements relative to its offset parent. Requires the element to be in the DOM. ```javascript m.fn.position=function(){if(this[0]){var a,b,c={top:0,left:0},d=this[0];return"fixed"===m.css(d,"position")?b=d.getBoundingClientRect():(a=this.offsetParent(),b=this.offset(),m.nodeName(a[0],"html")||(c=a.offset()),c.top+=m.css(a[0],"borderTopWidth",!0),c.left+=m.css(a[0],"borderLeftWidth",!0)),{top:b.top-c.top-m.css(d,"marginTop",!0),left:b.left-c.left-m.css(d,"marginLeft",!0)}}} ``` -------------------------------- ### HTML5 Shiv Initialization Source: https://github.com/braverock/portfolioanalytics/blob/master/sandbox/todo_notes.html Initializes HTML5 Shiv to support HTML5 elements in older browsers. Ensure this script is included before other scripts that might rely on these elements. ```javascript var t = { elements: n.elements || "abbr article aside audio bdi canvas data datalist details dialog figcaption figure footer header hgroup main mark meter nav output picture progress section summary template time video", version: m, shivCSS: n.shivCSS !== !1, supportsUnknownElements: l, shivMethods: n.shivMethods !== !1, type: "default", shivDocument: j, createElement: g, createDocumentFragment: h, addElements: e }; a.html5 = t, j(b)}(this, document); ```