Comments (7)
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.
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.
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.
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.
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.
Ahh... When I read the description of the problem I thought that the two firings of the script were:
- When the page loads
- 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.
Right, twice during JSP initialization.
from jscrollpane.
Related Issues (20)
- main prop removed from package.json -> Build failed HOT 9
- Incorrect height of scrolling element after reinitialization. HOT 18
- Line with console.log HOT 9
- archive project / search for maintainers HOT 6
- reinitialise method: do not always apply new options HOT 1
- Improvement: pause and resume methods HOT 2
- Broken after updating from 2.0.22 to 2.1.2: jScrollPane is not a function (npm, webpack) HOT 29
- NPM shows rc releases tagged as "latest" HOT 2
- Focus on a input in a table will cause auto scrolling to top under jQuery 3 HOT 10
- Missing kinetic scroll on touch devices HOT 9
- Scrollpane is jumping to bottom HOT 2
- Console error in jquery when use cursor keys HOT 8
- When using stickToBottom and alwaysShowVScroll it does not start by sticking HOT 5
- How to get jScrollPane from node_modules HOT 1
- Jquery 3.5.0 Security Fix Closing HTML Tags HOT 4
- Jquery 4.0: Use of number-typed values is deprecated HOT 4
- click don't work after JScrollPane and Ajax HOT 10
- Error in jScrollPane - v2.2.3-rc.1 - jquery.jscrollpane.js HOT 3
- Still "border-box" problem HOT 3
- jScrollPane loads its own jQuery when used in webpack HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jscrollpane.