Created
December 8, 2017 19:42
-
-
Save seedcms/bd108f10cb92c5b7e6d0a956911ce03c to your computer and use it in GitHub Desktop.
lookbooks-app-loading-fix.js - no jquery loader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Localize jQuery variable | |
var fancyBox = 'no'; | |
var masonry = 'no'; | |
var images = 'no'; | |
var bxSlider = 'no'; | |
var slickSlider = 'no'; | |
function scripts_loaded(scriptName){ | |
switch(scriptName){ | |
case 'bxSlider': | |
bxSlider = 'yes'; | |
break; | |
case 'fancyBox': | |
fancyBox = 'yes'; | |
break; | |
case 'images': | |
images = 'yes'; | |
break; | |
case 'masonry': | |
masonry = 'yes'; | |
break; | |
case 'slickSlider': | |
slickSlider = 'yes'; | |
break; | |
} | |
if( fancyBox === 'yes' && bxSlider === 'yes' && images === 'yes' && masonry === 'yes' && slickSlider === 'yes' ){ | |
main(); | |
} | |
} | |
function loadScript(url, callback){ | |
var script = document.createElement("script") | |
script.type = "text/javascript"; | |
if (script.readyState){ //IE | |
script.onreadystatechange = function(){ | |
if (script.readyState == "loaded" || | |
script.readyState == "complete"){ | |
script.onreadystatechange = null; | |
callback(); | |
} | |
}; | |
} else { //Others | |
script.onload = function(){ | |
callback(); | |
}; | |
} | |
script.src = url; | |
document.getElementsByTagName("head")[0].appendChild(script); | |
} | |
loadScript("https://pressify.s3.amazonaws.com/assets/fancybox/source/jquery.fancybox.js", function(){ | |
// do something | |
scripts_loaded('fancyBox') | |
}); // end loader | |
loadScript("https://npmcdn.com/[email protected]/dist/masonry.pkgd.min.js", function(){ | |
scripts_loaded('masonry') | |
}); // end loader | |
loadScript("https://npmcdn.com/[email protected]/imagesloaded.pkgd.min.js", function(){ | |
scripts_loaded('images') | |
}); // end loader | |
loadScript("https://pressify.s3.amazonaws.com/assets/bxslider/jquery.bxslider.min.js", function(){ | |
scripts_loaded('bxSlider') | |
}); // end loader | |
loadScript("https://s3-us-west-2.amazonaws.com/look-books/slick/slick.min.js", function(){ | |
scripts_loaded('slickSlider') | |
}); // end loader | |
/******** Our main function ********/ | |
function main() { | |
jQuery(document).ready(function(){ | |
// app domain | |
var appDomain = '//lookbooks-herokuapp-com.global.ssl.fastly.net'; | |
// default vars to load the correct gallery | |
var collection_id = jQuery('.lookbook_details').data('collection-id'); | |
var page_id = jQuery('.lookbook_details').data('page-id'); | |
var product_id = jQuery('.lookbook_details').data('product-id'); | |
var article_id = jQuery('.lookbook_details').data('article-id'); | |
var shop_url = jQuery('.lookbook_details').data('shop-url'); | |
var url = appDomain + '/lookbooks/get/?collection_id='+collection_id+'&product_id='+product_id+'&page_id='+page_id+'&article_id='+article_id+'&shop_url='+shop_url+'&v=4.0'; | |
console.log(appDomain + '/lookbooks/get/?collection_id='+collection_id+'&product_id='+product_id+'&page_id='+page_id+'&article_id='+article_id+'&shop_url='+shop_url+'&v=4.0'); | |
$.ajax({ | |
url: url, | |
cache: false, | |
dataType: "html", | |
success: function(data) { | |
jQuery(".lookbook_details").html(data); | |
} | |
}); | |
}); // end on document ready | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment