Permalink
Browse files

Merge branch 'master' of https://github.com/aino/galleria

  • Loading branch information...
2 parents 7b9160a + 7383b74 commit 4014ec82199d3a7c3e729eba6bd2ce4d11c77a1a @davidhellsing davidhellsing committed Nov 22, 2013
Showing with 61 additions and 33 deletions.
  1. +2 −0 README.rst
  2. +59 −33 src/galleria.js
View
@@ -20,3 +20,5 @@ 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/
+
+
View
@@ -7,13 +7,12 @@
*
*/
-(function( $, Galleria, undef ) {
+(function( $, window, Galleria, undef ) {
/*global jQuery, navigator, Image */
// some references
-var window = this,
- doc = window.document,
+var doc = window.document,
$doc = $( doc ),
$win = $( window ),
@@ -1115,7 +1114,7 @@ $win.on( 'orientationchange', function() {
*/
-Galleria = window.Galleria = function() {
+Galleria = function() {
var self = this;
@@ -5621,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();
});
}
@@ -6151,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 {
@@ -6198,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 );
}
@@ -6807,6 +6823,16 @@ $.fn.galleria = function( options ) {
};
+// export as AMD or CommonJS
+if ( typeof module === "object" && module && typeof module.exports === "object" ) {
+ module.exports = Galleria;
+} else {
+ window.Galleria = Galleria;
+ if ( typeof define === "function" && define.amd ) {
+ define( "galleria", ['jquery'], function() { return Galleria; } );
+ }
+}
+
// phew
-}( jQuery ) );
+}( jQuery, this ) );

0 comments on commit 4014ec8

Please sign in to comment.