PDA

View Full Version : I resolved non-onload problem when back via safari in iPhone



shinriyo
27 Mar 2012, 12:06 AM
iPhone can't DO onload when back page via safari.
So, I can't click.:((

But, I found how to add listener again though back prev page.



function addListenerTo(element, event, aFunction) {

/*
element.addEventListener(event, function(event){
aFunction(me,event);
}, false);
*/
// adding listener by 1s
setInterval(function() { element.addEventListener(event, function(event){ aFunction(me,event); }, false) }, 1000);
}


but... I'm afraid adding a lot listeners. :s

arnebech
27 Mar 2012, 4:16 PM
I am not fully sure what you are trying to accomplish.
Can you describe the issue more and show the relevant code?

shinriyo
27 Mar 2012, 6:37 PM
Hi arnebech

It is the problem of iPhone safari.

In the situation from A page to B page.
33216
A is the page developed by Sencha Animator.

I attached click event to AN-sObj-42 button.


window.addEventListener('load', function(){




var configData = {
parentId: 'AN-sObj-parentOl',
ormma: false,
scenes: [{id: 0,animationCount: 14,duration: 3800,dimensions: {height: 320,width: 320,expanded: false,fit: false}}],
clickEvents: [{id: "AN-sObj-42",handler: function(controller) {
linkConvert();
}}]
};
AN.Controller.setConfig(configData);
}, false);


when I go to B page from A page.
And I touch prev button of safari.

load event can't run!!


window.addEventListener('load', function(){


so, it doesn't run!


setupListeners: function() {
var me = this;

var eventName = "webkitAnimationEnd";


if (document.body.style.MozAnimationName !== undefined) {
eventName = "animationend";
this.browser = "moz";
}


this.olElement.addEventListener(eventName, function() {
me.onAnimationEnd();
},false);

function addMousemoveListenerTo(scene) {
scene.element.addEventListener('mousemove', function(event){
scene.mousemoveAction(me, event);
}, false);
}

var scene;
for (var i=0; i < this.scenesArray.length; i++) {
scene = this.scenesArray[i];
if (scene.mousemoveAction) {

addMousemoveListenerTo(scene);
}
}
/* it didn't run! */
function addListenerTo(element, event, aFunction) {
element.addEventListener(event, function(event){
aFunction(me,event);
}, false);


}

//add click events
var element, clickEvent;
for (var i=0; i < this.clickEvents.length; i++) {
clickEvent = this.clickEvents[i];
element = document.getElementById(clickEvent.id);
addListenerTo(element, 'click', clickEvent.handler);
}

},


I fix below and I resolved.


function addListenerTo(element, event, aFunction) {


/*
element.addEventListener(event, function(event){
aFunction(me,event);
}, false);
*/
// adding listener by 1s
setInterval(function() { element.addEventListener(event, function(event){ aFunction(me,event); }, false) }, 1000);
}

but, I'm afraid if the addEventListener increacing.

arnebech
28 Mar 2012, 10:35 AM
So if I understand you correctly, when you got back in Safari the animation won't load, because the 'load' event is never fired?

Could you check what the document state is when the load event is attached? And when/if the load event is fired?

e.g.



alert(document.readyState);
window.addEventListener('load', function(){
alert('load run state: ' + document.readyState);
.....
}

shinriyo
28 Mar 2012, 4:34 PM
Hi arnebech


>So if I understand you correctly, when you got back in Safari the animation won't load, because the 'load' event is never fired?

Yes.
Safari never fire load event when I back to prev page.


>Could you check what the document state is when the load event is attached? And when/if the load event is fired?

I tried your code.
Before backing, it is appeared.
--
loading
load run state:complete
---

But, when touch button later buck to prev page, it is never appeared.

arnebech
29 Mar 2012, 8:59 AM
Could you PM me a link or the exported project, so I could try it out?

shinriyo
29 Mar 2012, 6:58 PM
Hi arnebech

I found how to attach only one Listener.

I delete classified information and will send you PM later.

shinriyo
29 Mar 2012, 8:50 PM
Hi arnebech

I'm sorry.
I put the animation on the social game platform.
The social game platform avoid the animation. :s
It is not Sencha Animator problem.

arnebech
30 Mar 2012, 6:51 AM
As long as you only are attaching one handler you should be good. I tried to reproduce your issue, but was not able to, but sounds like you have it working now as well.