Skip to content

Commit 063633e

Browse files
committed
Correct content selector pagination bug
1 parent e0a9b3b commit 063633e

File tree

2 files changed

+50
-48
lines changed

2 files changed

+50
-48
lines changed

system/application/views/widgets/edit/jquery.content_selector.js

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -679,32 +679,33 @@ isMac = navigator.userAgent.indexOf('Mac OS X') != -1;
679679
modal_height();
680680
if (opts.pagination) { // Endless scroll pagination
681681
$tbody.find('.loadmore').remove();
682-
if (!opts.data.length) return;
683-
var $loadmore = $('<tr><td class="loadmore" colspan="'+($this.find('th').length)+'">Loading more content ...</td></tr>').appendTo($tbody);
684-
$loadmore.appendTo($tbody);
685-
$loadmore.hide();
686-
$this.find('.content').scroll(function() {
687-
if ($loadmore.find('td').hasClass('loading')) return;
688-
$loadmore.show();
689-
var $this = $(this);
690-
if ($this.innerHeight() + $this.scrollTop() < $this[0].scrollHeight) return;
691-
$loadmore.find('td').addClass('loading');
692-
opts.start = opts.start + opts.results_per_page;
693-
go();
694-
});
682+
if (opts.data.length) {
683+
var $loadmore = $('<tr><td class="loadmore" colspan="'+($this.find('th').length)+'">Loading more content ...</td></tr>').appendTo($tbody);
684+
$loadmore.appendTo($tbody);
685+
$loadmore.hide();
686+
$this.find('.content').unbind('scroll').scroll(function() {
687+
if ($loadmore.find('td').hasClass('loading')) return;
688+
$loadmore.show();
689+
var $this = $(this);
690+
if (Math.ceil($this.innerHeight() + $this.scrollTop()) < Math.floor($this[0].scrollHeight)) return;
691+
$loadmore.find('td').addClass('loading');
692+
opts.start = opts.start + opts.results_per_page;
693+
go();
694+
});
695+
};
695696
};
696-
$this.find('tr').find('a').click(function(event) { // Preview|Visit button
697+
$this.find('tr').find('a').unbind('click').click(function(event) { // Preview|Visit button
697698
event.stopPropagation();
698699
return true;
699700
});
700-
$this.find('tr').find('input[type="checkbox"]').click(function(event) { // Clicking a <tr> checks the checkbox; this allows it to work properly if checkbox itself is checked
701+
$this.find('tr').find('input[type="checkbox"]').unbind('click').click(function(event) { // Clicking a <tr> checks the checkbox; this allows it to work properly if checkbox itself is checked
701702
var $this = $(this);
702703
var checked = $this.is(":checked");
703704
$this.prop('checked', ((checked)?false:true));
704705
return true;
705706
});
706707
if (!opts.multiple) { // Select a single row
707-
$this.find('tr').click(function() {
708+
$this.find('tr').unbind('click').click(function() {
708709
var node = $(this).data('node');
709710
if ($(this).closest('.content_selector_bootbox').length) {
710711
$(this).closest('.content_selector_bootbox').modal( 'hide' ).data( 'bs.modal', null );
@@ -716,7 +717,7 @@ isMac = navigator.userAgent.indexOf('Mac OS X') != -1;
716717
$('.tt').remove();
717718
});
718719
} else { // Select multiple rows
719-
$this.find('tr').click(function() {
720+
$this.find('tr').unbind('click').click(function() {
720721
var $this = $(this);
721722
var checked = $this.find('input[type="checkbox"]').is(":checked");
722723
$(this).find('input[type="checkbox"]').prop('checked', ((checked)?false:true));
@@ -729,7 +730,7 @@ isMac = navigator.userAgent.indexOf('Mac OS X') != -1;
729730
}
730731
});
731732
}
732-
$('.thumb').parent().mouseover(function() { // Expand thumbnail
733+
$('.thumb').parent().unbind('mouseover').mouseover(function() { // Expand thumbnail
733734
var $this = $(this).children('.thumb:first');
734735
var offset = $this.offset();
735736
var $div = $('<div class="tt"></div>');
@@ -741,7 +742,7 @@ isMac = navigator.userAgent.indexOf('Mac OS X') != -1;
741742
$div.remove();
742743
});
743744
});
744-
$('.anno').parent().mouseover(function() { // Show item that is annotated
745+
$('.anno').parent().unbind('mouseover').mouseover(function() { // Show item that is annotated
745746
var $this = $(this).children('.anno:first');
746747
var str = '<i>Could not find target of this annotation</i>';
747748
var targets = $this.closest('tr').data('node').targets;
@@ -759,7 +760,7 @@ isMac = navigator.userAgent.indexOf('Mac OS X') != -1;
759760
$div.remove();
760761
});
761762
});
762-
$loadmore.hide();
763+
if ('undefined'!=typeof($loadmore)) $loadmore.hide();
763764
};
764765
var go = function() {
765766
opts.data = [];

system/application/views/widgets/edit/jquery.content_selector_bootstrap.js

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -568,16 +568,16 @@ isMac = navigator.userAgent.indexOf('Mac OS X') != -1;
568568
});
569569
if (opts.multiple) { // Can choose multiple rows
570570
$footer.show();
571-
$footer.find('label:first').show(); // Check all
572-
$footer.find('input[type="checkbox"]:first').click(function() {
573-
var active = $(this).data('active');
574-
$wrapper.find('input[type="checkbox"]').each(function() {
575-
var $this = $(this);
576-
if (active && $this.is(':checked')) $this.closest('tr').click();
571+
$footer.find('label:first').show(); // Check all
572+
$footer.find('input[type="checkbox"]:first').click(function() {
573+
var active = $(this).data('active');
574+
$wrapper.find('input[type="checkbox"]').each(function() {
575+
var $this = $(this);
576+
if (active && $this.is(':checked')) $this.closest('tr').click();
577577
if (!active && !$this.is(':checked')) $this.closest('tr').click();
578578
});
579-
$(this).data('active', ((active)?false:true));
580-
});
579+
$(this).data('active', ((active)?false:true));
580+
});
581581
$footer.find('a').eq(1).click(function() { // Cancel button
582582
if ($(this).closest('.content_selector_bootbox').length) {
583583
$(this).closest('.content_selector_bootbox').modal( 'hide' ).data( 'bs.modal', null );
@@ -655,32 +655,33 @@ isMac = navigator.userAgent.indexOf('Mac OS X') != -1;
655655
modal_height();
656656
if (opts.pagination) { // Endless scroll pagination
657657
$tbody.find('.loadmore').remove();
658-
if (!opts.data.length) return;
659-
var $loadmore = $('<tr><td class="loadmore" colspan="'+($this.find('th').length)+'">Loading more content ...</td></tr>').appendTo($tbody);
660-
$loadmore.appendTo($tbody);
661-
$loadmore.hide();
662-
$this.find('.content').unbind('scroll').scroll(function() {
663-
if ($loadmore.find('td').hasClass('loading')) return;
664-
$loadmore.show();
665-
var $this = $(this);
666-
if ($this.innerHeight() + $this.scrollTop() < $this[0].scrollHeight) return;
667-
$loadmore.find('td').addClass('loading');
668-
opts.start = opts.start + opts.results_per_page;
669-
go();
670-
});
658+
if (opts.data.length) {
659+
var $loadmore = $('<tr><td class="loadmore" colspan="'+($this.find('th').length)+'">Loading more content ...</td></tr>').appendTo($tbody);
660+
$loadmore.appendTo($tbody);
661+
$loadmore.hide();
662+
$this.find('.content').unbind('scroll').scroll(function() {
663+
if ($loadmore.find('td').hasClass('loading')) return;
664+
$loadmore.show();
665+
var $this = $(this);
666+
if ($this.innerHeight() + $this.scrollTop() < $this[0].scrollHeight) return;
667+
$loadmore.find('td').addClass('loading');
668+
opts.start = opts.start + opts.results_per_page;
669+
go();
670+
});
671+
};
671672
};
672-
$this.find('tr').find('a').click(function(event) { // Preview|Visit button
673+
$this.find('tr').find('a').unbind('click').click(function(event) { // Preview|Visit button
673674
event.stopPropagation();
674675
return true;
675676
});
676-
$this.find('tr').find('input[type="checkbox"]').click(function(event) { // Clicking a <tr> checks the checkbox; this allows it to work properly if checkbox itself is checked
677+
$this.find('tr').find('input[type="checkbox"]').unbind('click').click(function(event) { // Clicking a <tr> checks the checkbox; this allows it to work properly if checkbox itself is checked
677678
var $this = $(this);
678679
var checked = $this.is(":checked");
679680
$this.prop('checked', ((checked)?false:true));
680681
return true;
681682
});
682683
if (!opts.multiple) { // Select a single row
683-
$this.find('tr').click(function() {
684+
$this.find('tr').unbind('click').click(function() {
684685
var node = $(this).data('node');
685686
if ($(this).closest('.content_selector_bootbox').length) {
686687
$(this).closest('.content_selector_bootbox').modal( 'hide' ).data( 'bs.modal', null );
@@ -692,7 +693,7 @@ isMac = navigator.userAgent.indexOf('Mac OS X') != -1;
692693
$('.tt').remove();
693694
});
694695
} else { // Select multiple rows
695-
$this.find('tr').click(function() {
696+
$this.find('tr').unbind('click').click(function() {
696697
var $this = $(this);
697698
var checked = $this.find('input[type="checkbox"]').is(":checked");
698699
$(this).find('input[type="checkbox"]').prop('checked', ((checked)?false:true));
@@ -705,7 +706,7 @@ isMac = navigator.userAgent.indexOf('Mac OS X') != -1;
705706
}
706707
});
707708
}
708-
$('.thumb').parent().mouseover(function() { // Expand thumbnail
709+
$('.thumb').parent().unbind('mouseover').mouseover(function() { // Expand thumbnail
709710
var $this = $(this).children('.thumb:first');
710711
var offset = $this.offset();
711712
var $div = $('<div class="tt"></div>');
@@ -717,7 +718,7 @@ isMac = navigator.userAgent.indexOf('Mac OS X') != -1;
717718
$div.remove();
718719
});
719720
});
720-
$('.anno').parent().mouseover(function() { // Show item that is annotated
721+
$('.anno').parent().unbind('mouseover').mouseover(function() { // Show item that is annotated
721722
var $this = $(this).children('.anno:first');
722723
var str = '<i>Could not find target of this annotation</i>';
723724
var targets = $this.closest('tr').data('node').targets;
@@ -735,7 +736,7 @@ isMac = navigator.userAgent.indexOf('Mac OS X') != -1;
735736
$div.remove();
736737
});
737738
});
738-
$loadmore.hide();
739+
if ('undefined'!=typeof($loadmore)) $loadmore.hide();
739740
};
740741
var go = function() {
741742
opts.data = [];

0 commit comments

Comments
 (0)