From db2d7ce9ef25e812516eb5591984f39843d21c75 Mon Sep 17 00:00:00 2001 From: winkidney Date: Thu, 28 Feb 2019 18:01:15 +0800 Subject: [PATCH] Feature: Render pins by ourself without help of third-party's help --- pinry/static/js/vue/main.js | 60 +++++++++++++++++++++------------- pinry/templates/base.html | 1 - pinry/templates/core/pins.html | 5 ++- pinry/templates/includes/vue-pin.html | 12 ++++++- pinry/templates/includes/vue-pins.html | 16 --------- 5 files changed, 51 insertions(+), 43 deletions(-) delete mode 100644 pinry/templates/includes/vue-pins.html diff --git a/pinry/static/js/vue/main.js b/pinry/static/js/vue/main.js index 851deba..821450f 100644 --- a/pinry/static/js/vue/main.js +++ b/pinry/static/js/vue/main.js @@ -1,9 +1,9 @@ function fetchPins(offset) { - var apiUrl = API_BASE + 'pins/?format=json&ordering=-id&limit=50&offset='+String(offset); - if (tagFilter) apiUrl = apiUrl + '&tags__name=' + tagFilter; - if (userFilter) apiUrl = apiUrl + '&submitter__username=' + userFilter; - return axios.get(apiUrl) + var apiUrl = API_BASE + 'pins/?format=json&ordering=-id&limit=50&offset='+String(offset); + if (tagFilter) apiUrl = apiUrl + '&tags__name=' + tagFilter; + if (userFilter) apiUrl = apiUrl + '&submitter__username=' + userFilter; + return axios.get(apiUrl) } Vue.component('pin', { @@ -18,9 +18,11 @@ Vue.component('pin', { props: ['pin'], template: '#pin-template', methods: { + getInlineStyle: function() { + return {}; + }, onImageLoad: function () { this.loaded = true; - this.$emit("resize", this.getTextHeight()); }, getAvatar: function () { return "//gravatar.com/avatar/" + this.pin.submitter.gravatar; @@ -40,31 +42,45 @@ Vue.component('pin', { }); -var app = new Vue({ - el: '#app', - components: { - 'waterfall': Waterfall.waterfall, - 'waterfall-slot': Waterfall.waterfallSlot, - }, - data() { +Vue.component('pin-container', { + data: function () { return { - pins: [], - loading: true, - } + "windowWidth": null, + "blockWidth": "240px", + "blockMargin": "240px", + "pins": [], + }; }, - methods: { - getInitialPins: function () { + template: "#pin-container-template", + created: function() { + this.$emit("loading"); var self = this; var offset = 0; fetchPins(offset).then( function (res) { self.pins = res.data.results; - self.loading = false; - } + self.$emit( + "loaded", + ); + }, ); - }, }, - created: function () { - this.getInitialPins(); +}); + + +var app = new Vue({ + el: '#app', + data() { + return { + loading: true, + } + }, + methods: { + onLoaded: function(){ + this.loading = false; + }, + onLoading: function(){ + this.loading = true; + }, }, }); diff --git a/pinry/templates/base.html b/pinry/templates/base.html index 74fbe9d..b873ba8 100644 --- a/pinry/templates/base.html +++ b/pinry/templates/base.html @@ -109,7 +109,6 @@ {% compress js %} - {% endcompress %} {% compress js inline %} diff --git a/pinry/templates/core/pins.html b/pinry/templates/core/pins.html index 5d08750..224a9d6 100644 --- a/pinry/templates/core/pins.html +++ b/pinry/templates/core/pins.html @@ -1,8 +1,7 @@ {% extends "base.html" %} {% block yield %} -
- {% include "includes/vue-pins.html" %} -
+ +
{% endblock %} diff --git a/pinry/templates/includes/vue-pin.html b/pinry/templates/includes/vue-pin.html index 4b32a2e..9e68d97 100644 --- a/pinry/templates/includes/vue-pin.html +++ b/pinry/templates/includes/vue-pin.html @@ -1,6 +1,16 @@ {% verbatim %} + + +