All files / components/overviewPanel/js OverviewPanel.js

100% Statements 24/24
83.33% Branches 5/6
100% Functions 9/9
100% Lines 24/24
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205                        3x   3x       3x   3x 30x 30x 18x 18x       3x                                                                                                                                                                                                                                                                                                       3x 45x     3x 15x 15x       3x 15x 90x       3x 45x 45x 45x 45x 30x   15x          
/*
Copyright 2014-2015 OCAD University
 
Licensed under the Educational Community License (ECL), Version 2.0 or the New
BSD license. You may not use this file except in compliance with one these
Licenses.
 
You may obtain a copy of the ECL 2.0 License and BSD License at
https://github.com/fluid-project/infusion/raw/master/Infusion-LICENSE.txt
 
*/
 
var fluid_3_0_0 = fluid_3_0_0 || {};
 
(function ($, fluid) {
 
    "use strict";
 
    fluid.registerNamespace("fluid.overviewPanel");
 
    fluid.overviewPanel.makeBooleanListener = function (that, selector, method, path, value) {
        var elem = that.locate(selector);
        elem[method](function (evt) {
            that.applier.change(path, value === "toggle" ? !that.model[path] : value);
            evt.preventDefault();
        });
    };
 
    fluid.defaults("fluid.overviewPanel", {
        gradeNames: ["fluid.rendererComponent"],
        resources: {
            template: {
                href: "../html/overviewPanelTemplate.html"
            }
        },
        listeners: {
            "onCreate.setVisibility": "{that}.setVisibility",
            "onCreate.showTemplate": "fluid.overviewPanel.showTemplate",
            "afterRender.registerToggleListener": {
                "funcName": "fluid.overviewPanel.makeBooleanListener",
                "args": ["{that}", "toggleControl", "click", "showPanel", "toggle"]
            },
            "afterRender.registerCloseListener": {
                "funcName": "fluid.overviewPanel.makeBooleanListener",
                "args": ["{that}", "closeControl", "click", "showPanel", false]
            },
            "afterRender.setLinkHrefs": {
                "funcName": "fluid.overviewPanel.setLinkHrefs",
                "args": ["{that}", "{that}.options.links"]
            },
            "afterRender.setToggleControlAria": {
                "this": "{that}.dom.toggleControl",
                "method": "attr",
                "args": {
                    "role": "button",
                    "aria-controls": "{that}.containerId"
                }
            },
            "afterRender.setCloseControlAria": {
                "this": "{that}.dom.closeControl",
                "method": "attr",
                "args": {
                    "role": "button",
                    "aria-label": "{that}.options.strings.closePanelLabel",
                    "aria-controls": "{that}.containerId"
                }
            },
            "afterRender.setAriaStates": "{that}.setAriaStates"
        },
        model: {
            showPanel: true
        },
        modelListeners: {
            "setVisibility": {
                path: "showPanel",
                func: "{that}.setVisibility"
            },
            "setAriaStates": {
                path: "showPanel",
                func: "{that}.setAriaStates"
            }
        },
        members: {
            containerId: {
                expander: {
                    // create an id for that.container, if it does not have one already,
                    // and set that.containerId to the id value
                    funcName: "fluid.allocateSimpleId",
                    args: "{that}.container"
                }
            }
        },
        invokers: {
            setVisibility: {
                funcName: "fluid.overviewPanel.setVisibility",
                args: ["{that}", "{that}.model.showPanel"]
            },
            setAriaStates: {
                funcName: "fluid.overviewPanel.setAriaStates",
                args: ["{that}", "{that}.model.showPanel"]
            }
        },
        selectors: {
            toggleControl: ".flc-overviewPanel-toggleControl",
            titleBegin: ".flc-overviewPanel-title-begin",
            titleLink: ".flc-overviewPanel-titleLink",
            titleLinkText: ".flc-overviewPanel-title-linkText",
            titleEnd: ".flc-overviewPanel-title-end",
            componentName: ".flc-overviewPanel-componentName",
            description: ".flc-overviewPanel-description",
            instructionsHeading: ".flc-overviewPanel-instructionsHeading",
            instructions: ".flc-overviewPanel-instructions",
            demoCodeLink: ".flc-overviewPanel-demoCodeLink",
            demoCodeLinkText: ".flc-overviewPanel-demoCodeLinkText",
            infusionCodeLink: ".flc-overviewPanel-infusionCodeLink",
            infusionCodeLinkText: ".flc-overviewPanel-infusionCodeLinkText",
            apiLink: ".flc-overviewPanel-apiLink",
            apiLinkText: ".flc-overviewPanel-apiLinkText",
            designLink: ".flc-overviewPanel-designLink",
            designLinkText: ".flc-overviewPanel-designLinkText",
            feedbackText: ".flc-overviewPanel-feedbackText",
            feedbackLink: ".flc-overviewPanel-feedbackLink",
            feedbackLinkText: ".flc-overviewPanel-feedbackLinkText",
            closeControl: ".flc-overviewPanel-closeControl",
            closeText: ".flc-overviewPanel-closeText"
        },
        selectorsToIgnore: ["toggleControl", "titleLink", "demoCodeLink", "infusionCodeLink", "apiLink", "designLink", "feedbackLink", "closeControl"],
        protoTree: {
            titleBegin: {messagekey: "titleBegin"},
            titleLinkText: {messagekey: "titleLinkText"},
            titleEnd: {messagekey: "titleEnd"},
            componentName: {messagekey: "componentName"},
            description: {markup: "${{that}.options.markup.description}"},
            instructionsHeading: {messagekey: "instructionsHeading"},
            instructions: {markup: "${{that}.options.markup.instructions}"},
            demoCodeLinkText: {messagekey: "demoCodeLinkText"},
            infusionCodeLinkText: {messagekey: "infusionCodeLinkText"},
            apiLinkText: {messagekey: "apiLinkText"},
            designLinkText: {messagekey: "designLinkText"},
            feedbackText: {messagekey: "feedbackText"},
            feedbackLinkText: {messagekey: "feedbackLinkText"},
            closeText: {messagekey: "closeText"}
        },
        styles: {
            hidden: "fl-overviewPanel-hidden"
        },
        strings: {
            titleBegin: "An",
            titleLinkText: "Infusion",
            titleEnd: "component demo",
            componentName: "Component Name",
            instructionsHeading: "Instructions",
            demoCodeLinkText: "demo code",
            infusionCodeLinkText: "get Infusion",
            apiLinkText: "API",
            designLinkText: "design",
            feedbackText: "Found a bug? Have a question?",
            feedbackLinkText: "Let us know!",
            closeText: "close",
            openPanelLabel: "Open the overview panel",
            closePanelLabel: "Close the overview panel"
        },
        markup: {
            description: "A description of the component should appear here. It should say: <ul><li>What the component does.</li><li>Why it is interesting / useful.</li></ul>",
            instructions: "<p>Do this to do this. Do that to do that.</p>"
        },
        links: {
            titleLink: "http://fluidproject.org/infusion.html",
            demoCodeLink: "#",
            infusionCodeLink: "https://github.com/fluid-project/infusion/",
            apiLink: "#",
            designLink: "#",
            feedbackLink: "#"
        }
    });
 
    fluid.overviewPanel.setVisibility = function (that, showPanel) {
        that.container.toggleClass(that.options.styles.hidden, !showPanel);
    };
 
    fluid.overviewPanel.showTemplate = function (that) {
        fluid.fetchResources(that.options.resources, function () {
            that.refreshView();
        });
    };
 
    fluid.overviewPanel.setLinkHrefs = function (that, linkMap) {
        fluid.each(linkMap, function (linkHref, selector) {
            that.locate(selector).attr("href", linkHref);
        });
    };
 
    fluid.overviewPanel.setAriaStates = function (that, showPanel) {
        that.locate("toggleControl").attr("aria-pressed", !showPanel);
        that.locate("toggleControl").attr("aria-expanded", showPanel);
        that.locate("closeControl").attr("aria-expanded", showPanel);
        if (showPanel) {
            that.locate("toggleControl").attr("aria-label", that.options.strings.closePanelLabel);
        } else {
            that.locate("toggleControl").attr("aria-label", that.options.strings.openPanelLabel);
        }
    };
 
})(jQuery, fluid_3_0_0);