Document Gallery - Version 4.4.3

Version Description

  • Bug Fix: The pagination logic was not working correctly, resulting in the gallery not returning to the top after changing to a new page in some situations.
Download this release

Release Info

Developer dan.rossiter
Plugin Icon 128x128 Document Gallery
Version 4.4.3
Comparing to
See all releases

Code changes from version 4.4.2 to 4.4.3

CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
  # Changelog
2
 
 
 
 
 
3
  ## 4.4.2
4
  * **Enhancement:** When pagination is enabled for a gallery, navigating to another page will now scroll the page
5
  back to the top of the gallery.
1
  # Changelog
2
 
3
+ ## 4.4.3
4
+ * **Bug Fix:** The pagination logic was not working correctly, resulting in the gallery not returning to the
5
+ top after changing to a new page in some situations.
6
+
7
  ## 4.4.2
8
  * **Enhancement:** When pagination is enabled for a gallery, navigating to another page will now scroll the page
9
  back to the top of the gallery.
README.txt CHANGED
@@ -4,7 +4,7 @@ Tags: attachments, library, thumbnail, documents, gallery, word, pdf
4
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=EE5LWRLG933EN&lc=US&item_name=Document%20Gallery%20Plugin&item_number=document%2dgallery&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted
5
  Requires at least: 4.2
6
  Tested up to: 4.8
7
- Stable tag: 4.4.2
8
  License: GPLv3
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
@@ -470,6 +470,10 @@ To see a list of features planned for the future as well as to propose your own
470
  ideas for future Document Gallery development, take a look at our
471
  [issue tracker](https://github.com/thenadz/document-gallery/issues).
472
 
 
 
 
 
473
  = 4.4.2 =
474
  * **Enhancement:** When pagination is enabled for a gallery, navigating to another page will now scroll the page
475
  back to the top of the gallery.
4
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=EE5LWRLG933EN&lc=US&item_name=Document%20Gallery%20Plugin&item_number=document%2dgallery&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted
5
  Requires at least: 4.2
6
  Tested up to: 4.8
7
+ Stable tag: 4.4.3
8
  License: GPLv3
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
470
  ideas for future Document Gallery development, take a look at our
471
  [issue tracker](https://github.com/thenadz/document-gallery/issues).
472
 
473
+ = 4.4.3 =
474
+ * **Bug Fix:** The pagination logic was not working correctly, resulting in the gallery not returning to the
475
+ top after changing to a new page in some situations.
476
+
477
  = 4.4.2 =
478
  * **Enhancement:** When pagination is enabled for a gallery, navigating to another page will now scroll the page
479
  back to the top of the gallery.
assets/js/gallery.js CHANGED
@@ -26,10 +26,10 @@
26
 
27
  /**
28
  * Sets the size of the gallery icons based on the column count.
29
- * @param gallery If given, the target gallery. Otherwise all galleries on page.
30
  */
31
- function sizeGalleryIcons(gallery) {
32
- (gallery || $('.document-gallery[data-icon-width]')).each(function() {
33
  var icon_width = $(this).data('icon-width');
34
  if (typeof icon_width !== 'undefined') {
35
  $(this).find('.document-icon').width(icon_width + '%');
@@ -57,15 +57,15 @@
57
  */
58
  function registerPaginationHandler() {
59
  $('body').delegate('.dg-paginate-wrapper .paginate a', 'click', function (e) {
60
- var target = $(this).closest('.dg-paginate-wrapper');
61
- var atts = target.data('shortcode');
62
  atts['skip'] = 0;
63
  var split = $(this).attr('href').split('#')[1].split('=');
64
  if ( split.length >= 2 ) {
65
  atts['skip'] = atts['limit'] * (split.pop() - 1);
66
  }
67
 
68
- retrieveGallery(atts, target, function (gallery) {
69
  var adminBarHeight = $('#wpadminbar').height() || 0;
70
  var targetTop = gallery.offset().top - adminBarHeight;
71
 
@@ -104,10 +104,10 @@
104
  /**
105
  * Requests a gallery generated with the given attributes to populate the given target element.
106
  * @param atts array The gallery shortcode attributes.
107
- * @param target element The element to be updated with the AJAX HTML response.
108
  * @param callback function If provided, will be invoked once new gallery content is loaded with the updated element passed in.
109
  */
110
- function retrieveGallery(atts, target, callback) {
111
  // TODO: Cache already-retrieved gallery pages. Need to be careful not to keep too many at a time
112
  // (could consume a lot of memory) & handle caching pages for multiple galleries on a single pages.
113
  if ( typeof atts['id'] === 'undefined' ) {
@@ -116,21 +116,26 @@
116
 
117
  // request new gallery page from server
118
  $.post(ajaxurl, { action: 'dg_generate_gallery', atts: atts }, function(html) {
119
- var parsedHtml = $($.parseHTML(html));
120
- if ( is_editor && !thumber_pointer_shown && parsedHtml.find(thumber_exts_sel).length ) {
121
  thumber_pointer_shown = true;
122
  $('#insert-media-button').trigger('ready.dg');
123
  }
124
 
 
 
 
 
125
  // update gallery element with new content
126
- target.replaceWith(parsedHtml);
127
- sizeGalleryIcons(parsedHtml);
 
128
  resetPendingIcons();
129
 
130
  // invoke callback if provided
131
  if ( typeof callback !== 'undefined' ) {
132
  // get the new DOM element
133
- callback($('#' + target.attr('id')));
134
  }
135
  });
136
  }
@@ -173,16 +178,16 @@
173
  function processRetrievedThumbnails(response) {
174
  for (var id in response) {
175
  if (response.hasOwnProperty(id)) {
176
- var target = $('.document-gallery img[data-id="' + id + '"]');
177
- target.removeAttr('data-id');
178
 
179
- (function(id, target) {
180
  var speed = 'fast';
181
- target.fadeOut(speed, function () {
182
  $(this).attr('src', response[id]);
183
  $(this).fadeIn(speed);
184
  });
185
- })(id, target);
186
  }
187
  }
188
 
26
 
27
  /**
28
  * Sets the size of the gallery icons based on the column count.
29
+ * @param $gallery If given, the target gallery. Otherwise all galleries on page.
30
  */
31
+ function sizeGalleryIcons($gallery) {
32
+ ($gallery || $('.document-gallery[data-icon-width]')).each(function() {
33
  var icon_width = $(this).data('icon-width');
34
  if (typeof icon_width !== 'undefined') {
35
  $(this).find('.document-icon').width(icon_width + '%');
57
  */
58
  function registerPaginationHandler() {
59
  $('body').delegate('.dg-paginate-wrapper .paginate a', 'click', function (e) {
60
+ var $target = $(this).closest('.dg-paginate-wrapper');
61
+ var atts = $target.data('shortcode');
62
  atts['skip'] = 0;
63
  var split = $(this).attr('href').split('#')[1].split('=');
64
  if ( split.length >= 2 ) {
65
  atts['skip'] = atts['limit'] * (split.pop() - 1);
66
  }
67
 
68
+ retrieveGallery(atts, $target, function (gallery) {
69
  var adminBarHeight = $('#wpadminbar').height() || 0;
70
  var targetTop = gallery.offset().top - adminBarHeight;
71
 
104
  /**
105
  * Requests a gallery generated with the given attributes to populate the given target element.
106
  * @param atts array The gallery shortcode attributes.
107
+ * @param $target element The element to be updated with the AJAX HTML response.
108
  * @param callback function If provided, will be invoked once new gallery content is loaded with the updated element passed in.
109
  */
110
+ function retrieveGallery(atts, $target, callback) {
111
  // TODO: Cache already-retrieved gallery pages. Need to be careful not to keep too many at a time
112
  // (could consume a lot of memory) & handle caching pages for multiple galleries on a single pages.
113
  if ( typeof atts['id'] === 'undefined' ) {
116
 
117
  // request new gallery page from server
118
  $.post(ajaxurl, { action: 'dg_generate_gallery', atts: atts }, function(html) {
119
+ var $parsedHtml = $($.parseHTML(html));
120
+ if (is_editor && !thumber_pointer_shown && $parsedHtml.find(thumber_exts_sel).length) {
121
  thumber_pointer_shown = true;
122
  $('#insert-media-button').trigger('ready.dg');
123
  }
124
 
125
+ // keep old ID
126
+ var targetId = $target.attr('id');
127
+ $parsedHtml.attr('id', targetId);
128
+
129
  // update gallery element with new content
130
+ $target.replaceWith($parsedHtml);
131
+ $target = $('#' + targetId);
132
+ sizeGalleryIcons($target);
133
  resetPendingIcons();
134
 
135
  // invoke callback if provided
136
  if ( typeof callback !== 'undefined' ) {
137
  // get the new DOM element
138
+ callback($target);
139
  }
140
  });
141
  }
178
  function processRetrievedThumbnails(response) {
179
  for (var id in response) {
180
  if (response.hasOwnProperty(id)) {
181
+ var $target = $('.document-gallery img[data-id="' + id + '"]');
182
+ $target.removeAttr('data-id');
183
 
184
+ (function(id, $target) {
185
  var speed = 'fast';
186
+ $target.fadeOut(speed, function () {
187
  $(this).attr('src', response[id]);
188
  $(this).fadeIn(speed);
189
  });
190
+ })(id, $target);
191
  }
192
  }
193
 
assets/js/gallery.min.js CHANGED
@@ -2,6 +2,6 @@ var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.findInternal=function(a,d,c){a
2
  $jscomp.global=$jscomp.getGlobal(this);$jscomp.polyfill=function(a,d,c,f){if(d){c=$jscomp.global;a=a.split(".");for(f=0;f<a.length-1;f++){var e=a[f];e in c||(c[e]={});c=c[e]}a=a[a.length-1];f=c[a];d=d(f);d!=f&&null!=d&&$jscomp.defineProperty(c,a,{configurable:!0,writable:!0,value:d})}};$jscomp.polyfill("Array.prototype.find",function(a){return a?a:function(a,c){return $jscomp.findInternal(this,a,c).v}},"es6-impl","es3");
3
  (function(a){function d(b){(b||a(".document-gallery[data-icon-width]")).each(function(){var b=a(this).data("icon-width");"undefined"!==typeof b&&a(this).find(".document-icon").width(b+"%")})}function c(){l&&tinymce.PluginManager.add("dg",function(b,c){b.on("LoadContent update.dg undo",function(b){a(b.target.contentDocument).find('[data-wpview-type="dg"] [data-shortcode]').each(function(){g("object"===typeof a(this).data("shortcode")?a(this).data("shortcode"):JSON.parse(decodeURIComponent(a(this).data("shortcode"))),
4
  a(this))})})})}function f(){a("body").delegate(".dg-paginate-wrapper .paginate a","click",function(b){var c=a(this).closest(".dg-paginate-wrapper"),d=c.data("shortcode");d.skip=0;var e=a(this).attr("href").split("#")[1].split("=");2<=e.length&&(d.skip=d.limit*(e.pop()-1));g(d,c,function(b){var c=a("#wpadminbar").height()||0;b=b.offset().top-c;a(document).scrollTop()>b&&a("html, body").animate({scrollTop:b-20},"slow")});b.preventDefault()})}function e(){h=[];k=0;a(".document-gallery img[data-id]").each(function(){var b=
5
- a(this).data("id");-1===a.inArray(b,h)&&h.push(b)});m()}function g(b,c,f){"undefined"===typeof b.id&&(b.id=wp.media.dgDefaults.id);a.post(ajaxurl,{action:"dg_generate_gallery",atts:b},function(b){b=a(a.parseHTML(b));l&&!n&&b.find(p).length&&(n=!0,a("#insert-media-button").trigger("ready.dg"));c.replaceWith(b);d(b);e();"undefined"!==typeof f&&f(a("#"+c.attr("id")))})}function m(){for(var b=[];k<h.length&&4!==b.length;k++)b.push(h[k]);0!==b.length&&a.ajax({type:"POST",url:ajaxurl,dataType:"json",data:{action:"dg_generate_icons",
6
- ids:b},success:q,error:function(a){console.error(a.responseText)}})}function q(b){for(var c in b)if(b.hasOwnProperty(c)){var d=a('.document-gallery img[data-id="'+c+'"]');d.removeAttr("data-id");(function(c,d){d.fadeOut("fast",function(){a(this).attr("src",b[c]);a(this).fadeIn("fast")})})(c,d)}m()}var h,k,l,p='.document-gallery [data-ext="'+"doc docx ppt pptx xls xlsx pub vsd vsdx".split(" ").join('"],[data-ext="')+'"]',n=!1;a(document).ready(function(){l="undefined"!==typeof tinymce;d();e();c();
7
- f()})})(jQuery);
2
  $jscomp.global=$jscomp.getGlobal(this);$jscomp.polyfill=function(a,d,c,f){if(d){c=$jscomp.global;a=a.split(".");for(f=0;f<a.length-1;f++){var e=a[f];e in c||(c[e]={});c=c[e]}a=a[a.length-1];f=c[a];d=d(f);d!=f&&null!=d&&$jscomp.defineProperty(c,a,{configurable:!0,writable:!0,value:d})}};$jscomp.polyfill("Array.prototype.find",function(a){return a?a:function(a,c){return $jscomp.findInternal(this,a,c).v}},"es6-impl","es3");
3
  (function(a){function d(b){(b||a(".document-gallery[data-icon-width]")).each(function(){var b=a(this).data("icon-width");"undefined"!==typeof b&&a(this).find(".document-icon").width(b+"%")})}function c(){l&&tinymce.PluginManager.add("dg",function(b,c){b.on("LoadContent update.dg undo",function(b){a(b.target.contentDocument).find('[data-wpview-type="dg"] [data-shortcode]').each(function(){g("object"===typeof a(this).data("shortcode")?a(this).data("shortcode"):JSON.parse(decodeURIComponent(a(this).data("shortcode"))),
4
  a(this))})})})}function f(){a("body").delegate(".dg-paginate-wrapper .paginate a","click",function(b){var c=a(this).closest(".dg-paginate-wrapper"),d=c.data("shortcode");d.skip=0;var e=a(this).attr("href").split("#")[1].split("=");2<=e.length&&(d.skip=d.limit*(e.pop()-1));g(d,c,function(b){var c=a("#wpadminbar").height()||0;b=b.offset().top-c;a(document).scrollTop()>b&&a("html, body").animate({scrollTop:b-20},"slow")});b.preventDefault()})}function e(){h=[];k=0;a(".document-gallery img[data-id]").each(function(){var b=
5
+ a(this).data("id");-1===a.inArray(b,h)&&h.push(b)});m()}function g(b,c,f){"undefined"===typeof b.id&&(b.id=wp.media.dgDefaults.id);a.post(ajaxurl,{action:"dg_generate_gallery",atts:b},function(b){b=a(a.parseHTML(b));l&&!n&&b.find(p).length&&(n=!0,a("#insert-media-button").trigger("ready.dg"));var g=c.attr("id");b.attr("id",g);c.replaceWith(b);c=a("#"+g);d(c);e();"undefined"!==typeof f&&f(c)})}function m(){for(var b=[];k<h.length&&4!==b.length;k++)b.push(h[k]);0!==b.length&&a.ajax({type:"POST",url:ajaxurl,
6
+ dataType:"json",data:{action:"dg_generate_icons",ids:b},success:q,error:function(a){console.error(a.responseText)}})}function q(b){for(var c in b)if(b.hasOwnProperty(c)){var d=a('.document-gallery img[data-id="'+c+'"]');d.removeAttr("data-id");(function(c,d){d.fadeOut("fast",function(){a(this).attr("src",b[c]);a(this).fadeIn("fast")})})(c,d)}m()}var h,k,l,p='.document-gallery [data-ext="'+"doc docx ppt pptx xls xlsx pub vsd vsdx".split(" ").join('"],[data-ext="')+'"]',n=!1;a(document).ready(function(){l=
7
+ "undefined"!==typeof tinymce;d();e();c();f()})})(jQuery);
document-gallery.php CHANGED
@@ -5,14 +5,14 @@ defined( 'WPINC' ) OR exit;
5
  Plugin Name: Document Gallery
6
  Plugin URI: https://wordpress.org/plugins/document-gallery/
7
  Description: Display non-images (and images) in gallery format on a page or post with the [dg] shortcode.
8
- Version: 4.4.2
9
  Author: Dan Rossiter
10
  Author URI: http://danrossiter.org/
11
  License: GPLv3
12
  Text Domain: document-gallery
13
  */
14
 
15
- define( 'DG_VERSION', '4.4.2' );
16
 
17
  if ( version_compare( PHP_VERSION, '5.3', '<' ) ) {
18
  add_action( 'admin_notices', 'dg_php_lt_three' );
5
  Plugin Name: Document Gallery
6
  Plugin URI: https://wordpress.org/plugins/document-gallery/
7
  Description: Display non-images (and images) in gallery format on a page or post with the [dg] shortcode.
8
+ Version: 4.4.3
9
  Author: Dan Rossiter
10
  Author URI: http://danrossiter.org/
11
  License: GPLv3
12
  Text Domain: document-gallery
13
  */
14
 
15
+ define( 'DG_VERSION', '4.4.3' );
16
 
17
  if ( version_compare( PHP_VERSION, '5.3', '<' ) ) {
18
  add_action( 'admin_notices', 'dg_php_lt_three' );