forked from picuous/tumblrbox
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtumblrbox.js
96 lines (88 loc) · 2.85 KB
/
tumblrbox.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
* tumblrboxv2 - Lightbox effect for Tumblr
* using FancyBox
*
* Copyright (c) 2011 Picuous
* Copyright (c) 2013 makujaho
*
* Version: alpha (goodified => without tracking)
*
* Licensed under the MIT license
* http://www.opensource.org/licenses/mit-license.php
*/
;(function() {
console.log('tumblrbox start');
// Global variables
var otherlib = false;
if(typeof jQuery != 'undefined') {
//console.debug('This page is already using jQuery v'+jQuery.fn.jquery);
} else if (typeof $ == 'function') {
//console.debug('This page is using another $ library');
otherlib = true;
}
// more or less stolen form jquery core and adapted by paul irish
// shameless stolen again and chained to a fancyBox commit blob
function load_file(url, success) {
var script;
var blob = 'http://makujaho.github.com/tumblrbox/';
if(url.match(/\.js$/)) {
script = document.createElement('script');
script.src = blob+url;
script.type = 'text/javascript';
} else {
script = document.createElement('link');
script.rel = 'stylesheet';
script.type = 'text/css';
script.href = blob+url;
}
var head = document.getElementsByTagName('head')[0],
done = false;
// Attach handlers for all browsers
script.onload=script.onreadystatechange = function() {
if(!done && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete') ) {
done = true;
if(success) {
success();
}
script.onload = script.onreadystatechange = null;
//head.removeChild(script);
}
};
head.appendChild(script);
}
load_file('jquery-1.9.0.min.js', function() {
if(typeof jQuery=='undefined') {
console.log('Sorry, but jQuery wasn\'t able to load');
} else {
$ = jQuery.noConflict();
console.log('loaded '+$.fn.jquery);
// Add CSS
load_file('jquery.mousewheel-3.0.6.pack.js', function(){
console.log('Loaded MouseWheel')
load_file('jquery.fancybox.css', function() {
console.log('Added FancyBox CSS');
});
load_file('jquery.fancybox.pack.js', function() {
console.log('loaded fancybox');
var options = {
mouseWheel: false,
autoCenter: true,
closeClick: true,
fitToView: true,
autoSize: true,
padding : 20,
helpers: {
title: null,
css : {
'background' : 'rgba(58, 42, 45, 0.95)'
}
},
};
var $tb_hires = $('a[href*=".media.tumblr.com"].hi-res');
$tb_hires.fancybox(options).attr('data-fancybox-group', 'hires');
console.log(($tb_images.length + $tb_hires.length) + ' tumblr pictures tumblrboxed');
});
});
}
});
})();