!function(t){var a,e,n;function o(){a=[],e=0,t(".document-gallery img[data-id]").each(function(){var e=t(this).data("id");-1===t.inArray(e,a)&&a.push(e)}),d()}function i(a,e,n){void 0===a.id&&(a.id=wp.media.dgDefaults.id),t.post(ajaxurl,{action:"dg_generate_gallery",atts:a},function(a){var i=t(t.parseHTML(a)),d=e.attr("id");i.attr("id",d),e.replaceWith(i),e=t("#"+d),o(),void 0!==n&&n(e)})}function d(){for(var n=[];e<a.length&&4!==n.length;e++)n.push(a[e]);0!==n.length&&t.ajax({type:"POST",url:ajaxurl,dataType:"json",data:{action:"dg_generate_icons",ids:n},success:r,error:function(t){console.error(t.responseText)}})}function r(a){for(var e in a)if(a.hasOwnProperty(e)){var n=t('.document-gallery img[data-id="'+e+'"]');n.removeAttr("data-id"),function(e,n){var o="fast";n.fadeOut(o,function(){t(this).attr("src",a[e]),t(this).fadeIn(o)})}(e,n)}d()}t(document).ready(function(){n="undefined"!=typeof tinymce,o(),n&&tinymce.PluginManager.add("dg",function(a,e){a.on("LoadContent update.dg undo",function(a){t(a.target.contentDocument).find('[data-wpview-type="dg"] [data-shortcode]').each(function(){i("object"==typeof t(this).data("shortcode")?t(this).data("shortcode"):JSON.parse(decodeURIComponent(t(this).data("shortcode"))),t(this))})})}),t("body").delegate(".dg-paginate-wrapper .paginate a","click",function(a){var e=t(this).closest(".dg-paginate-wrapper"),n=e.data("shortcode");n.skip=0;var o=t(this).attr("href").split("#")[1].split("=");o.length>=2&&(n.skip=n.limit*(o.pop()-1)),i(n,e,function(a){var e=t("#wpadminbar").height()||0,n=a.offset().top-e;t(document).scrollTop()>n&&t("html, body").animate({scrollTop:n-20},"slow")}),a.preventDefault()})})}(jQuery);