Permalink
Browse files

Merge pull request #306 from nknapp/master

Fix for "No theme CSS loaded", when galleria is loaded dynamically through jquery-ui-tabs
  • Loading branch information...
2 parents 1e2e47b + 280d829 commit 63565e19db57aa23672497b61ce2df24e04be20f @davidhellsing davidhellsing committed Nov 20, 2013
Showing with 63 additions and 29 deletions.
  1. +17 −0 README.rst
  2. +46 −29 src/galleria.js
View
17 README.rst
@@ -20,3 +20,20 @@ Documentation is currently available in `reST
<http://en.wikipedia.org/wiki/ReStructuredText>`_ format in the repository.
You can build local HTML using Sphinx: http://sphinx.pocoo.org/
+
+
+Changes compared to original (aino) version of galleria
+=======================================================
+
+* Fix for "No theme CSS loaded", when galleria is loaded dynamically through JS and AJAX Galleria may be inserted into
+ the dom dynamically (e.g. via JavaScript loaded from an AJAX-Request). In such a case, the theme's script-tag seems
+ not to be immediately present in the DOM when the addTheme-function looks for it. We therefore try multiple times
+ before raising an error.
+
+* Sometimes, the dummy image was not scaled and centered properly when using lazyLoadChunked().
+ This was due to the dimensions of the dummy image not being computed in time (with lazyLoadChunked(...)).
+ We changed the retry method from "retry once after 2ms" to "Utils.wait{ ..., timeout: 100 }" to retry multiple times
+ for 100ms.
+
+
+
View
75 src/galleria.js
@@ -5620,29 +5620,42 @@ Galleria.addTheme = function( theme ) {
// else look for the absolute path and load the CSS dynamic
if ( !css ) {
- $(function() {
-
- $('script').each(function( i, script ) {
- // look for the theme script
- reg = new RegExp( 'galleria\\.' + theme.name.toLowerCase() + '\\.' );
- if( reg.test( script.src )) {
-
- // we have a match
- css = script.src.replace(/[^\/]*$/, '') + theme.css;
-
- window.setTimeout(function() {
- Utils.loadCSS( css, 'galleria-theme', function() {
- // the themeload trigger
- _themeLoad( theme );
+ $(function() {
+ // Try to determine the css-path from the theme script.
+ // In IE8/9, the script-dom-element seems to be not present
+ // at once, if galleria itself is inserted into the dom
+ // dynamically. We therefore try multiple times before raising
+ // an error.
+ var retryCount = 0;
+ var tryLoadCss = function() {
+ $('script').each(function (i, script) {
+ // look for the theme script
+ reg = new RegExp('galleria\\.' + theme.name.toLowerCase() + '\\.');
+ if (reg.test(script.src)) {
+
+ // we have a match
+ css = script.src.replace(/[^\/]*$/, '') + theme.css;
+
+ window.setTimeout(function () {
+ Utils.loadCSS(css, 'galleria-theme', function () {
+
+ // the themeload trigger
+ _themeLoad(theme);
- });
- }, 1);
+ });
+ }, 1);
+ }
+ });
+ if (!css) {
+ if (retryCount++ > 5) {
+ Galleria.raise('No theme CSS loaded');
+ } else {
+ window.setTimeout(tryLoadCss,500);
+ }
}
- });
- if ( !css ) {
- Galleria.raise('No theme CSS loaded');
}
+ tryLoadCss();
});
}
@@ -6150,7 +6163,7 @@ Galleria.Picture.prototype = {
// reload the image with a timestamp
window.setTimeout((function(image, src) {
return function() {
- image.attr('src', src + '?' + Utils.timestamp() );
+ image.attr('src', src + (src.indexOf('?') > -1 ? '&' : '?') + Utils.timestamp() );
};
}( $(this), src )), 50);
} else {
@@ -6197,22 +6210,26 @@ Galleria.Picture.prototype = {
// Delay the callback to "fix" the Adblock Bug
// http://code.google.com/p/adblockforchrome/issues/detail?id=3701
if ( ( !this.width || !this.height ) ) {
- window.setTimeout( (function( img ) {
- return function() {
- if ( img.width && img.height ) {
+ (function( img) {
+ Utils.wait({
+ until : function() {
+ return img.width && img.height;
+ },
+ success : function() {
complete.call( img );
- } else {
- // last resort, this should never happen but just in case it does...
+ },
+ error : function() {
if ( !resort ) {
$(new Image()).load( onload ).attr( 'src', img.src );
resort = true;
} else {
Galleria.raise('Could not extract width/height from image: ' + img.src +
'. Traced measures: width:' + img.width + 'px, height: ' + img.height + 'px.');
}
- }
- };
- }( this )), 2);
+ },
+ timeout: 100
+ });
+ }( this ));
} else {
complete.call( this );
}
@@ -6803,4 +6820,4 @@ if ( typeof module === "object" && module && typeof module.exports === "object"
// phew
-}( jQuery, this ) );
+}( jQuery, this ) );

0 comments on commit 63565e1

Please sign in to comment.