Foros del Web » Programando para Internet » Javascript » Frameworks JS »

Mootols conflicto con interpretador de JS

Estas en el tema de Mootols conflicto con interpretador de JS en el foro de Frameworks JS en Foros del Web. El Problema es que al cargar una librería que interpreta el código JS escrito por ajax, me deja de funcionar un slider que tengo con ...
  #1 (permalink)  
Antiguo 09/09/2010, 14:07
 
Fecha de Ingreso: diciembre-2009
Ubicación: Valparaíso
Mensajes: 118
Antigüedad: 14 años, 4 meses
Puntos: 3
Exclamación Mootols conflicto con interpretador de JS

El Problema es que al cargar una librería que interpreta el código JS escrito por ajax, me deja de funcionar un slider que tengo con mootols.

Código HTML:
Ver original
  1. //Cargo libreria mootols
  2. <script src="scripts/mootools-1.2-core.js" type="text/javascript"></script>
  3. <script src="scripts/_class.noobSlide.packed.js" type="text/javascript"></script>
  4. <script language='javascript' type="text/javascript">
  5.     window.addEvent('domready', function () {
  6.         //SAMPLE 4 (walk to item)
  7.         var nS4 = new noobSlide({
  8.             autoPlay: true,
  9.             mode: 'vertical',
  10.             box: $('slider'),
  11.             items: $$('#slider h3'),
  12.             size: 171,
  13.             handles: $$('#slider_botones img'),
  14.             onWalk: function (currentItem, currentHandle) {
  15.                 this.handles.set('opacity', 0.5);
  16.                 currentHandle.set('opacity', 1);
  17.             }
  18.         });
  19.     });
  20.  
  21. //Cargo libreria que interpreta los JS
  22. <script src="/include/scripts/InterpretaJS.js" type="text/javascript"></script>
  23. <script type="text/javascript">
  24.     function ajaxFunction() {
  25.         var xmlHttp;
  26.         try {
  27.             // Firefox, Opera 8.0+, Safari
  28.             xmlHttp = new XMLHttpRequest();
  29.             return xmlHttp;
  30.         }
  31.         catch (e) {
  32.             // Internet Explorer
  33.             try {
  34.                 xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
  35.                 return xmlHttp;
  36.             }
  37.             catch (e) {
  38.                 try {
  39.                     xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  40.                     return xmlHttp;
  41.                 }
  42.                 catch (e) {
  43.                     alert("Tu navegador no soporta AJAX!");
  44.                     return false;
  45.                 }
  46.             }
  47.         }
  48.     }
  49.  
  50.     function fajax(id) {
  51.         var url = "ajax.aspx";              //página que se debe cargar
  52.         var contenedor = "cargaAjax";       //id div a recargar
  53.         var ajax = ajaxFunction();
  54.         if (!ajax) {
  55.             alert("No se puede ejecutar este proceso: Error de navegador");
  56.             return false;
  57.         }
  58.  
  59.         document.getElementById(contenedor).innerHTML = "<div class='progr_box1'><div class='progr_video'><br><br><br><br><br><br><center><strong><span style='color:White;'> ..:: Cargando Video ::.. </span><br><br><img src='/imagenes/loading.gif'><br> <br> </center></strong><a id='player' style='display:block;width:640px;height:380px;'></a></div><div class='progr_video_share'><span>Visto: Cargando datos...</span>&nbsp &nbsp &nbsp &nbsp<img src='/imagenes/loading.gif'> </div><h1><span>Cargando título....<p>Cargando bajada</p></div>";
  60.         ajax.open("POST", url, true);
  61.  
  62.         ajax.onreadystatechange = function () {
  63.             if (ajax.readyState == 4 && (ajax.status == 200 || window.location.href.indexOf("http") == -1)) {
  64.                var scs = ajax.responseText.extractScript();
  65.                 document.getElementById(contenedor).innerHTML = ajax.responseText;
  66.                 scs.evalScript();
  67.                
  68.             }
  69.         }
  70.         ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  71.         ajax.send("id=" + id);
  72.     }
  73.                

Si saco la libreria InterpretaJS.js funciona el slider, por eso se ese es el problema, dicha librería es la siguiente:
Código Javascript:
Ver original
  1. var tagScript = '(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)';
  2. /**
  3. * Eval script fragment
  4. * @return String
  5. */
  6. String.prototype.evalScript = function () {
  7.     return (this.match(new RegExp(tagScript, 'img')) || []).evalScript();
  8. };
  9. /**
  10. * strip script fragment
  11. * @return String
  12. */
  13. String.prototype.stripScript = function () {
  14.     return this.replace(new RegExp(tagScript, 'img'), '');
  15. };
  16. /**
  17. * extract script fragment
  18. * @return String
  19. */
  20. String.prototype.extractScript = function () {
  21.     var matchAll = new RegExp(tagScript, 'img');
  22.     return (this.match(matchAll) || []);
  23. };
  24. /**
  25. * Eval scripts
  26. * @return String
  27. */
  28. Array.prototype.evalScript = function (extracted) {
  29.     var s = this.map(function (sr) {
  30.         var sc = (sr.match(new RegExp(tagScript, 'im')) || ['', ''])[1];
  31.         if (window.execScript) {
  32.             window.execScript(sc);
  33.         }
  34.         else {
  35.             window.setTimeout(sc, 0);
  36.         }
  37.     });
  38.     return true;
  39. };
  40. /**
  41. * Map array elements
  42. * @param {Function} fun
  43. * @return Function
  44. */
  45. Array.prototype.map = function (fun) {
  46.     if (typeof fun !== "function") { return false; }
  47.     var i = 0, l = this.length;
  48.     for (i = 0; i < l; i++) {
  49.         fun(this[i]);
  50.     }
  51.     return true;
  52. };

La saque de este mismo Foro

He intentado moviendo la librería que trae los conflictos antes de mootols y el problema sigue, ya no se que más puedo hacer.
  #2 (permalink)  
Antiguo 09/09/2010, 15:01
 
Fecha de Ingreso: diciembre-2009
Ubicación: Valparaíso
Mensajes: 118
Antigüedad: 14 años, 4 meses
Puntos: 3
Respuesta: Mootols conflicto con interpretador de JS

Lo solucione, para los que tengan el mismo problema:

La librería de mootols contiene dos funciones que tienen el mismo nombre de funciones de la otra librería. Lo que hice fue cambiar el nombre de ambas funciones en la librería InterpretaJS.js

Las funciones eran stripScript y map, la corrección quedó así

Código Javascript:
Ver original
  1. var tagScript = '(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)';
  2. /**
  3. * Eval script fragment
  4. * @return String
  5. */
  6. String.prototype.evalScript = function () {
  7.     return (this.match(new RegExp(tagScript, 'img')) || []).evalScript();
  8. };
  9. /**
  10. * strip script fragment
  11. * @return String
  12. * striptScript reemplazado por stripScriptPrototype para evitar conflicto
  13. */
  14. [COLOR="red"]String.prototype.stripScriptPrototype = function () {[/COLOR]
  15.     return this.replace(new RegExp(tagScript, 'img'), '');
  16. };
  17. /**
  18. * extract script fragment
  19. * @return String
  20. */
  21. String.prototype.extractScript = function () {
  22.     var matchAll = new RegExp(tagScript, 'img');
  23.     return (this.match(matchAll) || []);
  24. };
  25. /**
  26. * Eval scripts
  27. * @return String
  28. */
  29. Array.prototype.evalScript = function (extracted) {
  30.     var s = this.map(function (sr) {
  31.         var sc = (sr.match(new RegExp(tagScript, 'im')) || ['', ''])[1];
  32.         if (window.execScript) {
  33.             window.execScript(sc);
  34.         }
  35.         else {
  36.             window.setTimeout(sc, 0);
  37.         }
  38.     });
  39.     return true;
  40. };
  41. /**
  42. * Map array elements
  43. * @param {Function} fun
  44. * @return Function
  45. * * map reemplazado por mapPrototype para evitar conflicto
  46. */
  47. [COLOR="Red"]Array.prototype.mapPrototype = function (fun) {[/COLOR]
  48.     if (typeof fun !== "function") { return false; }
  49.     var i = 0, l = this.length;
  50.     for (i = 0; i < l; i++) {
  51.         fun(this[i]);
  52.     }
  53.     return true;
  54. };
  #3 (permalink)  
Antiguo 09/09/2010, 15:02
 
Fecha de Ingreso: diciembre-2009
Ubicación: Valparaíso
Mensajes: 118
Antigüedad: 14 años, 4 meses
Puntos: 3
Respuesta: Mootols conflicto con interpretador de JS

Cita:
Iniciado por javiercitox Ver Mensaje
Lo solucione, para los que tengan el mismo problema:

La librería de mootols contiene dos funciones que tienen el mismo nombre de funciones de la otra librería. Lo que hice fue cambiar el nombre de ambas funciones en la librería InterpretaJS.js

Las funciones eran stripScript y map, la corrección quedó así

Código Javascript:
Ver original
  1. var tagScript = '(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)';
  2. /**
  3. * Eval script fragment
  4. * @return String
  5. */
  6. String.prototype.evalScript = function () {
  7.     return (this.match(new RegExp(tagScript, 'img')) || []).evalScript();
  8. };
  9. /**
  10. * strip script fragment
  11. * @return String
  12. * striptScript reemplazado por stripScriptPrototype para evitar conflicto
  13. */
  14. String.prototype.stripScriptPrototype = function () {
  15.     return this.replace(new RegExp(tagScript, 'img'), '');
  16. };
  17. /**
  18. * extract script fragment
  19. * @return String
  20. */
  21. String.prototype.extractScript = function () {
  22.     var matchAll = new RegExp(tagScript, 'img');
  23.     return (this.match(matchAll) || []);
  24. };
  25. /**
  26. * Eval scripts
  27. * @return String
  28. */
  29. Array.prototype.evalScript = function (extracted) {
  30.     var s = this.map(function (sr) {
  31.         var sc = (sr.match(new RegExp(tagScript, 'im')) || ['', ''])[1];
  32.         if (window.execScript) {
  33.             window.execScript(sc);
  34.         }
  35.         else {
  36.             window.setTimeout(sc, 0);
  37.         }
  38.     });
  39.     return true;
  40. };
  41. /**
  42. * Map array elements
  43. * @param {Function} fun
  44. * @return Function
  45. * * map reemplazado por mapPrototype para evitar conflicto
  46. */
  47. Array.prototype.mapPrototype = function (fun) {
  48.     if (typeof fun !== "function") { return false; }
  49.     var i = 0, l = this.length;
  50.     for (i = 0; i < l; i++) {
  51.         fun(this[i]);
  52.     }
  53.     return true;
  54. };

Etiquetas: ajax, conflicto, mootools
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 00:47.