Jump to content

SUBIECTE NOI
« 1 / 5 »
RSS
Deparazitare externa pisici fara ...

Seriale turcesti/coreene online H...

Merita un Termostat Smart pentru ...

Sfat achizitie MTB Devron Riddle
 Problema mare cu parintii= nervi ...

switch microtik

Permis categoria B la 17 ani

Sfaturi pentru pregatirea de eval...
 Crapaturi placa

cum imi accesez dosarul electroni...

Momentul Aprilie 1964

Sursa noua - zgomot ?
 A fost lansat Ubuntu 24.04 LTS

Pareri apartament in zona Berceni?

Free streaming SkyShowtime de la ...

Skoda Fabia 1.0 TSI (110 CP)- 19 ...
 

Acelasi Javascript merge pe o pagina si nu pe alta

- - - - -
  • Please log in to reply
No replies to this topic

#1
leny29

leny29

    Member

  • Grup: Members
  • Posts: 438
  • Înscris: 17.06.2013
Salut,

Am un javascript care imi da batai de cap.
Merge pe o pagina si nu pe alta. Site-u e Drupal 7. Dar problema nu e cu Drupal, e de javascript si jQuery.

Parerea mea e ca e ceva lega de un eveniment undefined in jQuery...
Nu e nici o eroare in loguri.

Aici e secevanta din Chrome DevTools care functioneaza bine:
SCENARIUL 1
1) Am un cod html integrat intr-o pagina mai mare:
<div class="player">
<audio data-playing="false"> <source src="/sites/default/files/titlu_fisier.mp3" type="audio/mpeg">
</audio>
<button class="sm2_button" onclick="toggleAudio(this.previousElementSibling)"></button>
</div>


2) Cand dau click pe button ajunge callul la audio.js care contine
function toggleAudio (d) {
if (d.dataset.playing === "false" || typeof(d.dataset.playing) == "undefined") {
	 d.play();
	 d.dataset.playing = "true";
	 }
}


3) Apoi DevTools se intoarce la:
toggleAudio(this.previousElementSibling)

4) Apoi ajunge in jquery-1.4.4-uncompressed.js   la linia ultima linie:
return typeof jQuery !== "undefined" && !jQuery.event.triggered ?
jQuery.event.handle.apply( eventHandle.elem, arguments ) :
undefined;


Am postat aici o parte mai mare din script. Am adaugat eu variabilele test si test1 in penultimile linii, ca sa le inspectez mai usor. E acelasi lucru ca si linia de sub ele cu return.

jQuery.event = {
// Bind an event to an element
// Original by Dean Edwards
add: function( elem, types, handler, data ) {
if ( elem.nodeType === 3 || elem.nodeType === 8 ) {
return;
}
// For whatever reason, IE has trouble passing the window object
// around, causing it to be cloned in the process
if ( jQuery.isWindow( elem ) && ( elem !== window && !elem.frameElement ) ) {
elem = window;
}
if ( handler === false ) {
handler = returnFalse;
} else if ( !handler ) {
// Fixes bug #7229. Fix recommended by jdalton
return;
}
var handleObjIn, handleObj;
if ( handler.handler ) {
handleObjIn = handler;
handler = handleObjIn.handler;
}
// Make sure that the function being executed has a unique ID
if ( !handler.guid ) {
handler.guid = jQuery.guid++;
}
// Init the element's event structure
var elemData = jQuery.data( elem );
// If no elemData is found then we must be trying to bind to one of the
// banned noData elements
if ( !elemData ) {
return;
}
// Use a key less likely to result in collisions for plain JS objects.
// Fixes bug #7150.
var eventKey = elem.nodeType ? "events" : "__events__",
events = elemData[ eventKey ],
eventHandle = elemData.handle;

if ( typeof events === "function" ) {
// On plain objects events is a fn that holds the the data
// which prevents this data from being JSON serialized
// the function does not need to be called, it just contains the data
eventHandle = events.handle;
events = events.events;
} else if ( !events ) {
if ( !elem.nodeType ) {
// On plain objects, create a fn that acts as the holder
// of the values to avoid JSON serialization of event data
elemData[ eventKey ] = elemData = function(){};
}
elemData.events = events = {};
}
if ( !eventHandle ) {
elemData.handle = eventHandle = function() {
// Handle the second event of a trigger and when
// an event is called after a page has unloaded
test= typeof jQuery;
test1 = typeof jQuery !== "undefined" && !jQuery.event.triggered ?
	 jQuery.event.handle.apply( eventHandle.elem, arguments ) :
	 undefined;
return typeof jQuery !== "undefined" && !jQuery.event.triggered ?
	 jQuery.event.handle.apply( eventHandle.elem, arguments ) :
	 undefined;
};
}


5) Callul merge in fisierul asta: https://code.jquery....2.1.slim.min.js
r.event = {
	 global: {},
	 add: function(a, b, c, d, e) {
		 var f, g, h, i, j, k, l, m, n, o, p, q = W.get(a);
		 if (q) {
			 c.handler && (f = c,
			 c = f.handler,
			 e = f.selector),
			 e && r.find.matchesSelector(ra, e),
			 c.guid || (c.guid = r.guid++),
			 (i = q.events) || (i = q.events = {}),
			 (g = q.handle) || (g = q.handle = function(b) {
return "undefined" != typeof r && r.event.triggered !== b.type ? r.event.dispatch.apply(a, arguments) : void 0
			 }


6) iese apoi din jQuery si ajunge apoi in alt javascript legat de altceva, de eu_cookied_compliance. Nu il mai adaug aici pentru ca pentru mine nu e relevant.

SCENARIUL 2
Acelasi html ca la punctul unu este adaugat in alta pagina unde nu merge, pentru ca la sfarsit face un submit la toata pagina:
Pasii 1,2 sunt aceeasi
3) in DevTools se intoarce in pagina HTML la tag-ul html de dupa </div> de la pasul 1 adica la tagul <ul>
<div class="player">
<audio><source src="/sites/default/files/titlu_fisier.mp3" type="audio/mpeg">
</audio>
<button class="sm2_button" onclick="toggleAudio(this.previousElementSibling)"></button>
</div>
<ul class="exercise_ul">
<div id="edit-question-0" class="form-radios">


4) jquery-uncompressed.1.4.4  acelasi ca in scenariul 1 cand functioneaza bine
5) https://code.jquery....2.1.slim.min.js acelasi ca in scenariul 1 cand functioneaza bine
6) revine in jquery-uncompressed.1.4.4 de la pasul 4 si apoi face un re-submit la toata pagina

Eu nu inteleg de ce face re-submit-ul, si de ce e diferenta asta intre Scenariul 1 si 2.

Puteti sa ma ajutati va rog, sa-l debughez, sa inteleg de unde vine diferenta, si de ce face re-submit cand nu ar trebui sa faca re-submit?

Edited by leny29, 25 March 2023 - 15:46.


Anunturi

Bun venit pe Forumul Softpedia!

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Forumul Softpedia foloseste "cookies" pentru a imbunatati experienta utilizatorilor Accept
Pentru detalii si optiuni legate de cookies si datele personale, consultati Politica de utilizare cookies si Politica de confidentialitate