2013-02-12 3 views
0

Ektron의 JS.RegisterJSInclude를 사용하여 자바 스크립트 파일을로드하고 싶지만 JavaScript의로드 순서를 설정하고 싶습니다.Ektron v8.6에서 JS.RegisterJSInclude()를 사용하여로드 순서를 설정할 수 있습니까?

Ektron.Cms.CommonApi _api = new Ektron.Cms.CommonApi(); 

    // I'd like this to be called first every time 
    JS.RegisterJSInclude(this, _api.SitePath + "/js/first.js", "FirstJS"); 

    JS.RegisterJSInclude(this, _api.SitePath + "/js/atk.js", "AdobeTypeKitJS"); 
    JS.RegisterJSInclude(this, _api.SitePath + "/js/file2.js", "File2JS"); 

    // I'd like this to be called last every time 
    JS.RegisterJSInclude(this, _api.SitePath + "/js/last.js", "LastJS"); 

이러한 파일은 호출 순서대로로드됩니다. 마스터 페이지, 웹 폼 또는 위젯에서 호출되는지 여부에 관계없이 호출 순서를 제어하고 싶습니다. 예를 들어

Ektron.Cms.CommonApi _api = new Ektron.Cms.CommonApi(); 
    JS.RegisterJSInclude(this, _api.SitePath + "/js/widget.js", "WidgetJS"); 

으로 전화를 걸면 나는 항상 'LastJS'앞에 오기를 원합니다.

Ektron v8.6에서도 가능합니까? 우선 순위를 지정하는 방법이없는 -

답변

0

이 페이지의 이벤트 실행 순서에 내려 오는 당신은 버전을 지정하지 않은, 그래서 전체 프레임 워크 API와 8.5+ 가정거야 수동으로 주문하십시오.

그러나 위젯 Init 이벤트에 /js/widget.js를로드하고 페이지 Load 이벤트에서 다른 이벤트를로드하면 예를 들어 widget.js가 먼저로드되어야합니다. 위에서 설명한 내용에 이상적인지 확신 할 수 없습니다. 위 코드에서 사이에 두 개의 다른 위젯을로드 할 것을 요청할 수 있습니다. 이는 불가능합니다. 적어도 상자 밖에서는 안됩니다.

그러나 사용자 지정 솔루션으로 수행 할 수있는 작업이있을 수 있습니다. 예를 들어, 과 같은 것은이되어야합니다. 테스트하지는 않았지만 말입니다. 내가 다음에 하나 개의 이벤트에서 오브젝트를 전달하는 HttpContext를 사용하고 -, 위젯, 페이지, 마스터에서 작동되는 등

// adding javascript objects to http context in init function on page/widget 
protected void Page_Init(object sender, EventArgs e) 
{ 
    List<JSObject> AddOns; 
    object StoredAddOns = HttpContext.Current.Items["JSAddOns"]; 
    if (StoredAddOns == null) 
    { 
     AddOns = new List<JSObject>(); 
    } 
    else 
    { 
     AddOns = (List<JSObject>)StoredAddOns; 
    } 
    // javascript being added to the list in the wrong order intentionally 
    AddOns.Add(new JSObject() { name = "LastJS", path = "/js/last.js", priority = 10 }); 
    AddOns.Add(new JSObject() { name = "WidgetJS", path = "/js/widget.js", priority = 5 }); 
    HttpContext.Current.Items["JSAddOns"] = AddOns; 
} 

// reading js objects from httpcontext and adding them to the page using framework ui api 
// this could just as easily be prerender - as long as the event that reads the objects is after the event that writes them 
protected void Page_Load(object sender, EventArgs e) 
{ 
    object StoredAddOns = HttpContext.Current.Items["JSAddOns"]; 
    if (StoredAddOns != null) 
    { 
     var AddOns = (List<JSObject>)StoredAddOns; 
     // using LINQ to order the JS objects by custom-defined priority setting 
     var SortedAddOns = AddOns.OrderBy(j => j.priority); 
     // looping through items in priority order to add to the page 
     foreach (var js in SortedAddOns) 
     { 
      Ektron.Cms.Framework.UI.JavaScript.Register(this, js.path, true); 
     } 
    } 
} 

// the custom js object 
public class JSObject 
{ 
    public int priority { get; set; } 
    public string path { get; set; } 
    public string name { get; set; } 
    public JSObject() 
    { 
     priority = 0; 
     path = string.Empty; 
     name = string.Empty; 
    } 
} 

사이드 참고 : 당신이 SitePath을 사용하려고하는 경우, 돈 ' /로 다음 문자열을 시작하십시오. 그렇지 않으면 경로가 //js/widget.js (Ektron 응용 프로그램이 사이트의 루트에 있다고 가정) 또는 /path//js/widget.js (하위 폴더 또는 하위 응용 프로그램에있는 경우)로 나옵니다.

+0

답변 해 주셔서 감사합니다. 이것은 이상적은 아니지만 우리가하는 일에 효과적입니다. – whoacowboy

관련 문제