Skip to content

Commit

Permalink
Add tests & fix bug when 404 returned
Browse files Browse the repository at this point in the history
  • Loading branch information
arief-hidayat committed Apr 18, 2012
1 parent 85cea93 commit 84ee179
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 8 deletions.
9 changes: 4 additions & 5 deletions jquery.infinitescroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@

desturl = path.join(opts.state.currPage);

method = (opts.dataType == 'html' || opts.dataType == 'json') ? opts.dataType : 'html+callback';
method = (opts.dataType == 'html' || opts.dataType == 'json' ) ? opts.dataType : 'html+callback';
if (opts.appendCallback && opts.dataType == 'html') method += '+callback'

switch (method) {
Expand All @@ -526,11 +526,10 @@
});

break;

case 'json':
instance._debug('Using ' + (method.toUpperCase()) + ' via $.ajax() method');
$.ajax({
dataType:'json',
dataType: 'json',
type: 'GET',
url: desturl,
success: function(data, textStatus, jqXHR) {
Expand All @@ -543,7 +542,7 @@
box.append(theData);
(condition) ? instance._loadcallback(box, theData) : instance._error('end');
} else {
this._debug("template must be defined.");
instance._debug("template must be defined.");
instance._error('end');
}
} else {
Expand All @@ -552,7 +551,7 @@
}
},
error: function(jqXHR, textStatus, errorThrown) {
this._debug("JSON ajax request failed.");
instance._debug("JSON ajax request failed.");
instance._error('end');
}
});
Expand Down
108 changes: 108 additions & 0 deletions test/mobile.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<!doctype html>
<!--[if lt IE 7]> <html class="no-js ie6" lang="en"> <![endif]-->
<!--[if IE 7]> <html class="no-js ie7" lang="en"> <![endif]-->
<!--[if IE 8]> <html class="no-js ie8" lang="en"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
<head>

<meta charset="utf-8">

<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

<title>Infinite Scroll Testing</title>
<meta name="description" content="">
<meta name="author" content="">


<link rel="stylesheet" href="style.css">

</head>

<body>

<div id="debug">
<a href="#" id="debug-trigger">+</a>
<h3>Debug bar</h3>
<nav id="debug-nav">
<a href="#" rel="destroy">Destroy</a>
<a href="#" rel="pause">Pause</a>
<a href="#" rel="resume">Resume</a>
<a href="#" rel="toggle">Toggle</a>
<a href="#" rel="scroll">Scroll</a>
<a href="#" rel="unbind">Unbind</span></a>
<a href="#" rel="bind">Bind</span></a>
<a href="#" rel="retrieve">Retrieve</a>
<a href="#" rel="cthullu">Invalid command</a>
<a href="#" rel="pause" data-arg="the-apocalypse">Invalid argument</a>
</nav>
</div>

<div id="content">

<h1>Infinite Scroll Testing</h1>

<p>One for all and all for one, Muskehounds are always ready. One for all and all for one, helping everybody. One for all and all for one, it's a pretty story. Sharing everything with fun, that's the way to be. One for all and all for one, Muskehounds are always ready. One for all and all for one, helping everybody. One for all and all for one, can sound pretty corny. If you've got a problem chum, think how it could be.</p>

<p>Barnaby The Bear's my name, never call me Jack or James, I will sing my way to fame, Barnaby the Bear's my name. Birds taught me to sing, when they took me to their king, first I had to fly, in the sky so high so high, so high so high so high, so - if you want to sing this way, think of what you'd like to say, add a tune and you will see, just how easy it can be. Treacle pudding, fish and chips, fizzy drinks and liquorice, flowers, rivers, sand and sea, snowflakes and the stars are free. La la la la la, la la la la la la la, la la la la la la la, la la la la la la la la la la la la la, so - Barnaby The Bear's my name, never call me Jack or James, I will sing my way to fame, Barnaby the Bear's my name.</p>

<p>There's a voice that keeps on calling me. Down the road, that's where I'll always be. Every stop I make, I make a new friend. Can't stay for long, just turn around and I'm gone again. Maybe tomorrow, I'll want to settle down, Until tomorrow, I'll just keep moving on.</p>

<p>Top Cat! The most effectual Top Cat! Who's intellectual close friends get to call him T.C., providing it's with dignity. Top Cat! The indisputable leader of the gang. He's the boss, he's a pip, he's the championship. He's the most tip top, Top Cat.</p>

<p>Hong Kong Phooey, number one super guy. Hong Kong Phooey, quicker than the human eye. He's got style, a groovy style, and a car that just won't stop. When the going gets tough, he's really rough, with a Hong Kong Phooey chop (Hi-Ya!). Hong Kong Phooey, number one super guy. Hong Kong Phooey, quicker than the human eye. Hong Kong Phooey, he's fan-riffic!</p>

<p>Barnaby The Bear's my name, never call me Jack or James, I will sing my way to fame, Barnaby the Bear's my name. Birds taught me to sing, when they took me to their king, first I had to fly, in the sky so high so high, so high so high so high, so - if you want to sing this way, think of what you'd like to say, add a tune and you will see, just how easy it can be. Treacle pudding, fish and chips, fizzy drinks and liquorice, flowers, rivers, sand and sea, snowflakes and the stars are free. La la la la la, la la la la la la la, la la la la la la la, la la la la la la la la la la la la la, so - Barnaby The Bear's my name, never call me Jack or James, I will sing my way to fame, Barnaby the Bear's my name.</p>

<p>There's a voice that keeps on calling me. Down the road, that's where I'll always be. Every stop I make, I make a new friend. Can't stay for long, just turn around and I'm gone again. Maybe tomorrow, I'll want to settle down, Until tomorrow, I'll just keep moving on.</p>

<p>Top Cat! The most effectual Top Cat! Who's intellectual close friends get to call him T.C., providing it's with dignity. Top Cat! The indisputable leader of the gang. He's the boss, he's a pip, he's the championship. He's the most tip top, Top Cat.</p>

<p>Hong Kong Phooey, number one super guy. Hong Kong Phooey, quicker than the human eye. He's got style, a groovy style, and a car that just won't stop. When the going gets tough, he's really rough, with a Hong Kong Phooey chop (Hi-Ya!). Hong Kong Phooey, number one super guy. Hong Kong Phooey, quicker than the human eye. Hong Kong Phooey, he's fan-riffic!</p>

</div>

<a id="next" href="mobile2.json">next page?</a>

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.js"></script>
<script>window.jQuery || document.write("<script src='jquery-1.6.1.js'>\x3C/script>")</script>

<script src="debug.js"></script>
<script src="../jquery.infinitescroll.js"></script>
<script src="../behaviors/manual-trigger.js"></script>

<script>

var _renderItem = function(data) {
return "<p>Title :" + data.title + "</p>"
}


$('#content').infinitescroll({

// callback : function () { console.log('using opts.callback'); },
navSelector : "a#next:last",
nextSelector : "a#next:last",
itemSelector : "#content p",
debug : true,
dataType : 'json',
// behavior : 'twitter',
appendCallback : false, // USE FOR PREPENDING
// pathParse : function( pathStr, nextPage ){ return pathStr.replace('2', nextPage ); }
}, function( response ) {
var jsonData = response.results;
$theCntr = $("#content");
var newElements = "";
//var newItems = new Array();
for(var i=0;i<jsonData.length;i++) {
var item = $(_renderItem(jsonData[i]));
//item.css({ opacity: 0 });
$theCntr.append(item);
//newItems.push(item.attr('id'));
}
//_addMasonryItem(newItems);
});
</script>


</body>
</html>
2 changes: 1 addition & 1 deletion test/mobile2.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"results":[{"title":"this is the json title"},{"title":"this is another json title"},{"title":"this is the json title"},{"title":"this is another json title"},{"title":"this is the json title"},{"title":"this is another json title"},{"title":"this is the json title"},{"title":"this is another json title"}]}
{"results":[{"title":"2. this is the json title"},{"title":"2. this is another json title"},{"title":"2. this is the json title"},{"title":"2. this is another json title"},{"title":"2. this is the json title"},{"title":"2. this is another json title"},{"title":"2. this is the json title"},{"title":"2. this is another json title"}]}
2 changes: 1 addition & 1 deletion test/mobile3.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"results":[{"title":"this is the json title"},{"title":"this is another json title"},{"title":"this is the json title"},{"title":"this is another json title"},{"title":"this is the json title"},{"title":"this is another json title"},{"title":"this is the json title"},{"title":"this is another json title"}]}
{"results":[{"title":"3. this is the json title"},{"title":"3. this is another json title"},{"title":"3. this is the json title"},{"title":"3. this is another json title"},{"title":"3. this is the json title"},{"title":"3. this is another json title"},{"title":"3. this is the json title"},{"title":"this is another json title"}]}
2 changes: 1 addition & 1 deletion test/mobile4.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"results":[{"title":"this is the json title"},{"title":"this is another json title"},{"title":"this is the json title"},{"title":"this is another json title"},{"title":"this is the json title"},{"title":"this is another json title"},{"title":"this is the json title"},{"title":"this is another json title"}]}
{"results":[{"title":"4. this is the json title"},{"title":"4. this is another json title"},{"title":"4. this is the json title"},{"title":"4. this is another json title"},{"title":"4. this is the json title"},{"title":"4. this is another json title"},{"title":"4. this is the json title"},{"title":"4. this is another json title"}]}

0 comments on commit 84ee179

Please sign in to comment.