nodebb-plugin-niki-loyalty 1.1.2 → 1.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-niki-loyalty",
3
- "version": "1.1.2",
3
+ "version": "1.1.4",
4
4
  "description": "Niki The Cat Coffee Loyalty System - Earn points while studying on IEU Forum.",
5
5
  "main": "library.js",
6
6
  "nbbpm": {
@@ -54,6 +54,70 @@ $(document).ready(function () {
54
54
  }, 500);
55
55
  }
56
56
 
57
+ // -------------------------------------------------------------
58
+ // 🐱 FLOATING WIDGET (Sol Alt - Dinamik Oluşturma)
59
+ // -------------------------------------------------------------
60
+ function createFloatingWidget() {
61
+ // Sadece giriş yapmış kullanıcılar için göster
62
+ if (!app.user || !app.user.uid) return;
63
+
64
+ // Widget zaten varsa oluşturma
65
+ if ($('#niki-floating-widget').length > 0) return;
66
+
67
+ // Logo URL
68
+ const logoUrl = (config && config.relative_path ? config.relative_path : '') + '/plugins/nodebb-plugin-niki-loyalty/static/logo.png';
69
+ const walletUrl = (config && config.relative_path ? config.relative_path : '') + '/niki-wallet';
70
+
71
+ // Widget HTML'i
72
+ const widgetHtml = `
73
+ <div id="niki-floating-widget">
74
+ <a href="${walletUrl}" class="niki-widget-content" id="niki-widget-link">
75
+ <img src="${logoUrl}" alt="Niki" class="niki-widget-logo">
76
+ <div class="niki-widget-text">
77
+ <span class="niki-lbl">NİKİ PUAN</span>
78
+ <span class="niki-val" id="widget-user-points">...</span>
79
+ </div>
80
+ </a>
81
+ </div>
82
+ `;
83
+
84
+ // Body'ye ekle
85
+ $('body').append(widgetHtml);
86
+
87
+ // Widget'a tıklama olayı (SPA için ajaxify kullan)
88
+ $('#niki-widget-link').on('click', function (e) {
89
+ e.preventDefault();
90
+ if (typeof ajaxify !== 'undefined' && ajaxify.go) {
91
+ ajaxify.go('niki-wallet');
92
+ } else {
93
+ window.location.href = $(this).attr('href');
94
+ }
95
+ });
96
+
97
+ console.log('[Niki-Loyalty] Floating widget oluşturuldu.');
98
+
99
+ // İlk veriyi yükle
100
+ updateFloatingWidget();
101
+ }
102
+
103
+ // Floating Widget Puanını Güncelle
104
+ function updateFloatingWidget() {
105
+ if ($('#niki-floating-widget').length === 0) return;
106
+
107
+ $.get('/api/niki-loyalty/wallet-data', function (data) {
108
+ if (data && typeof data.points !== 'undefined') {
109
+ const points = Math.floor(data.points);
110
+ $('#widget-user-points').text(points);
111
+ console.log('[Niki-Loyalty] Widget puanı güncellendi:', points);
112
+ }
113
+ }).fail(function () {
114
+ console.log('[Niki-Loyalty] Widget puanı yüklenemedi.');
115
+ });
116
+ }
117
+
118
+ // Sayfa yüklendiğinde widget oluştur
119
+ createFloatingWidget();
120
+
57
121
  // -------------------------------------------------------------
58
122
  // 🌅 GÜNLÜK GİRİŞ KONTROLÜ (Session açık olsa bile puan ver)
59
123
  // -------------------------------------------------------------
@@ -148,8 +212,11 @@ $(document).ready(function () {
148
212
  // WIDGET GÜNCELLEME (Dinamik Sayaçlı)
149
213
  // --------------------------------------------------------
150
214
  function updateSidebarWidget() {
151
- // Widget sayfada yoksa boşa istek atma
152
- if ($('#widget-daily-progress').length === 0) return;
215
+ // Herhangi bir widget sayfada yoksa boşa istek atma
216
+ const hasFloatingWidget = $('#niki-floating-widget').length > 0 || $('#widget-user-points').length > 0;
217
+ const hasSidebarWidget = $('#widget-daily-progress').length > 0;
218
+
219
+ if (!hasFloatingWidget && !hasSidebarWidget) return;
153
220
 
154
221
  $.get('/api/niki-loyalty/wallet-data', function (data) {
155
222
  // 1. Ana Puanlar