GithubHelp home page GithubHelp logo

Comments (7)

charlau avatar charlau commented on September 21, 2024

This even happens if the javascript is added after jSP is activated. For example, I have this problem with google's recaptcha in a form inside a scroll pane. I tried to build the recaptcha outside of it, and after a settimout, change the content of a div inside the scroll pane. As soon as that div is modified with the javascript, the page reacts and becomes unusable...

Still looking for a workaround, since the whole site is scroller enabled...

By the way, that happens in FF but not in Chrome.

from jscrollpane.

phena109 avatar phena109 commented on September 21, 2024

I thought I won't be able to work out a workaround for that but suprisingly i worked out a ralatively quick and dirty solution for that.

With the inspiration of the page here: http://stackoverflow.com/questions/610995/jquery-cant-append-script-element (message posted by Hendra Uzia)

I am now able to execute the code only once with the drawback that the script is not inspectable via simple mean (and i don't feel that i must make it visible). It is as follow:

taking the v2.0.0beta10/11 as the starting point, around line 92 (or below a line with "<originalScrollLeft = elem.scrollLeft();">")

insert:

                    var scripts = [];
                    elem.find("script").each(function(){
                        scripts.push($(this).clone());
                    });                    
                    elem.find("script").remove();

and at acount line 120 (or below a line ").append(pane).appendTo(elem);")

insert:

                    _size = scripts.length;
                    for(i=0;i<_size;i++){
                        eval(scripts[i]);
                    }

What it does is that it clones all the script elements in the block and save it in an array. Then execute(eval()) all scripts after the JSP finished with DOM manipulation. It at least for my case on IE9(comp ie8,ie7),FF,GC and my android phone. what i didn't test is native ie7+8, opera all iProducts. improvements on that likely are memory management, better code placement, etc.

At last, i don't own any credit of this. Use at your own risk.

from jscrollpane.

nelsonad avatar nelsonad commented on September 21, 2024

I tracked this down to being an issue with how the elements are being manipulated during jScrollPane initialization.

Scripts are eval'd and run within jQuery's append method, which is used to move the elements children within the new jspPane container. But the jspPane has not yet been added to the document. So any inline scripts that run against the children elements will not be able to find the element.

By changing the order in which elements are created and appended, this issue can be resolved without ripping out the scripts from the dom and eval'ing them manually.

example:
current code Version: 2.0.0beta11, Last updated: 2011-07-04

pane = $('<div class="jspPane" />').css('padding', originalPadding).append(elem.children());
container = $('<div class="jspContainer" />')
     .css({
     'width': paneWidth + 'px',
     'height': paneHeight + 'px'
    }
).append(pane).appendTo(elem);

becomes

elemChildren = elem.children().remove();
pane = $('<div class="jspPane" />').css('padding', originalPadding)
container = $('<div class="jspContainer" />')
.css({
    'width': paneWidth + 'px',
    'height': paneHeight + 'px'
    }
).append(pane).appendTo(elem);
pane.append(elemChildren);

from jscrollpane.

vitch avatar vitch commented on September 21, 2024

Sorry for the very slow reply on this - I haven't had much time to dedicate to jScrollPane recently. A newly submitted issue (#160) reminded me of this one...

I'm curious as to why appending the children to the pane after it is already in the DOM prevents the script firing twice?

from jscrollpane.

nelsonad avatar nelsonad commented on September 21, 2024

In the first code block, the children are appended to "pane" and script is evaluated, then "pane" is appended to "container" and script is evaluated again.

In my suggested change, the child content is only passed to jquery's append method once, so script is only executed once.

I didnt end up using this solution though, instead fixed the issue with the control which had inline script that was erroring out.

from jscrollpane.

vitch avatar vitch commented on September 21, 2024

Ahh... When I read the description of the problem I thought that the two firings of the script were:

  1. When the page loads
  2. When JSP is initialised

And I didn't understand how your code would prevent either of these times. But it seems like the script is firing twice when JSP is initialised?

from jscrollpane.

nelsonad avatar nelsonad commented on September 21, 2024

Right, twice during JSP initialization.

from jscrollpane.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.