Skip to content

Commit

Permalink
Issue #271 Added support for existing behaviors
Browse files Browse the repository at this point in the history
  • Loading branch information
67726e committed Dec 5, 2012
1 parent faba1b3 commit c950fb6
Show file tree
Hide file tree
Showing 11 changed files with 173 additions and 126 deletions.
15 changes: 7 additions & 8 deletions behaviors/cufon.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@
+ Documentation: http://infinite-scroll.com/
*/

$.extend($.infinitescroll.prototype,{

_callback_cufon: function infscr_callback_cufon(newElements) {
Cufon.refresh(newElements);
}

});
(function ($, undefined) {
$.extend($.infinitescroll.prototype,{
_callback_cufon: function infscr_callback_cufon(newElements) {
Cufon.refresh(newElements);
}
});
})(jQuery);
86 changes: 44 additions & 42 deletions behaviors/manual-trigger.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,48 +12,50 @@
*/

$.extend($.infinitescroll.prototype,{

_setup_twitter: function infscr_setup_twitter () {
var opts = this.options,
instance = this;

// Bind nextSelector link to retrieve
$(opts.nextSelector).click(function(e) {
if (e.which == 1 && !e.metaKey && !e.shiftKey) {
e.preventDefault();
instance.retrieve();
(function($, undefined) {
$.extend($.infinitescroll.prototype,{

_setup_twitter: function infscr_setup_twitter () {
var opts = this.options,
instance = this;

// Bind nextSelector link to retrieve
$(opts.nextSelector).click(function(e) {
if (e.which == 1 && !e.metaKey && !e.shiftKey) {
e.preventDefault();
instance.retrieve();
}
});

// Define loadingStart to never hide pager
instance.options.loading.start = function (opts) {
opts.loading.msg
.appendTo(opts.loading.selector)
.show(opts.loading.speed, function () {
instance.beginAjax(opts);
});
}
});

// Define loadingStart to never hide pager
instance.options.loading.start = function (opts) {
},
_showdonemsg_twitter: function infscr_showdonemsg_twitter () {
var opts = this.options,
instance = this;

//Do all the usual stuff
opts.loading.msg
.appendTo(opts.loading.selector)
.show(opts.loading.speed, function () {
instance.beginAjax(opts);
});
.find('img')
.hide()
.parent()
.find('div').html(opts.loading.finishedMsg).animate({ opacity: 1 }, 2000, function () {
$(this).parent().fadeOut('normal');
});

//And also hide the navSelector
$(opts.navSelector).fadeOut('normal');

// user provided callback when done
opts.errorCallback.call($(opts.contentSelector)[0],'done');

}
},
_showdonemsg_twitter: function infscr_showdonemsg_twitter () {
var opts = this.options,
instance = this;

//Do all the usual stuff
opts.loading.msg
.find('img')
.hide()
.parent()
.find('div').html(opts.loading.finishedMsg).animate({ opacity: 1 }, 2000, function () {
$(this).parent().fadeOut('normal');
});

//And also hide the navSelector
$(opts.navSelector).fadeOut('normal');

// user provided callback when done
opts.errorCallback.call($(opts.contentSelector)[0],'done');

}

});

});
})(jQuery);
14 changes: 7 additions & 7 deletions behaviors/masonry-isotope.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
*/

$.extend($.infinitescroll.prototype,{

_callback_masonry: function infscr_callback_masonry (newElements) {
$(this).masonry('appended',$(newElements));
}

});
(function($, undefined) {
$.extend($.infinitescroll.prototype,{
_callback_masonry: function infscr_callback_masonry (newElements) {
$(this).masonry('appended',$(newElements));
}
});
})(jQuery);
10 changes: 5 additions & 5 deletions behaviors/sausage.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
*/

$.extend($.infinitescroll.prototype,{



});
(function($, undefined) {
$.extend($.infinitescroll.prototype,{
// TODO: Implement
});
})(jQuery);
15 changes: 7 additions & 8 deletions wordpress-plugin/behaviors/cufon.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@
+ Documentation: http://infinite-scroll.com/
*/

$.extend($.infinitescroll.prototype,{

_callback_cufon: function infscr_callback_cufon(newElements) {
Cufon.refresh(newElements);
}

});
(function ($, undefined) {
$.extend($.infinitescroll.prototype,{
_callback_cufon: function infscr_callback_cufon(newElements) {
Cufon.refresh(newElements);
}
});
})(jQuery);
86 changes: 44 additions & 42 deletions wordpress-plugin/behaviors/manual-trigger.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,48 +12,50 @@
*/

$.extend($.infinitescroll.prototype,{

_setup_twitter: function infscr_setup_twitter () {
var opts = this.options,
instance = this;

// Bind nextSelector link to retrieve
$(opts.nextSelector).click(function(e) {
if (e.which == 1 && !e.metaKey && !e.shiftKey) {
e.preventDefault();
instance.retrieve();
(function($, undefined) {
$.extend($.infinitescroll.prototype,{

_setup_twitter: function infscr_setup_twitter () {
var opts = this.options,
instance = this;

// Bind nextSelector link to retrieve
$(opts.nextSelector).click(function(e) {
if (e.which == 1 && !e.metaKey && !e.shiftKey) {
e.preventDefault();
instance.retrieve();
}
});

// Define loadingStart to never hide pager
instance.options.loading.start = function (opts) {
opts.loading.msg
.appendTo(opts.loading.selector)
.show(opts.loading.speed, function () {
instance.beginAjax(opts);
});
}
});

// Define loadingStart to never hide pager
instance.options.loading.start = function (opts) {
},
_showdonemsg_twitter: function infscr_showdonemsg_twitter () {
var opts = this.options,
instance = this;

//Do all the usual stuff
opts.loading.msg
.appendTo(opts.loading.selector)
.show(opts.loading.speed, function () {
instance.beginAjax(opts);
});
.find('img')
.hide()
.parent()
.find('div').html(opts.loading.finishedMsg).animate({ opacity: 1 }, 2000, function () {
$(this).parent().fadeOut('normal');
});

//And also hide the navSelector
$(opts.navSelector).fadeOut('normal');

// user provided callback when done
opts.errorCallback.call($(opts.contentSelector)[0],'done');

}
},
_showdonemsg_twitter: function infscr_showdonemsg_twitter () {
var opts = this.options,
instance = this;

//Do all the usual stuff
opts.loading.msg
.find('img')
.hide()
.parent()
.find('div').html(opts.loading.finishedMsg).animate({ opacity: 1 }, 2000, function () {
$(this).parent().fadeOut('normal');
});

//And also hide the navSelector
$(opts.navSelector).fadeOut('normal');

// user provided callback when done
opts.errorCallback.call($(opts.contentSelector)[0],'done');

}

});

});
})(jQuery);
14 changes: 7 additions & 7 deletions wordpress-plugin/behaviors/masonry-isotope.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
*/

$.extend($.infinitescroll.prototype,{

_callback_masonry: function infscr_callback_masonry (newElements) {
$(this).masonry('appended',$(newElements));
}

});
(function($, undefined) {
$.extend($.infinitescroll.prototype,{
_callback_masonry: function infscr_callback_masonry (newElements) {
$(this).masonry('appended',$(newElements));
}
});
})(jQuery);
10 changes: 5 additions & 5 deletions wordpress-plugin/behaviors/sausage.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
*/

$.extend($.infinitescroll.prototype,{



});
(function($, undefined) {
$.extend($.infinitescroll.prototype,{
// TODO: Implement
});
})(jQuery);
17 changes: 16 additions & 1 deletion wordpress-plugin/infinite-scroll.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,26 @@ function enqueue_js() {
$suffix = ( WP_DEBUG ) ? '.dev' : '';

$file = "/js/front-end/jquery.infinitescroll{$suffix}.js";

wp_enqueue_script( $this->slug, plugins_url( $file, __FILE__ ), array( 'jquery' ), $this->version, true );

$options = apply_filters( $this->prefix . 'js_options', $this->options->get_options() );
wp_localize_script( $this->slug, $this->slug_, $options );

// Output a behavior script if needed
if ($options["behavior"]) {
$scripts["twitter"] = "manual-trigger.js";
$scripts["local"] = "local.js";
$scripts["cufon"] = "cufon.js";
$scripts["masonry"] = "masonry-isotope.js";

$behaviorFile = $scripts[$options["behavior"]];

if ($behaviorFile) {
$behaviorFile = "/behaviors/" . $behaviorFile;
wp_enqueue_script($this->slug . "-behavior", plugins_url($behaviorFile, __FILE__),
array("jquery", $this->slug), $this->version, true);
}
}
}

/**
Expand Down
6 changes: 5 additions & 1 deletion wordpress-plugin/languages/infinite-scroll.pot
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,11 @@ msgstr ""
msgid "URL of existing or uploaded image to display as new posts are retrieved"
msgstr ""

#:templates/options.php
#: templates/options.php
mgsid "Behavior"
msgstr ""

#: templates/options.php
mgsid "Debug"
msgstr ""

Expand Down
26 changes: 26 additions & 0 deletions wordpress-plugin/templates/options.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,32 @@
<span class="description"><?php _e( 'URL of existing or uploaded image to display as new posts are retrieved', 'infinite-scroll' ); ?></span>
</td>
</tr>
<tr valign="top">
<th scope="row">
<?php _e("Behavior", "infinite-scroll") ?>
</th>
<td>

<?php
$behavior = $this->parent->options->behavior;

function isBehavior($value, $behavior) {
if ($value === $behavior) {
print("selected=\"selected\"");
}
}

?>

<select id="infinite_scroll[behavior]" name="infinite_scroll[behavior]">
<option <?php isBehavior("", $behavior); ?> value="">Default</option>
<option <?php isBehavior("twitter", $behavior); ?> value="twitter">Manual Trigger</option>
<option <?php isBehavior("local", $behavior); ?> value="local">Local</option>
<option <?php isBehavior("cufon", $behavior); ?> value="cufon">Cufon</option>
<option <?php isBehavior("masonry", $behavior); ?> value="masonry">Masonry/Isotope</option>
</select>
</td>
</tr>
<tr valign="top">
<th scope="row">
<?php _e("Debug", "infinite-scroll") ?>
Expand Down

0 comments on commit c950fb6

Please sign in to comment.