Skip to content

Commit

Permalink
finishing demos
Browse files Browse the repository at this point in the history
  • Loading branch information
shprink committed Jan 23, 2014
1 parent d127f83 commit 42d2a38
Show file tree
Hide file tree
Showing 15 changed files with 676 additions and 632 deletions.
48 changes: 24 additions & 24 deletions BttrLazyLoading.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class BttrLazyLoading

_setOptionsFromData.call @

@$wrapper = $ '<div class="bttrlazyloading-wrapper">'
@$wrapper = $ '<span class="bttrlazyloading-wrapper">'
@$wrapper.addClass @options.wrapperClasses if @options.wrapperClasses and typeof @options.wrapperClasses is 'string'
@$img.before @$wrapper
# The easier way to simulate a responsive image is to use canvas
Expand Down Expand Up @@ -58,10 +58,10 @@ class BttrLazyLoading
false
i = i.replace('bttrlazyloading', '').replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase().split '-'
if i.length > 1
@options.img[i[0]][i[1]] = v if typeof @options.img[i[0]][i[1]] isnt 'undefined'
@options[i[0]][i[1]] = v if typeof @options[i[0]][i[1]] isnt 'undefined'
else
if $.inArray(i[0], @whiteList) > -1 and typeof v is 'object'
$.extend(@options.img[i[0]], v)
if typeof v is 'object'
$.extend(@options[i[0]], v)
else
@options[i[0]] = v if typeof @options[i[0]] isnt 'undefined'

Expand Down Expand Up @@ -119,6 +119,8 @@ class BttrLazyLoading
_update.call @

@container[onOrOff] @options.event, update
# making sure we laod image within a container not in the viewport
$(window)[onOrOff] @options.event, update if @options.container isnt window
$(window)[onOrOff] "resize", update

_getRangeFromScreenSize = () ->
Expand All @@ -145,8 +147,8 @@ class BttrLazyLoading
src

_getImgObjectPerRange = (range)->
if typeof @options.img[range].src isnt 'undefined' and @options.img[range].src isnt null
return @options.img[range]
if typeof @options[range].src isnt 'undefined' and @options[range].src isnt null
return @options[range]
return null

_getLargestImgObject = () ->
Expand Down Expand Up @@ -204,7 +206,6 @@ class BttrLazyLoading
# If the range changed (window resize) we update the canvas size
if @range isnt _getRangeFromScreenSize.call @
_updateCanvasSize.call @
console.log _isUpdatable.call @, '_isUpdatable.call @'
if _isUpdatable.call @
@$img.trigger 'bttrlazyloading.load'

Expand Down Expand Up @@ -251,23 +252,22 @@ class BttrLazyLoadingGlobal
lg : 1200

@options =
img:
xs :
src : null
width : 100
height : 100
sm :
src : null
width : 100
height : 100
md :
src : null
width : 100
height : 100
lg :
src : null
width : 100
height : 100
xs :
src : null
width : 100
height : 100
sm :
src : null
width : 100
height : 100
md :
src : null
width : 100
height : 100
lg :
src : null
width : 100
height : 100
retina : false
animation: 'bounceIn'
delay: 0
Expand Down
1 change: 1 addition & 0 deletions bttrlazyloading.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ MIT License, https://github.com/shprink/BttrLazyLoading/blob/master/LICENSE
.bttrlazyloading-wrapper {
background-repeat: no-repeat;
background-position: center;
display: table;
}
.bttrlazyloading-clone,
.bttrlazyloading {
Expand Down
2 changes: 1 addition & 1 deletion bttrlazyloading.min.css

Large diffs are not rendered by default.

102 changes: 42 additions & 60 deletions demo/animations.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,13 @@
<link rel="stylesheet" type="text/css" href="../bower_components/bootswatch/yeti/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="../bower_components/font-awesome/css/font-awesome.min.css" />
<link rel="stylesheet" type="text/css" href="../bttrlazyloading.min.css" />
<link rel="stylesheet" type="text/css" href="css/style.css" />
<script src="../bower_components/jquery/jquery.min.js"></script>
<script src="../bower_components/jquery.smooth-scroll/jquery.smooth-scroll.min.js"></script>
<script src="../bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="../bower_components/highlight.js/src/styles/solarized_dark.css" />
<script src="js/highlight.pack.js"></script>
<script src="../jquery.bttrlazyloading.min.js"></script>
<style>
body{
margin-top: 58px;
}
#back-to-top{
font-size: 30px;
position: fixed;
bottom: 20px;
right: 20px;
cursor: pointer;
}
.alert {
font-size: 15px;
font-weight: 500;
}
</style>
</head>
<body>
<div class="container">
Expand All @@ -42,6 +27,7 @@
<div class="col-md-6">
<h2>HTML</h2>
<pre><code class="html">&lt;img id=&quot;yourImg&quot; class=&quot;bttrlazyloading&quot;
data-bttrlazyloading-xs-transition=&quot;flipInX&quot;
data-bttrlazyloading-xs-src=&quot;img/800x300.jpg&quot;
data-bttrlazyloading-xs-width=&quot;800&quot;
data-bttrlazyloading-xs-height=&quot;300&quot;
Expand Down Expand Up @@ -70,28 +56,26 @@
<div class="col-md-6">
<h2>JavaScript</h2>
<pre><code class="javascript">$('#yourImg').bttrlazyloading({
transition: 'flipInX' // Select among the CSS animations below
img: {
xs: {
src: 'http://placekitten.com/800/300',
width: 800,
height: 300
},
sm: {
src: 'http://placekitten.com/380/380',
width: 380,
height: 380
},
md: {
src: 'http://placekitten.com/350/350',
width: 350,
height: 350
},
lg: {
src: 'http://placekitten.com/300/300',
width: 300,
height: 300
}
transition: 'flipInX' // Select among the CSS animations below
xs: {
src: 'http://placekitten.com/800/300',
width: 800,
height: 300
},
sm: {
src: 'http://placekitten.com/380/380',
width: 380,
height: 380
},
md: {
src: 'http://placekitten.com/350/350',
width: 350,
height: 350
},
lg: {
src: 'http://placekitten.com/300/300',
width: 300,
height: 300
}
});</pre></code>
</div>
Expand Down Expand Up @@ -185,7 +169,7 @@
</div>
<?php include 'more-demo.php'; ?>
</div>
<?php include 'menu.php'; ?>
<?php include '../menu.php'; ?>
<script type="text/javascript">
$(function($, hljs) {
$('#back-to-top').click(function(event) {
Expand Down Expand Up @@ -231,27 +215,25 @@
$img.bttrlazyloading({
animation: animations[i],
delay: 1000,
img: {
xs: {
src: 'img/800x300.jpg',
width: 800,
height: 300
},
sm: {
src: 'img/380x380.jpg',
width: 380,
height: 380
},
md: {
src: 'img/350x350.jpg',
width: 350,
height: 350
},
lg: {
src: 'img/300x300.jpg',
width: 300,
height: 300
}
xs: {
src: 'img/800x300.jpg',
width: 800,
height: 300
},
sm: {
src: 'img/380x380.jpg',
width: 380,
height: 380
},
md: {
src: 'img/350x350.jpg',
width: 350,
height: 350
},
lg: {
src: 'img/300x300.jpg',
width: 300,
height: 300
}
});
}
Expand Down
17 changes: 17 additions & 0 deletions demo/css/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
body{
margin-top: 58px;
}
#back-to-top{
font-size: 30px;
position: fixed;
bottom: 20px;
right: 20px;
cursor: pointer;
}
.alert {
font-size: 15px;
font-weight: 500;
}
#loading-area > div{
margin-bottom: 15px;
}
136 changes: 136 additions & 0 deletions demo/different-sizes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
<?php
define('DEMO', 'different-sizes');
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="../bower_components/bootswatch/yeti/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="../bower_components/font-awesome/css/font-awesome.min.css" />
<link rel="stylesheet" type="text/css" href="../bttrlazyloading.min.css" />
<link rel="stylesheet" type="text/css" href="css/style.css" />
<script src="../bower_components/jquery/jquery.min.js"></script>
<script src="../bower_components/jquery.smooth-scroll/jquery.smooth-scroll.min.js"></script>
<script src="../bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="../bower_components/highlight.js/src/styles/solarized_dark.css" />
<script src="js/highlight.pack.js"></script>
<script src="../jquery.bttrlazyloading.min.js"></script>
</head>
<body>
<div class="container">
<div class="jumbotron">
<h1>Different sizes</h1>
<p>BttrLazyLoading works even better when image sizes are defined. See for yourself!</p>
</div>
<div class="row">
<div class="col-md-6">
<h2>HTML</h2>
<pre><code class="html">&lt;img id=&quot;yourImg&quot; class=&quot;bttrlazyloading&quot;
data-bttrlazyloading-xs-src=&quot;img/800x300.jpg&quot;
data-bttrlazyloading-xs-width=&quot;800&quot;
data-bttrlazyloading-xs-height=&quot;300&quot;
data-bttrlazyloading-sm-src=&quot;img/380x380.jpg&quot;
data-bttrlazyloading-sm-width=&quot;380&quot;
data-bttrlazyloading-sm-height=&quot;380&quot;
data-bttrlazyloading-md-src=&quot;img/350x350.jpg&quot;
data-bttrlazyloading-md-width=&quot;350&quot;
data-bttrlazyloading-md-height=&quot;350&quot;
data-bttrlazyloading-lg-src=&quot;img/300x300.jpg&quot;
data-bttrlazyloading-lg-width=&quot;300&quot;
data-bttrlazyloading-lg-height=&quot;300&quot;
/&gt;</pre></code>
</div>
<div class="col-md-6">
<h2>JavaScript</h2>
<pre><code class="javascript">$('#yourImg').bttrlazyloading();</pre></code>
</div>
</div>
<div class="alert alert-info text-center"><b>OR</b></div>
<div class="row">
<div class="col-md-6">
<h2>HTML</h2>
<pre><code class="html">&lt;img id=&quot;yourImg&quot; class=&quot;bttrlazyloading&quot; /&gt;</pre></code>
</div>
<div class="col-md-6">
<h2>JavaScript</h2>
<pre><code class="javascript">$('#yourImg').bttrlazyloading({
xs: {
src: 'http://placekitten.com/800/300',
width: 800,
height: 300
},
sm: {
src: 'http://placekitten.com/380/380',
width: 380,
height: 380
},
md: {
src: 'http://placekitten.com/350/350',
width: 350,
height: 350
},
lg: {
src: 'http://placekitten.com/300/300',
width: 300,
height: 300
}
});</pre></code>
</div>
</div>

<div class="page-header">
<h2>Demo</h2>
</div>
<div class="row" id="loading-area"></div>
<div class="page-header">
<h2>Mode Demos</h2>
</div>
<?php include 'more-demo.php'; ?>
</div>
<?php include '../menu.php'; ?>
<script type="text/javascript">
$(function($, hljs) {
$('#back-to-top').click(function(event) {
$.smoothScroll({
scrollTarget: 'body'
});
});
hljs.initHighlightingOnLoad();

/* DEMO */
$('.bttrlazyloading').bttrlazyloading()
for (var i = 0; i < 32; i++)
{
var $wrapper = $('<div class=" col-sm-6 col-md-4 col-lg-3">');
var $img = $('<img class="bttrlazyloading">');
$wrapper.append($img);
$('#loading-area').append($wrapper);
$img.bttrlazyloading({
delay: 1000,
xs: {
src: 'img/800x300.jpg',
width: 800,
height: 300
},
sm: {
src: 'img/380x380.jpg',
width: 380,
height: 380
},
md: {
src: 'img/350x350.jpg',
width: 350,
height: 350
},
lg: {
src: 'img/300x300.jpg',
width: 300,
height: 300
}
});
}
}(jQuery, hljs));
</script>
</body>
</html>
Loading

0 comments on commit 42d2a38

Please sign in to comment.