JQuery reel breaks inside AJAX called DOM change / insertion .load() - javascript

It is a bit hard to explain everything I have done in this situation, but here I go...
From a nav / menu I am inserting a variety of PHP files with content into my index page via .on('click') and .load('page.php')... one of those php pages includes 3 other php elements that are related to 2 JQuery reel instances and a 2 drop down selectors inside of another .on('click') that displays the instructions and the default images.
I have gotten all of my JQuery / raw JS to work inside the called PHP div - those related to the JQuery reel by using getScript inside of the .on('click')->.load('page.php')...
But even using getScript - JQuery reel only initializes the first time. I tried using window reload (because after going back to the home page - the first instance works again) before loading the div with the called PHP (it refreshed to the home page and didn't load the div), I tried clearing the JQuery cache, etc...
Long story short.
JQuery reel populates the head when initializing the css/images... on the first instance but not after that inside of AJAX called content.

The answer was built in to JQuery reel all along. Petre Vostrel is top notch.
FROM: GitHub Reel - issues
"Hi, please use $.reel.scan() method after you inject the HTML. Excerpt from the documentation:
Responsible for discovery and subsequent conversion of data-configured Reel images is $.reel.scan() method, which is being called automagically when the DOM becomes ready. Under normal circumstances you don't need to scan by yourself.
It however comes in handy to re-scan when you happen to inject a data-configured Reel into already ready DOM."

Related

PHP File Tree displays tree expanded first then collapse and causes flickering on initial page load

I've been using this PHP File Tree library with jQuery for quite some time now. Although it works flawlessly for my requirements (thanks to the author for sharing), one little detail bothers me. When loading/refreshing the web page, the file tree always shows up fully expanded first then very quickly gets collapsed by the following function call:
$(".php-file-tree").find("UL").hide();
Is there a way to either call this function before the page content gets displayed to the users or perhaps temporarily hide displaying anything on the page until this function did it's magic?
The whole idea is that the user would not see the initial expanded tree, only the collapsed view.
jQuery version used : 3.1.1
Maybe adding script after <body> tag can help you.
Check more info here:
Running JavaScript function before page load (setting background of appropriate size)

jQuery loses ability to read HTML and CSS tags inside AJAX script after location hash change

I'm experiencing some issues regarding an AJAX script I'm working on.
The page loads perfectly well, and all needed scripts are loaded the same for basic page functionality inside AJAX script, but after hash change, jQuery behaves awkwardly.
Let's take this example.
The custom jQuery script writes an inline CSS propriety for a specific DIV at page loading:
Now, I load the login page for example:
I get back to the main page and inline style disappears as well as the basic loaded functionalities cease to exist after Ajax call:
*
Any experience on this? Does anyone have a clue why this happens? Or even near it... Seems the script unloads on page/hash change, which I don't believe. Or enters in double loop, therefore doubling the classes for HTML. I don't get it.
Already searched a lot and went trough the coding and is fine becasue it works fine alongside with basic HTML. Would appreciate some thoughts on this matter.
Thanks!

How can I add jQuery (SharePoint 2010)?

I have a HTML page that I need to be linked to within our organization's SharePoint 2010 portal. I have all needed files (CSS, images, jquery) stored in the same document library. The CSS seems to be working fine but I'm having trouble getting the jQuery to work. Any suggestions or thoughts on what could be the issue here? Thank you.
**Update: The HTML page consists of one image (image map) that I have sectioned into 100 or so clickable areas. When clicked, a jQuery plugin activates and (SHOULD) display a tooltip directly to the right of the clickable area. My issue is that the tooltip is being displayed to the right of the WHOLE image instead. So I think I was wrong in my initial question about the jQuery not working. The tooltip plugin indeed activates, it is just appearing outside the image instead of on top of the image where it should be. This works properly in a local environment but once the files are uploaded to the SharePoint server this behavior happens. Is there some internal JS/CSS files within SharePoint that I can/need to override? Thanks for helping!
Need some more details, is jQuery not loading at all? Or just errors calling jQuery functions? I'm guessing you're getting errors calling jQuery functions. You'll want to use jQuery.noConflict(); to prevent conflicts with SharePoint javascript functions. The $ symbol that jQuery uses by default is also used by SharePoint. So you call jQuery.noConflict(); at the top of your javascript, and then you just swap using the $ for calling jQuery functions to just writing jQuery. So $(document).ready becomes jQuery(document).ready. $.ajax becomes jQuery.ajax, and so on.
jQuery.noConflict Details

Javascript 1-2 second delay on page load, weird styling

I'm using Skrollr to animate & create parralax effects when scrolling the page, but there's a short lag which I guess is the Skrollr javascript/jQuery initialising.
Any ideas on how to avoid having the mess at the beginning?
The WP website in question is this one : http://hustynminepark.com
Thank You!
Unless I'm mistaken, the layout of your page entirely depends on the activation of the plugin. You can solve this problem by finetuning the CSS so that the initial page corresponds exactly to what you see after activation of the plugin.
Also, don't forget to minify (concatenate / uglify) your javascript files before loading them into the browser; this will speed up the loading of the page and the activation of the plugin.
Btw, the site looks pretty cool.
If I am correct you have a FOUC, you can use jQuery to detect when your DOM in ready then call init.
First of all you want to include the skrollr.min.js file at the bottom of your document (right before the closing ) and then call skrollr.init(). Or you can place it inside the if you want to, but make sure to call init() once the document has been loaded (e.g. jQuery's ready event or even window.onload).

What to use in place of $(document).ready();?

So I'm using jquery along with some plugins I wrote.
I do all the initialization in a $(document).ready(function(){}) block however this is executed when the whole DOM has been loaded and is ready to be used.
However that would take long eg. when there is a server load. Or maybe the user clicks a button that has been loaded while the rest of the page hasn't loaded yet (and thus document.ready() hasn't been executed yet) in which case it would do nothing.
So, what if I want a code to be executed right after the related part of the page has been loaded instead of waiting for the WHOLE page to be loaded?
I know placing inline code right after the html that this js operates on would do the trick but what if that code uses a library like jQuery that hasn't been loaded yet?
I know placing inline code right after the html that this js operates on would do the trick but what if that code uses a library like jQuery that hasn't been loaded yet?
That would be the only way. The HTML is parsed from top to bottom. So you can expect every script you included to be accesible after you included it.
Your page should still work without JavaScript anyway, so a user clicking a button extremely fast will just temporarily have a somewhat degraded experience.
That being said, the DOM is basically ready when the HTML document all scripts are loaded. Since you cannot execute meaningful JavaScript before the JavaScript code is loaded (duh), I'd have a close look at page performance. Sending an HTML document and 2,3 JavaScript files should not be slow.
You could also use the old-style inline event handlers, like <button onclick="registerButtonClickEvent()">. However, this would introduce a complex, potentially buggy and hardly testable layer of temporary event holding.
If your <script src="jquery-whatever.js> line precedes the first clickable element in your HTML, it is guaranteed that the jquery library will be loaded and run before the user has anything useful to click on.
Just don't add async or defer attributes to the script element.
The onload event isn't triggered from all html elements, so you're forced to wait for window load. It doesn't matter where you load jQuery since it will have to wait for document to be ready. That total time required to load jQuery plus the rest of the document will be thet same.

Categories

Resources