Skip to content

Commit c950fb6

Browse files
committedDec 5, 2012
Issue metafizzy#271 Added support for existing behaviors
1 parent faba1b3 commit c950fb6

11 files changed

+173
-126
lines changed
 

‎behaviors/cufon.js

+7-8
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@
1111
+ Documentation: http://infinite-scroll.com/
1212
1313
*/
14-
15-
$.extend($.infinitescroll.prototype,{
16-
17-
_callback_cufon: function infscr_callback_cufon(newElements) {
18-
Cufon.refresh(newElements);
19-
}
20-
21-
});
14+
(function ($, undefined) {
15+
$.extend($.infinitescroll.prototype,{
16+
_callback_cufon: function infscr_callback_cufon(newElements) {
17+
Cufon.refresh(newElements);
18+
}
19+
});
20+
})(jQuery);

‎behaviors/manual-trigger.js

+44-42
Original file line numberDiff line numberDiff line change
@@ -12,48 +12,50 @@
1212
1313
*/
1414

15-
$.extend($.infinitescroll.prototype,{
16-
17-
_setup_twitter: function infscr_setup_twitter () {
18-
var opts = this.options,
19-
instance = this;
20-
21-
// Bind nextSelector link to retrieve
22-
$(opts.nextSelector).click(function(e) {
23-
if (e.which == 1 && !e.metaKey && !e.shiftKey) {
24-
e.preventDefault();
25-
instance.retrieve();
15+
(function($, undefined) {
16+
$.extend($.infinitescroll.prototype,{
17+
18+
_setup_twitter: function infscr_setup_twitter () {
19+
var opts = this.options,
20+
instance = this;
21+
22+
// Bind nextSelector link to retrieve
23+
$(opts.nextSelector).click(function(e) {
24+
if (e.which == 1 && !e.metaKey && !e.shiftKey) {
25+
e.preventDefault();
26+
instance.retrieve();
27+
}
28+
});
29+
30+
// Define loadingStart to never hide pager
31+
instance.options.loading.start = function (opts) {
32+
opts.loading.msg
33+
.appendTo(opts.loading.selector)
34+
.show(opts.loading.speed, function () {
35+
instance.beginAjax(opts);
36+
});
2637
}
27-
});
28-
29-
// Define loadingStart to never hide pager
30-
instance.options.loading.start = function (opts) {
38+
},
39+
_showdonemsg_twitter: function infscr_showdonemsg_twitter () {
40+
var opts = this.options,
41+
instance = this;
42+
43+
//Do all the usual stuff
3144
opts.loading.msg
32-
.appendTo(opts.loading.selector)
33-
.show(opts.loading.speed, function () {
34-
instance.beginAjax(opts);
35-
});
45+
.find('img')
46+
.hide()
47+
.parent()
48+
.find('div').html(opts.loading.finishedMsg).animate({ opacity: 1 }, 2000, function () {
49+
$(this).parent().fadeOut('normal');
50+
});
51+
52+
//And also hide the navSelector
53+
$(opts.navSelector).fadeOut('normal');
54+
55+
// user provided callback when done
56+
opts.errorCallback.call($(opts.contentSelector)[0],'done');
57+
3658
}
37-
},
38-
_showdonemsg_twitter: function infscr_showdonemsg_twitter () {
39-
var opts = this.options,
40-
instance = this;
41-
42-
//Do all the usual stuff
43-
opts.loading.msg
44-
.find('img')
45-
.hide()
46-
.parent()
47-
.find('div').html(opts.loading.finishedMsg).animate({ opacity: 1 }, 2000, function () {
48-
$(this).parent().fadeOut('normal');
49-
});
50-
51-
//And also hide the navSelector
52-
$(opts.navSelector).fadeOut('normal');
53-
54-
// user provided callback when done
55-
opts.errorCallback.call($(opts.contentSelector)[0],'done');
56-
57-
}
58-
59-
});
59+
60+
});
61+
})(jQuery);

‎behaviors/masonry-isotope.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
1313
*/
1414

15-
$.extend($.infinitescroll.prototype,{
16-
17-
_callback_masonry: function infscr_callback_masonry (newElements) {
18-
$(this).masonry('appended',$(newElements));
19-
}
20-
21-
});
15+
(function($, undefined) {
16+
$.extend($.infinitescroll.prototype,{
17+
_callback_masonry: function infscr_callback_masonry (newElements) {
18+
$(this).masonry('appended',$(newElements));
19+
}
20+
});
21+
})(jQuery);

‎behaviors/sausage.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
1313
*/
1414

15-
$.extend($.infinitescroll.prototype,{
16-
17-
18-
19-
});
15+
(function($, undefined) {
16+
$.extend($.infinitescroll.prototype,{
17+
// TODO: Implement
18+
});
19+
})(jQuery);

‎wordpress-plugin/behaviors/cufon.js

+7-8
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@
1111
+ Documentation: http://infinite-scroll.com/
1212
1313
*/
14-
15-
$.extend($.infinitescroll.prototype,{
16-
17-
_callback_cufon: function infscr_callback_cufon(newElements) {
18-
Cufon.refresh(newElements);
19-
}
20-
21-
});
14+
(function ($, undefined) {
15+
$.extend($.infinitescroll.prototype,{
16+
_callback_cufon: function infscr_callback_cufon(newElements) {
17+
Cufon.refresh(newElements);
18+
}
19+
});
20+
})(jQuery);

‎wordpress-plugin/behaviors/manual-trigger.js

+44-42
Original file line numberDiff line numberDiff line change
@@ -12,48 +12,50 @@
1212
1313
*/
1414

15-
$.extend($.infinitescroll.prototype,{
16-
17-
_setup_twitter: function infscr_setup_twitter () {
18-
var opts = this.options,
19-
instance = this;
20-
21-
// Bind nextSelector link to retrieve
22-
$(opts.nextSelector).click(function(e) {
23-
if (e.which == 1 && !e.metaKey && !e.shiftKey) {
24-
e.preventDefault();
25-
instance.retrieve();
15+
(function($, undefined) {
16+
$.extend($.infinitescroll.prototype,{
17+
18+
_setup_twitter: function infscr_setup_twitter () {
19+
var opts = this.options,
20+
instance = this;
21+
22+
// Bind nextSelector link to retrieve
23+
$(opts.nextSelector).click(function(e) {
24+
if (e.which == 1 && !e.metaKey && !e.shiftKey) {
25+
e.preventDefault();
26+
instance.retrieve();
27+
}
28+
});
29+
30+
// Define loadingStart to never hide pager
31+
instance.options.loading.start = function (opts) {
32+
opts.loading.msg
33+
.appendTo(opts.loading.selector)
34+
.show(opts.loading.speed, function () {
35+
instance.beginAjax(opts);
36+
});
2637
}
27-
});
28-
29-
// Define loadingStart to never hide pager
30-
instance.options.loading.start = function (opts) {
38+
},
39+
_showdonemsg_twitter: function infscr_showdonemsg_twitter () {
40+
var opts = this.options,
41+
instance = this;
42+
43+
//Do all the usual stuff
3144
opts.loading.msg
32-
.appendTo(opts.loading.selector)
33-
.show(opts.loading.speed, function () {
34-
instance.beginAjax(opts);
35-
});
45+
.find('img')
46+
.hide()
47+
.parent()
48+
.find('div').html(opts.loading.finishedMsg).animate({ opacity: 1 }, 2000, function () {
49+
$(this).parent().fadeOut('normal');
50+
});
51+
52+
//And also hide the navSelector
53+
$(opts.navSelector).fadeOut('normal');
54+
55+
// user provided callback when done
56+
opts.errorCallback.call($(opts.contentSelector)[0],'done');
57+
3658
}
37-
},
38-
_showdonemsg_twitter: function infscr_showdonemsg_twitter () {
39-
var opts = this.options,
40-
instance = this;
41-
42-
//Do all the usual stuff
43-
opts.loading.msg
44-
.find('img')
45-
.hide()
46-
.parent()
47-
.find('div').html(opts.loading.finishedMsg).animate({ opacity: 1 }, 2000, function () {
48-
$(this).parent().fadeOut('normal');
49-
});
50-
51-
//And also hide the navSelector
52-
$(opts.navSelector).fadeOut('normal');
53-
54-
// user provided callback when done
55-
opts.errorCallback.call($(opts.contentSelector)[0],'done');
56-
57-
}
58-
59-
});
59+
60+
});
61+
})(jQuery);

‎wordpress-plugin/behaviors/masonry-isotope.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
1313
*/
1414

15-
$.extend($.infinitescroll.prototype,{
16-
17-
_callback_masonry: function infscr_callback_masonry (newElements) {
18-
$(this).masonry('appended',$(newElements));
19-
}
20-
21-
});
15+
(function($, undefined) {
16+
$.extend($.infinitescroll.prototype,{
17+
_callback_masonry: function infscr_callback_masonry (newElements) {
18+
$(this).masonry('appended',$(newElements));
19+
}
20+
});
21+
})(jQuery);

‎wordpress-plugin/behaviors/sausage.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
1313
*/
1414

15-
$.extend($.infinitescroll.prototype,{
16-
17-
18-
19-
});
15+
(function($, undefined) {
16+
$.extend($.infinitescroll.prototype,{
17+
// TODO: Implement
18+
});
19+
})(jQuery);

‎wordpress-plugin/infinite-scroll.php

+16-1
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,26 @@ function enqueue_js() {
117117
$suffix = ( WP_DEBUG ) ? '.dev' : '';
118118

119119
$file = "/js/front-end/jquery.infinitescroll{$suffix}.js";
120-
121120
wp_enqueue_script( $this->slug, plugins_url( $file, __FILE__ ), array( 'jquery' ), $this->version, true );
122121

123122
$options = apply_filters( $this->prefix . 'js_options', $this->options->get_options() );
124123
wp_localize_script( $this->slug, $this->slug_, $options );
124+
125+
// Output a behavior script if needed
126+
if ($options["behavior"]) {
127+
$scripts["twitter"] = "manual-trigger.js";
128+
$scripts["local"] = "local.js";
129+
$scripts["cufon"] = "cufon.js";
130+
$scripts["masonry"] = "masonry-isotope.js";
131+
132+
$behaviorFile = $scripts[$options["behavior"]];
133+
134+
if ($behaviorFile) {
135+
$behaviorFile = "/behaviors/" . $behaviorFile;
136+
wp_enqueue_script($this->slug . "-behavior", plugins_url($behaviorFile, __FILE__),
137+
array("jquery", $this->slug), $this->version, true);
138+
}
139+
}
125140
}
126141

127142
/**

‎wordpress-plugin/languages/infinite-scroll.pot

+5-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,11 @@ msgstr ""
150150
msgid "URL of existing or uploaded image to display as new posts are retrieved"
151151
msgstr ""
152152

153-
#:templates/options.php
153+
#: templates/options.php
154+
mgsid "Behavior"
155+
msgstr ""
156+
157+
#: templates/options.php
154158
mgsid "Debug"
155159
msgstr ""
156160

‎wordpress-plugin/templates/options.php

+26
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,32 @@
9797
<span class="description"><?php _e( 'URL of existing or uploaded image to display as new posts are retrieved', 'infinite-scroll' ); ?></span>
9898
</td>
9999
</tr>
100+
<tr valign="top">
101+
<th scope="row">
102+
<?php _e("Behavior", "infinite-scroll") ?>
103+
</th>
104+
<td>
105+
106+
<?php
107+
$behavior = $this->parent->options->behavior;
108+
109+
function isBehavior($value, $behavior) {
110+
if ($value === $behavior) {
111+
print("selected=\"selected\"");
112+
}
113+
}
114+
115+
?>
116+
117+
<select id="infinite_scroll[behavior]" name="infinite_scroll[behavior]">
118+
<option <?php isBehavior("", $behavior); ?> value="">Default</option>
119+
<option <?php isBehavior("twitter", $behavior); ?> value="twitter">Manual Trigger</option>
120+
<option <?php isBehavior("local", $behavior); ?> value="local">Local</option>
121+
<option <?php isBehavior("cufon", $behavior); ?> value="cufon">Cufon</option>
122+
<option <?php isBehavior("masonry", $behavior); ?> value="masonry">Masonry/Isotope</option>
123+
</select>
124+
</td>
125+
</tr>
100126
<tr valign="top">
101127
<th scope="row">
102128
<?php _e("Debug", "infinite-scroll") ?>

0 commit comments

Comments
 (0)
Please sign in to comment.