我有一个.js模板(我没有这个),它位于顶部
(function(){ JQUERY_SCRIPT =" https://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.0.2.min.js&#34 ;; JQUERYUI_SCRIPT =" https://ajax.aspnetcdn.com/ajax/jquery.ui/1.11.4/jquery-ui.js&#34 ;; JQUERYUI_CSS =" // code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css" ;;
整个文件是一个函数,里面有很多函数,就像我看到的那样。我认为这三行引用了外部JQuery库,但我只看到使用标签引用的脚本所以我想知道的是为什么它是这样编写的?谢谢
答案 0 :(得分:0)
由于您还没有显示整个代码,因此它们看起来像全局变量,可用于在代码的稍后阶段呈现包含的脚本
答案 1 :(得分:0)
(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')
})();