{"version":3,"sources":["recententries/src/RecentEntriesWidget.js"],"names":["$","Craft","RecentEntriesWidget","Garnish","Base","extend","params","$widget","$body","$container","$tbody","init","widgetId","find","hasEntries","length","instances","push","this","destroy","bind","addEntry","entry","css","oldHeight","height","$table","prependTo","prepend","appendTo","url","escapeHtml","title","dateCreated","formatDate","username","edition","Pro","heightDiff","props","margin-top","velocity","splice","inArray","base","jQuery"],"mappings":"CAAA,SAACA,GAEGC,MAAAC,oBAAAC,QAAAC,KAAAC,OAAA,CACMH,OAAAA,KACFI,QAD4C,KAE5CC,MAAS,KACTC,WAH4C,KAI5CC,OAAY,KACZC,WAL4C,KAQxCC,KAAE,SAASC,EAAUN,GAChBA,KAALA,OAAAA,EACKC,KAAAA,QAAYP,EAAA,UAAYY,GACxBJ,KAALA,MAAkBD,KAAAA,QAAaM,KAAA,eAC1BJ,KAAAA,WAAkBF,KAAAA,QAAaM,KAAA,kCAC/BH,KAALA,OAAmBD,KAAAA,WAAgBI,KAAA,eAC9BC,KAAAA,aAAoBJ,KAALA,OAApBK,OAIMb,KAAAA,QAAAA,KAAAA,UAAoBc,GAAUC,UAApCC,KAAAC,QAAAC,KAAAF,OAGIjB,MAAEC,oBAAgBc,UAAAC,KAAAC,OAA1BG,SAAU,SAASC,GAIVJ,KAAKJ,WAAYS,IAAA,aAAA,GAClB,IAAAC,EAAAN,KAAAT,WAAAgB,SAEA,IAAKf,KAASV,WAAC,CADf,IAAI0B,EAAS1B,EAAE,mCAAmC2B,UAAUT,KAAKT,YAIhEC,KAAOkB,OACR5B,EAAA,YAEA6B,SAAAH,GAeCjB,KAAAA,OAAWc,QAEP,oBAETD,EAAAQ,IAAA,KAAA7B,MAAA8B,WAAAT,EAAAU,OAFS,4BAGClB,MAAAA,YACAQ,EAAAW,YAAoBT,MAA1BU,WAAAZ,EAAAW,aAAA,KACKnB,EAAamB,aAAlBX,EAAAa,UAAAlC,MAAAmC,SAAAnC,MAAAoC,IAAA,KAAA,KACHf,EAAAa,UAAAlC,MAAAmC,SAAAnC,MAAAoC,IAAAf,EAAAa,SAAA,KANQ,qBAcZ,IACFG,EADEpB,KAAAT,WAAAgB,SACFD,EAlEHN,KAAAT,WAAAc,IAAA,cAAAe,GAmDQ,IAAIC,EAAQ,CAACC,aAAc,GAGtBtB,KAAKJ,aACNyB,EAAM,kBAAoBf,EAC1BN,KAAKJ,YAAa,GAGtBI,KAAKT,WAAWgC,SAASF,IAG7BpB,QAAS,WACLlB,MAAMC,oBAAoBc,UAAU0B,OAAO1C,EAAE2C,QAAQzB,KAAMjB,MAAMC,oBAAoBc,WAAY,GACjGE,KAAK0B,SAEV,CACC5B,UAAW,KAtEnB,CAwEG6B","file":"RecentEntriesWidget.min.js","sourcesContent":["(function($) {\n    /** global: Craft */\n    /** global: Garnish */\n    Craft.RecentEntriesWidget = Garnish.Base.extend({\n        params: null,\n        $widget: null,\n        $body: null,\n        $container: null,\n        $tbody: null,\n        hasEntries: null,\n\n        init: function(widgetId, params) {\n            this.params = params;\n            this.$widget = $('#widget' + widgetId);\n            this.$body = this.$widget.find('.body:first');\n            this.$container = this.$widget.find('.recententries-container:first');\n            this.$tbody = this.$container.find('tbody:first');\n            this.hasEntries = !!this.$tbody.length;\n\n            this.$widget.data('widget').on('destroy', this.destroy.bind(this));\n\n            Craft.RecentEntriesWidget.instances.push(this);\n        },\n\n        addEntry: function(entry) {\n            this.$container.css('margin-top', 0);\n            var oldHeight = this.$container.height();\n\n            if (!this.hasEntries) {\n                // Create the table first\n                var $table = $('<table class=\"data fullwidth\"/>').prependTo(this.$container);\n                this.$tbody = $('<tbody/>').appendTo($table);\n            }\n\n            this.$tbody.prepend(\n                '<tr>' +\n                '<td>' +\n                '<a href=\"' + entry.url + '\">' + Craft.escapeHtml(entry.title) + '</a> ' +\n                '<span class=\"light\">' +\n                Craft.escapeHtml(\n                    (entry.dateCreated ? Craft.formatDate(entry.dateCreated) : '') +\n                    (entry.dateCreated && entry.username && Craft.edition == Craft.Pro ? ', ' : '') +\n                    (entry.username && Craft.edition == Craft.Pro ? entry.username : '')\n                ) +\n                '</span>' +\n                '</td>' +\n                '</tr>'\n            );\n\n            var newHeight = this.$container.height(),\n                heightDiff = newHeight - oldHeight;\n\n            this.$container.css('margin-top', -heightDiff);\n\n            var props = {'margin-top': 0};\n\n            // Also animate the \"No entries exist\" text out of view\n            if (!this.hasEntries) {\n                props['margin-bottom'] = -oldHeight;\n                this.hasEntries = true;\n            }\n\n            this.$container.velocity(props);\n        },\n\n        destroy: function() {\n            Craft.RecentEntriesWidget.instances.splice($.inArray(this, Craft.RecentEntriesWidget.instances), 1);\n            this.base();\n        }\n    }, {\n        instances: []\n    });\n})(jQuery);\n"]}