Search code examples
tridiontridion-2011

how to overwrite initialization of standard method


can we use standard 'InsertCpDialog$initialize()' in our javascript like this , so that i can call other function once it get initializes. I used like below code but it is not working. :(

Type.registerNamespace("Extensions");
Extensions.InsertCpDialog.prototype.initialize  = function InsertCpDialog$initialize()
{
alert('hi  inside insert');
var p = this.properties;
if(window.document.nameProp == "Name" || window.document.title == "Name") {

    var browserName=navigator.appName; // Get the Browser Name

    if(browserName=="Microsoft Internet Explorer") // For IE
    {
    alert('hi inside IE');
//window.onload=init(); // Call init function in IE
    }
    else
    {
    if (document.addEventListener) // For Firefox
    {
    alert('hi inside firefox');    
//document.addEventListener("DOMContentLoaded", init(), false); // Call init function in Firefox
    }
}
}
}

Original(standard) one is like:

Type.registerNamespace ("Tridion.Cme.Views");  
Tridion.Cme.Views.InsertCpDialog = function InsertCpDialog()
{
Type.enableInterface(this, "Tridion.Cme.Views.InsertCpDialog");
this.addInterface("Tridion.Cme.Views.DashboardBase");
};

Tridion.Cme.Views.InsertCpDialog.prototype.initialize = function InsertCpDialog$initialize()
{
}

Edit

hi frank thank you, but already i am using same thing in my code to get the list of componet and template listed on a page under CP tab.

function getbtn() {
//alert('inside getbtn');
var sbtn = document.getElementById ("buttonComponentInsert");
$evt.addEventHandler(sbtn , "click", getListofCPBtnClick);
} 

function getListofCPBtnClick(e) {
//code will go here    
}

My question is : I need to get selected Component and template Id from Insert CP window.Earlier i was able to get that by changing the CME extension standard code, but i am not suppose to do that, So first i am trying to initialize the "insert CP window" from my javascript code. I can create event handler for that window, but my question is how to initialize that so that i can call any function once it get initialize. Kindly let me know if i anot clear.


Solution

  • Is your script getting loaded into the dialog?

    If not, Albert shows how to do that here: http://albertromkes.com/2012/01/30/tridion-gui-extensions-how-to-load-a-javascript-without-showing-a-gui-element/

    He then also shows how to listen to events to accomplish something similar to what you are trying to do.