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

Dejar sin efecto una función mediante otra

Estas en el tema de Dejar sin efecto una función mediante otra en el foro de Frameworks JS en Foros del Web. Hola. Me explico. Tengo un slider de noticias que se activa con: @import url("http://static.forosdelweb.com/clientscript/vbulletin_css/geshi.css"); Código Javascript : Ver original < script type = "text/javascript" > ...
  #1 (permalink)  
Antiguo 19/07/2010, 15:41
Avatar de AlZuwaga
Colaborador
 
Fecha de Ingreso: febrero-2001
Ubicación: 34.517 S, 58.500 O
Mensajes: 14.550
Antigüedad: 23 años, 2 meses
Puntos: 535
Dejar sin efecto una función mediante otra

Hola. Me explico. Tengo un slider de noticias que se activa con:

Código Javascript:
Ver original
  1. <script type="text/javascript">
  2.    
  3.         function formatText(index, panel) {
  4.           return index + "";
  5.         }
  6.    
  7.         $(function () {
  8.        
  9.             $('.anythingSlider').anythingSlider({
  10.                 easing: "easeInOutExpo",        // Anything other than "linear" or "swing" requires the easing plugin
  11.                 autoPlay: true,                 // This turns off the entire FUNCTIONALY, not just if it starts running or not.
  12.                 delay: 3000,                    // How long between slide transitions in AutoPlay mode
  13.                 startStopped: false,            // If autoPlay is on, this can force it to start stopped
  14.                 animationTime: 600,             // How long the slide transition takes
  15.                 hashTags: true,                 // Should links change the hashtag in the URL?
  16.                 buildNavigation: true,          // If true, builds and list of anchor links to link to each slide
  17.                 pauseOnHover: true,             // If true, and autoPlay is enabled, the show will pause on hover
  18.                 startText: "Go",             // Start text
  19.                 stopText: "Stop",               // Stop text
  20.                 navigationFormatter: formatText       // Details at the top of the file on this use (advanced use)
  21.             });
  22.            
  23.             $("#slide-jump").click(function(){
  24.                 $('.anythingSlider').anythingSlider(6);
  25.             });
  26.            
  27.         });
  28.     </script>


Ahora, resulta que quiero dejar ese slider sin efecto mediante un función llamada slider_lista(elemento)

Código Javascript:
Ver original
  1. <script type="text/javascript">
  2.     function slider_lista(elemento){
  3. /*      <div class="anythingSlider" id="slider">*/
  4.         var elemento = document.getElementById(elemento.id);
  5.         if(elemento.textContent == "Ordenar"){
  6.             elemento.textContent = "Rotar"
  7.             document.getElementById('slider').className = "anythingSliderOrden";
  8.         }
  9.         else{
  10.             elemento.textContent = "Ordenar"
  11.             document.getElementById('slider').className = "anythingSlider";
  12.         }
  13.     }
  14.     </script>
  15.  
  16.  
  17. <div id="slider_lista" onclick="slider_lista(this)">Ordenar</div>

Lo que hace esa función básicamente es reemplazar la clase anythingSlider por otra (anythingSliderOrden) al div #slider peeeeero... si bien el slider deja de funcionar, me siguen apareciendo "cosas" creadas por la ejecución original de $('.anythingSlider').anythingSlider(...). Cosas como por ejemplo que los enlaces de navegación siguen apareciendo y me agrega <li> de más (el primero lo duplica al final y el último al inicio). Lo que me gustaría es que esa función hiciera de cuenta que jamás se hubiera llamado a la primera (y que al volver a hacer click vuelva todo a la normalidad)

El motivo de todo esto es poder "desactivar" el slider para poder ordenar sus contenidos "visualmente" mediante "jquery.ui.sortable.js".

Me explico? Se puede?
Gracias!
__________________
...___...
  #2 (permalink)  
Antiguo 19/07/2010, 15:55
Avatar de David
Moderador
 
Fecha de Ingreso: abril-2005
Ubicación: In this planet
Mensajes: 15.720
Antigüedad: 19 años
Puntos: 839
Respuesta: Dejar sin efecto una función mediante otra

De forma sencilla, no. Según he visto en la documentación el slider que estás usando no tiene un método para destruirlo.

Sin indagar más a fondo, una idea sería tener una copia de la lista sin modificar que ocultes/muestres cuando vayas a realizar el ordenamiento.

Saludos.
__________________
Por favor, antes de preguntar, revisa la Guía para realizar preguntas.
  #3 (permalink)  
Antiguo 19/07/2010, 16:00
Avatar de AlZuwaga
Colaborador
 
Fecha de Ingreso: febrero-2001
Ubicación: 34.517 S, 58.500 O
Mensajes: 14.550
Antigüedad: 23 años, 2 meses
Puntos: 535
Respuesta: Dejar sin efecto una función mediante otra

Gracias David. Había pensado en esa opción pero quería previamente ver si existía una manera más (por llamarlo) "elegante". Si no encuentro forma lo haré así
__________________
...___...
  #4 (permalink)  
Antiguo 19/07/2010, 20:48
Avatar de David
Moderador
 
Fecha de Ingreso: abril-2005
Ubicación: In this planet
Mensajes: 15.720
Antigüedad: 19 años
Puntos: 839
Respuesta: Dejar sin efecto una función mediante otra

Otra cosa que he probado y al parecer funciona correctamente es guardar el contenido del div y luego restaurarlo para hacer el reset. Algo como esto:
Código Javascript:
Ver original
  1. function formatText(index, panel) {
  2.     return index + "";
  3. }
  4.  
  5. function startSlider() {
  6.     var obj = $(".anythingSlider");
  7.     obj.data("lastcontent", obj.html());
  8.     obj.anythingSlider({
  9.         easing: "easeInOutExpo",        // Anything other than "linear" or "swing" requires the easing plugin
  10.         autoPlay: true,                 // This turns off the entire FUNCTIONALY, not just if it starts running or not.
  11.         delay: 3000,                    // How long between slide transitions in AutoPlay mode
  12.         startStopped: false,            // If autoPlay is on, this can force it to start stopped
  13.         animationTime: 600,             // How long the slide transition takes
  14.         hashTags: true,                 // Should links change the hashtag in the URL?
  15.         buildNavigation: true,          // If true, builds and list of anchor links to link to each slide
  16.         pauseOnHover: true,             // If true, and autoPlay is enabled, the show will pause on hover
  17.         startText: "Go",             // Start text
  18.         stopText: "Stop",               // Stop text
  19.         navigationFormatter: formatText       // Details at the top of the file on this use (advanced use)
  20.     });
  21. }
  22.  
  23. function stopSlider() {
  24.     var obj = $(".anythingSlider");
  25.     obj.html(obj.data("lastcontent"));
  26. }
  27.  
  28. $(function () {
  29.     startSlider();
  30.    
  31.     $("#slide-jump").click(function(){
  32.         $('.anythingSlider').anythingSlider(6);
  33.     });
  34. });
De modo que llames a stopSlider() para volver al contenido original y startSlider() para volver a iniciarlo.
__________________
Por favor, antes de preguntar, revisa la Guía para realizar preguntas.
  #5 (permalink)  
Antiguo 20/07/2010, 08:10
Avatar de AlZuwaga
Colaborador
 
Fecha de Ingreso: febrero-2001
Ubicación: 34.517 S, 58.500 O
Mensajes: 14.550
Antigüedad: 23 años, 2 meses
Puntos: 535
Respuesta: Dejar sin efecto una función mediante otra

Gracias David. Lo pruebo en cuanto llegue a la ofician. Igual no lo estoy entendiendo del todo :sonrojado:
__________________
...___...
  #6 (permalink)  
Antiguo 20/07/2010, 11:20
Avatar de AlZuwaga
Colaborador
 
Fecha de Ingreso: febrero-2001
Ubicación: 34.517 S, 58.500 O
Mensajes: 14.550
Antigüedad: 23 años, 2 meses
Puntos: 535
Respuesta: Dejar sin efecto una función mediante otra

Ok. Funciona! Gracias. Ahora tengo otro problema.
Si cargo la página por primera vez todo funciona OK. Pero cuando llamo a stopSlider() deja de funcionar este fragmento de código que es el que hace el "sort":


Código Javascript:
Ver original
  1. $(document).ready(function() {
  2.       $(".wrapper ul").sortable({
  3.         update : function () {
  4.             var order = $('.wrapper ul').sortable('serialize');
  5.             alert('noti_ordena_tapa_exe.php?'+order+'&action=updateOrder');
  6. //          $.post('noti_ordena_tapa_exe.php?'+order+'&action=updateOrder');
  7.         }
  8.       });
  9.     });

Si vuelvo a llamar a startSlider() tampoco funciona $(".wrapper ul").sortable() (cosa que si ocurre al cargar la página por primera vez)

Tenés idea qué puede estar pasando?
__________________
...___...
  #7 (permalink)  
Antiguo 20/07/2010, 11:29
Avatar de David
Moderador
 
Fecha de Ingreso: abril-2005
Ubicación: In this planet
Mensajes: 15.720
Antigüedad: 19 años
Puntos: 839
Respuesta: Dejar sin efecto una función mediante otra

Es porque el contenido del ul vuelve a su estado original.

Si, como tengo entendido, lo que quieres es que al momento de llamar a stopSlider() puedas ordenar los elementos, probablemente esto va a servir:
Código Javascript:
Ver original
  1. function startSlider() {
  2.     $(".wrapper ul").sortable("destroy");
  3.  
  4.     // Resto del código de startSlider()
  5. }
  6.  
  7. function stopSlider() {
  8.     // Código de stopSlider()
  9.  
  10.       $(".wrapper ul").sortable({
  11.         update : function () {
  12.             var order = $('.wrapper ul').sortable('serialize');
  13.             alert('noti_ordena_tapa_exe.php?'+order+'&action=updateOrder');
  14. //          $.post('noti_ordena_tapa_exe.php?'+order+'&action=updateOrder');
  15.         }
  16.       });
  17. }
__________________
Por favor, antes de preguntar, revisa la Guía para realizar preguntas.
  #8 (permalink)  
Antiguo 20/07/2010, 11:38
Avatar de AlZuwaga
Colaborador
 
Fecha de Ingreso: febrero-2001
Ubicación: 34.517 S, 58.500 O
Mensajes: 14.550
Antigüedad: 23 años, 2 meses
Puntos: 535
Respuesta: Dejar sin efecto una función mediante otra

Sos un "mostro"!!! :reverencias:
Cuando vengas para Argentina avisame que lo menos que puedo hacer es invitarte unas cuantas Coca Colas
__________________
...___...
  #9 (permalink)  
Antiguo 20/07/2010, 15:05
Avatar de David
Moderador
 
Fecha de Ingreso: abril-2005
Ubicación: In this planet
Mensajes: 15.720
Antigüedad: 19 años
Puntos: 839
Respuesta: Dejar sin efecto una función mediante otra

De acuerdo, gracias por la invitación.

Me alegra que haya funcionado.

Saludos.
__________________
Por favor, antes de preguntar, revisa la Guía para realizar preguntas.

Etiquetas: dejar, efecto
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 02:29.