me gustaría hacerles llegar la siguiente duda que me ha surgido al intentar hacer un widget:
Tengo un fichero .js con el siguiente contenido:
************************************************** *****************************
// Inicialización de widgets
if (typeof BolsamaniaWidgetInicializar == 'undefined') {
function BolsamaniaWidgetInicializar() {
// Cotizaciones
var widgets = document.getElementsByTagName("div");
var idWidget = 0;
for (var i = 0; i < widgets.length; i++) {
if (widgets[i].className == "bolsamania_widget_cotizacion") {
var atributos = (widgets[i].getAttribute("rel")).split("#");
var widget = new BolsamaniaWidgetCotizacion(idWidget, atributos[0], atributos[1]);
eval("BolsamaniaWidgetCotizacion_" + idWidget + " = widget;");
idWidget++;
}
}
}
}
// Añade funciones que se ejecutarán al cargar la página
if (typeof addLoadListener == 'undefined') {
function addLoadListener(fn) {
if (typeof window.addEventListener != 'undefined') window.addEventListener('load', fn, false);
else if (typeof document.addEventListener != 'undefined') document.addEventListener('load', fn, false);
else if (typeof window.attachEvent != 'undefined') window.attachEvent('onload', fn);
else {
var oldfn = window.onload;
if (typeof window.onload != 'function') window.onload = fn;
else window.onload = function() { oldfn(); fn(); };
}
}
}
// Crea la clase de objetos widget de cotización
addLoadListener(BolsamaniaWidgetInicializar);
if (typeof BolsamaniaWidgetCotizacion == 'undefined') {
function BolsamaniaWidgetCotizacion(id, cotizaciones, template) {
this.cotizaciones = cotizaciones;
this.template = template;
this.id = id;
this.div = "bolsamania_widget_cotizacion_" + id;
this.divContenido = "bolsamania_widget_cotizacion_contenido_" + id;
this.datos = null;
var divsWidget = new Array();
var divs = document.getElementsByTagName("div");
for (var i = 0; i < divs.length; i++) if (divs[i].className == "bolsamania_widget_cotizacion") divsWidget.push(divs[i]);
divsWidget[id].id = this.div;
//var flag = false;
for (var i = 0; i < divsWidget[id].childNodes.length; i++) {
//if (divsWidget[id].childNodes[i].className == "cabecera-economista") flag = true;
if (divsWidget[id].childNodes[i].className == "contenido-bolsamania") divsWidget[id].childNodes[i].id = this.divContenido;
}
this.obtenerDatos = BolsamaniaWidgetCotizacion_ObtenerDatos;
this.pintarDatos = BolsamaniaWidgetCotizacion_PintarDatos;
this.obtenerEstilos = BolsamaniaWidgetCotizacion_ObtenerEstilos;
/*if (!flag) {
alert("La estructura del widget no es correcta");
return;
}*/
this.obtenerEstilos();
this.obtenerDatos();
}
/*elemento1.appendChild(elemento2);
Con este método añadiremos el elemento “elemento2” a “elemento1”.*/
function BolsamaniaWidgetCotizacion_ObtenerDatos() {
sc = document.getElementById(this.div + "_js");
con = document.getElementById(this.div);
if (sc) con.removeChild(sc);
sc = document.createElement("script");
sc.id = this.div + "_js";
con.appendChild(sc);
sc.src = "http://--/widgets/cotizacion-datos.php?widget=BolsamaniaWidgetCotizacion_" + this.id + "&cotizacion=" + this.cotizaciones;
//alert(sc.src);
setTimeout("BolsamaniaWidgetCotizacion_" + this.id + ".obtenerDatos()", 60000);
}
function BolsamaniaWidgetCotizacion_PintarDatos() {
alert("HOLA");
sc = document.getElementById(this.divContenido);
var datos = this.datos.valores;
var contenido = "";
contenido += "<div id=\"cotizacion-bolsamania\">";
for (var i = 0; i < datos.length; i++) {
contenido += "<div class=\"datos-bolsamania\">";
contenido += "<table class=\"eco-tabla\">";
contenido += "<tbody>";
contenido += "<tr class=\"eco-name\">";
contenido += "<td colspan=\"2\">";
contenido += "<a href=\"" + datos[i].url + "\">" + datos[i].cotizacion + "</a>";
contenido += "</td>";
contenido += "</tr>";
//contenido += "<tr><td>Precio:</td><td>" + datos[i].valor + "</td></tr>";
contenido += "<tr><td>Variación:</td><td><span class=\"accion" + datos[i].estado + "\">" + datos[i].diferencia + "</span></td></tr>";
contenido += "<tr><td>Hora:</td><td>" + datos[i].hora + "</td></tr>";
contenido += "</tr>";
contenido += "</table>";
contenido += "</div>";
if (datos[i].grafico == "on") {
contenido += "<div class=\"grafico-bolsamania\">";
if (this.template == "160-white") contenido += "<a href=\"" + datos[i].url + "\"><img src=\"http://--/Graficos/graficaIntradia_Reducida.php?idQuote=" + datos[i].id + "\" /></a>";
else if (this.template == "160-black") contenido += "<a href=\"" + datos[i].url + "\"><img src=\"http://--/Graficos/graficaIntradiaNegro_Reducida.php?idQuote=" + datos[i].id + "\" /></a>";
else if (this.template == "250-white") contenido += "<a href=\"" + datos[i].url + "\"><img src=\"--/Graficos/graficaIntradia.php?idQuote=" + datos[i].id + "\" /></a>";
else if (this.template == "250-black") contenido += "<a href=\"" + datos[i].url + "\"><img src=\"--/Graficos/graficaIntradiaNegro.php?idQuote=" + datos[i].id + "\" width=\"240\" width=\"154\" /></a>";
contenido += "</div>";
}
sc.innerHTML = contenido;
}
}
function BolsamaniaWidgetCotizacion_ObtenerEstilos() {
var cssElementCheck = document.getElementById(this.div + "_css");
if (cssElementCheck) cssElementCheck.parentNode.removeChild(cssElementC heck);
var cssElement = document.createElement("link");
cssElement.id = this.div + "_css";
cssElement.rel = "stylesheet";
cssElement.type = "text/css";
document.getElementsByTagName("head")[0].appendChild(cssElement);
cssElement.href = "http://--/widgets/cotizacion-estilos.php?div=" + this.div + "&template=" + this.template;
}
}
La duda que me surge es como tiene que ser el código del php: cotizacion-datos.php para hacer correctamente la llamada a la function BolsamaniaWidgetCotizacion_PintarDatos() y me pinte los datos, es decir,
Yo lo que quiero es desde el php provacar la ejecucion de la función. Tampoco se como darle los valores que tiene que pintar dicha función.
Os ruego, por favor que me ayuden, porque no tengo ni idea de cómo hacerlo.