<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>src\js\reference.js</title>
    <link rel="stylesheet" href="http://yui.yahooapis.com/3.9.1/build/cssgrids/cssgrids-min.css">
    <link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
    <link rel="stylesheet" href="../assets/css/main.css" id="site_styles">
    <link rel="icon" href="../assets/favicon.ico">
    <script src="http://yui.yahooapis.com/combo?3.9.1/build/yui/yui-min.js"></script>
</head>
<body class="yui3-skin-sam">

<div id="doc">
    <div id="hd" class="yui3-g header">
        <div class="yui3-u-3-4">
                <h1><img src="../assets/css/logo.png" title="" width="117" height="52"></h1>
        </div>
        <div class="yui3-u-1-4 version">
            <em>API Docs for: </em>
        </div>
    </div>
    <div id="bd" class="yui3-g">

        <div class="yui3-u-1-4">
            <div id="docs-sidebar" class="sidebar apidocs">
                <div id="api-list">
                    <h2 class="off-left">APIs</h2>
                    <div id="api-tabview" class="tabview">
                        <ul class="tabs">
                            <li><a href="#api-classes">Classes</a></li>
                            <li><a href="#api-modules">Modules</a></li>
                        </ul>
                
                        <div id="api-tabview-filter">
                            <input type="search" id="api-filter" placeholder="Type to filter APIs">
                        </div>
                
                        <div id="api-tabview-panel">
                            <ul id="api-classes" class="apis classes">
                                <li><a href="../classes/ColorSwitcher.html">ColorSwitcher</a></li>
                                <li><a href="../classes/Comment.html">Comment</a></li>
                                <li><a href="../classes/comment.js_anonymous.html">comment.js_anonymous</a></li>
                                <li><a href="../classes/Data.html">Data</a></li>
                                <li><a href="../classes/Global.html">Global</a></li>
                                <li><a href="../classes/helpInfo.js_anonymous.html">helpInfo.js_anonymous</a></li>
                                <li><a href="../classes/IO.html">IO</a></li>
                                <li><a href="../classes/io.js_anonymous.html">io.js_anonymous</a></li>
                                <li><a href="../classes/JQuery.html">JQuery</a></li>
                                <li><a href="../classes/ManualMarkup.html">ManualMarkup</a></li>
                                <li><a href="../classes/manualMarkup.js_anonymous.html">manualMarkup.js_anonymous</a></li>
                                <li><a href="../classes/markupPopup.js_anonymous.html">markupPopup.js_anonymous</a></li>
                                <li><a href="../classes/navbar.js_anonymous.html">navbar.js_anonymous</a></li>
                                <li><a href="../classes/Popup.html">Popup</a></li>
                                <li><a href="../classes/Regex.html">Regex</a></li>
                                <li><a href="../classes/Summary.html">Summary</a></li>
                                <li><a href="../classes/summary.js_anonymous.html">summary.js_anonymous</a></li>
                                <li><a href="../classes/switcher.js_anonymous.html">switcher.js_anonymous</a></li>
                                <li><a href="../classes/tagRegex.js_anonymous.html">tagRegex.js_anonymous</a></li>
                                <li><a href="../classes/UI.html">UI</a></li>
                                <li><a href="../classes/ui.js_anonymous.html">ui.js_anonymous</a></li>
                                <li><a href="../classes/Util.html">Util</a></li>
                                <li><a href="../classes/utilities.js_anonymous.html">utilities.js_anonymous</a></li>
                                <li><a href="../classes/WebDictionary.html">WebDictionary</a></li>
                                <li><a href="../classes/webDictionary.js_anonymous.html">webDictionary.js_anonymous</a></li>
                            </ul>
                
                
                            <ul id="api-modules" class="apis modules">
                                <li><a href="../modules/comment.js.html">comment.js</a></li>
                                <li><a href="../modules/data.js.html">data.js</a></li>
                                <li><a href="../modules/helpInfo.js.html">helpInfo.js</a></li>
                                <li><a href="../modules/io.js.html">io.js</a></li>
                                <li><a href="../modules/markupPopup.js.html">markupPopup.js</a></li>
                                <li><a href="../modules/markus.js.html">markus.js</a></li>
                                <li><a href="../modules/navbar.js.html">navbar.js</a></li>
                                <li><a href="../modules/reference.js.html">reference.js</a></li>
                                <li><a href="../modules/summary.js.html">summary.js</a></li>
                                <li><a href="../modules/switcher.js.html">switcher.js</a></li>
                                <li><a href="../modules/tagRegex.js.html">tagRegex.js</a></li>
                                <li><a href="../modules/TestModule.html">TestModule</a></li>
                                <li><a href="../modules/ui.js.html">ui.js</a></li>
                                <li><a href="../modules/utilities.js.html">utilities.js</a></li>
                                <li><a href="../modules/webDictionary.js.html">webDictionary.js</a></li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="yui3-u-3-4">
                <div id="api-options">
                    Show:
                    <label for="api-show-inherited">
                        <input type="checkbox" id="api-show-inherited" checked>
                        Inherited
                    </label>
            
                    <label for="api-show-protected">
                        <input type="checkbox" id="api-show-protected">
                        Protected
                    </label>
            
                    <label for="api-show-private">
                        <input type="checkbox" id="api-show-private">
                        Private
                    </label>
                    <label for="api-show-deprecated">
                        <input type="checkbox" id="api-show-deprecated">
                        Deprecated
                    </label>
            
                </div>
            
            <div class="apidocs">
                <div id="docs-main">
                    <div class="content">
<h1 class="file-heading">File: src\js\reference.js</h1>

<div class="file">
    <pre class="code prettyprint linenums">
/**
 * reference.js base file.
 * @module reference.js
 */

/**
 * Registers the resize handler for the WebDictionary and registers the webDictionary
 * afterwards using the &#x60;markus.webDict.registWebDictionary()&#x60; function.
 *
 * @for Global
 * @method registWebDictionary
 */
var registWebDictionary = function() {
  //Resize handler
    markus.webDict.resize = function(obj) {
        $(obj).height($(window).height() - $(&quot;#content&quot;).offset().top - $(&quot;#buttonsRow&quot;).outerHeight() - 100);
    };
    markus.webDict.registWebDictionary();
};

/**
 * This method searches the CBDB using the input value of the provided webdictionary. If
 * there are multiple matches, display just one and create switcher buttons for the other matches.
 * When you click such a button &#x60;Global.searchCBDBID&#x60; is called
 *
 * @for Global
 * @method searchCBDB
 * @param  {Element} dictionary the dictionary element. Used to grab its &#x60;&lt;input&gt;&#x60; element
 */
var searchCBDB = function(dictionary) {
    //get the DB query
    var query = $(dictionary.input).val();
    //Hide the cbdbIDRef
    $(&quot;#cbdbIDRef&quot;).hide();

    //Find one or more digits
    if (query.match(/\d+/g)) {
        //If there are multiple, they are split along the &#x27;|&#x27; mark
        var cbdbids = query.split(&quot;|&quot;);

        //The markus webDictionary opens the url from the cbdb
        markus.webDict.openURL(dictionary, &#x27;http://cbdb.fas.harvard.edu/cbdbapi/person.php?id=&#x27; + cbdbids[0]);

        //If there are multiple matches
        if (cbdbids.length &gt; 1) {
            var txt = &quot;&quot;;
            for (var i = 0; i &lt; cbdbids.length; i++) {
                var cbdbid = cbdbids[i];
                //Create a button, if you click it. It searches for that person by ID
                txt += &#x27;&lt;label class=&quot;btn btn-danger &#x27; + ((i === 0) ? &#x27;active&#x27; : &#x27;noColor&#x27;) + &#x27;&quot; onclick=&quot;searchCBDBID(\&#x27;&#x27; + cbdbid + &#x27;\&#x27;)&quot;&gt;&lt;input type=&quot;radio&quot; name=&quot;options&quot; id=&quot;&#x27; + cbdbid + &#x27;&quot; &gt;&#x27; + cbdbid + &#x27;&lt;/label&gt;&#x27;
            }

            //Show the generated HTML text
            $(&quot;#cbdbIDRef&quot;).html(txt).show();
        }
    } else {
      //If it wasn&#x27;t just digits, try &#x60;encodeURI&#x60; on it as a URL variable
        markus.webDict.openURL(dictionary, &#x27;http://cbdb.fas.harvard.edu/cbdbapi/person.php?name=&#x27; + encodeURI(query));
    }


};

/**
 * Looks for a match in the CBDB using the idRef contained in the provided webdictionary.
 *
 * @for Global
 * @method searchByID
 * @param  {Element} dictionary reference to the webdictionary, used to grab its &#x60;&lt;input&gt;&#x60;
 */
var searchByID = function(dictionary) {
    //get the query from the input holder
    var query = $(dictionary.input).val();
    //get a reference to the idRef
    var idRef = $(dictionary.holder).find(&quot;.IDRef&quot;);
    //and hide it
    idRef.hide();

    //regex in the dictionary
    var regex = new RegExp(dictionary.idRegex);

    if (query.match(regex)) {
      //Once again, if there are multiple id&#x27;s, split them on &#x27;|&#x27;
        var ids = query.split(&quot;|&quot;);
        //Open the first id
        markus.webDict.openURL(dictionary, dictionary.idSrc.replace(dictionary.param, ids[0]));

        //Generate buttons to switch to that id if there are multiple id&#x27;s
        if (ids.length &gt; 1) {
            var txt = &quot;&quot;;
            for (var i = 0; i &lt; ids.length; i++) {
                var id = ids[i];
                txt += &#x27;&lt;label class=&quot;btn btn-danger &#x27; + ((i === 0) ? &#x27;active&#x27; : &#x27;noColor&#x27;) + &#x27;&quot; onclick=&quot;searchFromID(\&#x27;&#x27; + dictionary.dictionary_name + &#x27;\&#x27;,\&#x27;&#x27; + id + &#x27;\&#x27;)&quot;&gt;&lt;input type=&quot;radio&quot; name=&quot;options&quot; id=&quot;&#x27; + id + &#x27;&quot; &gt;&#x27; + id + &#x27;&lt;/label&gt;&#x27;;
            }
            //Show the generated HTML containing the buttons
            idRef.html(txt).show();
        }
    } else {
      //Just open the url using the webdictionary
        markus.webDict.openURL(dictionary, dictionary.src.replace(dictionary.param, encodeURI($(dictionary.input).val())));
    }

};

/**
 * Opens the provided id in the dictionary referenced by the provided dictionary_name
 * as a string. Matches for that ID in the containing dictionary element are
 * given the &#x60;active&#x60; class
 *
 * @for Global
 * @method searchFromID
 * @param  {String} dictionary_name the name of the dictionary to find
 * @param  {String} id              the id to look for in the CBDB
 */
var searchFromID = function(dictionary_name, id) {
    //get the dictionary by name using JQUery and the name attribute
    var dictionary = $(&quot;.web-dictionary[web-dictionary-name=&#x27;&quot; + dictionary_name + &quot;&#x27;]&quot;);

    //Get each of the labels, containing a cbdbid
    $(dictionary).find(&quot;label&quot;).each(function() {
        //If we found a match to the id we&#x27;re looking for
        if ($(this).find(&quot;#&quot; + id).length &gt; 0) {
            $(this).removeClass(&quot;noColor&quot;).addClass(&quot;active&quot;);
        } else {
            $(this).removeClass(&quot;active&quot;).addClass(&quot;noColor&quot;);
        }

    });

    //Returns the dictionary by that name
    dictionary = markus.webDict.getDictionary(dictionary_name);

    //Opens the url in that dictionary
    markus.webDict.openURL(dictionary, dictionary.idSrc.replace(dictionary.param, id));
};

/**
 * Searches trough the &#x60;#cbdbIDRef&#x60;. Finds matches for the provided id. If found
 * matches are given the &#x60;active&#x60; class. Then opens the url in the standard cbdb dictionary.
 *
 * @for Global
 * @method searchCBDBID
 * @param  {String} id the id of the cbdbid we&#x27;re trying to match/find
 */
var searchCBDBID = function(id) {
    //Go through the cbdbdIdRef element and find each label for a match.
    $(&quot;#cbdbIDRef&quot;).find(&quot;label&quot;).each(function() {
      //If there is a match, make it active, else just display it without a color
        if ($(this).find(&quot;#&quot; + id).length &gt; 0) {
            $(this).removeClass(&quot;noColor&quot;).addClass(&quot;active&quot;);
        } else {
            $(this).removeClass(&quot;active&quot;).addClass(&quot;noColor&quot;);
        }
    });

    //Returns the dictionary that contains cbdb
    var dictionary = markus.webDict.getDictionary(&quot;cbdb&quot;);
    //Opens the url using that dictionary
    markus.webDict.openURL(dictionary, &#x27;http://cbdb.fas.harvard.edu/cbdbapi/person.php?id=&#x27; + id);

};

    </pre>
</div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="../assets/vendor/prettify/prettify-min.js"></script>
<script>prettyPrint();</script>
<script src="../assets/js/yui-prettify.js"></script>
<script src="../assets/../api.js"></script>
<script src="../assets/js/api-filter.js"></script>
<script src="../assets/js/api-list.js"></script>
<script src="../assets/js/api-search.js"></script>
<script src="../assets/js/apidocs.js"></script>
</body>
</html>
