问题描述:

I have a .js Template (I did not make this) that has at the top

(function () {

JQUERY_SCRIPT = "https://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.0.2.min.js";

JQUERYUI_SCRIPT = "https://ajax.aspnetcdn.com/ajax/jquery.ui/1.11.4/jquery-ui.js";

JQUERYUI_CSS = "//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css";

The entire file is a Function and a lot of functions inside it, the way I see it. I think these three lines are referencing the external JQuery libraries but I have only seen scripts referenced using tags so all I want to know is why is it written like this? Thank you

网友答案:

Since you haven't shown your entire code, they look like global variables which could be used to render the contained scripts at a later stage in the code

网友答案:

(function () {

JQUERY_SCRIPT = "https://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.0.2.min.js";
JQUERYUI_SCRIPT = "https://ajax.aspnetcdn.com/ajax/jquery.ui/1.11.4/jquery-ui.js";
JQUERYUI_CSS = "//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css";
JQUERYUI_CSS = "https://intranet-sharepoint-pbdev.labs.addev.ssa.gov/sites/DCSServices/Style%20Library/XSL%20Style%20Sheets/jquery-ui.css";
JQUERYUI_IMAGES = "https://intranet-sharepoint-pbdev.labs.addev.ssa.gov/sites/DCSServices/Style%20Library/Images/";


function OnAccordionViewPostRender(renderCtx) {
    $('#accordionFAQ').accordion({
        collapsible: true
    });

}

 //        $('#accordionFAQ').accordion("option", "icons",
//        { 'header': 'ui-icon-circle-plus', 'headerSelected': 'ui-icon-circle-minus'})

function OnAccordionViewPreRender(renderCtx) {
}

function RenderAccordionViewBodyTemplate(renderCtx) {

    var listData = renderCtx.ListData;
    if (renderCtx.Templates.Body == '') {
        return RenderViewTemplate(renderCtx);
    }
    var accordionHtml = '';

    accordionHtml = '<div id="accordionFAQ">';
    for (var idx in listData.Row) {
        var listItem = listData.Row[idx];
        accordionHtml += '<h3>';
        accordionHtml += listItem.Title;
        accordionHtml += '</h3>';
        accordionHtml += '<div>';
        accordionHtml += listItem.Answer;
        accordionHtml += '</div>';
    }

    accordionHtml += '</div>';

    return accordionHtml;
}

function registerAccordionViewTemplate() {

    var accordionViewContext = {};

    //accordionViewContext.BaseViewID = 'Accordion';
    accordionViewContext.Templates = {};
    accordionViewContext.Templates.View = RenderAccordionViewBodyTemplate;
    accordionViewContext.OnPreRender = OnAccordionViewPreRender;
    accordionViewContext.OnPostRender = OnAccordionViewPostRender;
    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(accordionViewContext);
}

loadjQueryScript = function () {
    loadScript(JQUERY_SCRIPT, loadjQueryUIScript)
}

loadjQueryUIScript = function () {
    loadScript(JQUERYUI_SCRIPT, registerAccordionViewTemplate)
}

function loadScript(scriptUrl, callback) {
    var head = document.getElementsByTagName('head')[0];
    var script = document.createElement('script');
    script.src = scriptUrl;
    var done = false;
    script.onload = script.onreadystatechange = function () {
        if (!done && (!this.readyState || this.readyState == "loaded" || this.readyState == "complete")) {
            done = true;
            callback();
        }
    };
    head.appendChild(script);
}

function loadCss(url) {
    var link = document.createElement('link');
    link.href = url;
    link.rel = 'stylesheet';
    document.getElementsByTagName('head')[0].appendChild(link);
}


//**** 
//**** main flow
//**** 
debugger;
loadjQueryUIScript
loadCss(JQUERYUI_CSS, JQUERYUI_IMAGES);
ExecuteOrDelayUntilScriptLoaded(loadjQueryScript, 'clienttemplates.js')

})();

相关阅读:
Top