Skip to content

Commit 2c81c50

Browse files
committed
Bug Fixes
Better error handling, broken image identification
1 parent 09c943b commit 2c81c50

File tree

3 files changed

+26
-20
lines changed

3 files changed

+26
-20
lines changed

index.html

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@
1717

1818
<body>
1919
<center class="row">
20-
<img src="img/thumbnail/1.jpg" title="1.jpg" width="80">
21-
<img src="img/thumbnail/2.jpg" title="2.jpg" width="80">
22-
<img src="img/thumbnail/3.jpg" title="3.jpg" width="80">
23-
<img src="img/thumbnail/4.jpg" title="4.jpg" width="80">
24-
<img src="img/thumbnail/5.jpg" title="5.jpg" width="80">
25-
<img src="img/thumbnail/6.jpg" title="6.jpg" width="80">
26-
<img src="img/thumbnail/7.jpg" title="" width="80">
27-
<img src="img/thumbnail/8.jpg" title="8.jpg" width="80">
28-
<img src="img/thumbnail/9.jpg" title="9.jpg" width="80">
29-
<img src="img/thumbnail/10.jpg" title="10.jpg" width="80">
20+
<img src="img/thumbnail/1.jpg" data-content="1.jpg" width="80">
21+
<img src="img/thumbnail/2.jpg" data-content="2.jpg" width="80">
22+
<img src="img/thumbnail/3.jpg" data-content="3.jpg" width="80">
23+
<img src="img/thumbnail/4.jpg" data-content="4.jpg" width="80">
24+
<img src="img/thumbnail/5.jpg" data-content="5.jpg" width="80">
25+
<img src="img/thumbnail/6.jpg" data-content="6.jpg" width="80">
26+
<img src="img/thumbnail/7.jpg" data-content="71" width="80">
27+
<img src="img/thumbnail/8.jpg" data-content="" width="80">
28+
<img src="img/thumbnail/9.jpg" data-content="9.jpg" width="80">
29+
<img src="img/thumbnail/10.jpg" data-content="10.jpg" width="80">
3030
</center>
3131
<!-- Bootstrap core JavaScript
3232
================================================== -->
@@ -37,7 +37,7 @@
3737
<script>
3838
$("img").airview({
3939
url: './img/',
40-
width: 200,
40+
width: 250,
4141
container:'body'
4242
});
4343
</script>

js/airview.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* ========================================================================
22
* Bootstrap-Airview: airview.js v1.0.0
3-
* https://github.com/deviprsd21/Bootstrap-Airview
3+
* http://deviprsd21.github.io/Airview/
44
* ========================================================================
55
* This Plugin is inspired by Tooltip.js by Jacob Thornton
66
* Copyright 2014 Devi Prasad
@@ -46,6 +46,7 @@
4646
}
4747

4848
Airview.prototype.setContent = function () {
49+
var $e = this.$element
4950
var $tip = this.tip()
5051
var title = this.getTitle()
5152
var imgalt = title.substr(title.lastIndexOf('/') + 1)
@@ -68,7 +69,8 @@
6869

6970
// IE8 doesn't accept hiding via the `:empty` pseudo selector, we have to do
7071
// this manually by checking the contents.
71-
if (!title) $tip.find('.airview-inner').empty().html('<h4>' + this.options.error + '</h4>')
72+
if (!title || $e.attr('data-lost')) $tip.find('.airview-inner').empty().addClass('error').html('<span>' + this.options.error + '</span>')
73+
else if(title && isNaN(dimension.height) && $e.attr('data-broken')) $tip.find('.airview-inner').empty().addClass('error').html('<span>Broken Link</span>')
7274
}
7375

7476
Airview.prototype.getHeight = function (width) {
@@ -78,7 +80,7 @@
7880

7981
Airview.prototype.fixTitle = function () {
8082
var $e = this.$element
81-
var loaded = false
83+
var error = false
8284
var wait = false
8385
var img = new Image()
8486
var that = this
@@ -99,15 +101,19 @@
99101
else title = content ? this.options.url ? this.options.url + content : content : title
100102
}
101103

102-
img.addEventListener('load', function () { }, true)
104+
$(img).error(function(e){
105+
if(title) $e.attr('data-broken', true)
106+
else $e.attr('data-lost', true)
107+
error = true
108+
})
103109
img.src = title
104110

105111
wait = setInterval(function () {
106-
if(img.width != 0 && img.height != 0) {
112+
if(img.width != 0 && img.height != 0 || error) {
107113
$e.attr('data-aratio', img.width / img.height)
108114
img.removeAttribute("src")
109-
img = null
110-
clearInterval(wait)
115+
img = null
116+
clearInterval(wait)
111117
}
112118
},0)
113119
}

js/airview.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)