PageSourceSearch

https://proparcel.com/static/js/initialization/parcel_query_buttons_sync.js?v=20260531-ada-parsel-btn

js proparcel.com collected 2026-09-24 14:51:13 UTC 6,709 bytes, 229 lines download raw bytes

1/**
2 * Parsel Sorgu Butonları Senkronizasyon Yöneticisi
3 * 
4 * Bu modül, Parsel Sorgu butonlarının (dropdown, unified bar)
5 * birbirleriyle senkronize çalışmasını sağlar.
6 * 
7 * Butonlar:
8 * 1. dropdown-parsel-sorgu-btn - Dropdown menü içindeki buton
9 * 2. proAdaParselSorguBtn - Unified bar butonu
10 */
11
12(function() {
13  'use strict';
14
15  // Buton ID'leri
16  const BUTTON_IDS = {
17    dropdown: 'dropdown-parsel-sorgu-btn',
18    pro: 'proAdaParselSorguBtn'
19  };
20
21  // Sidebar element
22  let sidebar = null;
23  let observer = null;
24
25  /**
26   * Tüm Parsel Sorgu butonlarını bulur
27   * @returns {Object} Buton elementleri
28   */
29  function getParcelQueryButtons() {
30    return {
31      dropdown: document.getElementById(BUTTON_IDS.dropdown) || 
32                document.querySelector('.dropdown-menu button[onclick*="toggleSidebar"][title*="Parsel Sorgu"]'),
33      pro: document.getElementById(BUTTON_IDS.pro)
34    };
35  }
36
37  /**
38   * Sidebar'ın aktif durumunu kontrol eder
39   * @returns {boolean} Sidebar aktif mi?
40   */
41  function isSidebarActive() {
42    if (!sidebar) {
43      sidebar = document.getElementById("sidebar");
44    }
45    return sidebar ? sidebar.classList.contains("active") : false;
46  }
47
48  /**
49   * Tüm Parsel Sorgu butonlarını senkronize eder
50   * @param {boolean} isActive - Butonlar aktif mi olacak?
51   */
52  function syncAllButtons(isActive) {
53    const buttons = getParcelQueryButtons();
54    
55    // Eğer isActive belirtilmemişse, sidebar durumuna göre belirle
56    if (isActive === undefined || isActive === null) {
57      isActive = isSidebarActive();
58    }
59
60    // Tüm butonları senkronize et
61    Object.keys(buttons).forEach(key => {
62      const btn = buttons[key];
63      if (btn) {
64        if (isActive) {
65          btn.classList.add('active');
66        } else {
67          btn.classList.remove('active');
68        }
69      }
70    });
71  }
72
73  /**
74   * Toolbar'daki Ada Parsel Sorgu butonu DOM'dan silinirse yeniden oluştur.
75   */
76  function ensureProAdaParselButton() {
77    if (document.getElementById(BUTTON_IDS.pro)) return;
78
79    const container = document.getElementById('top-button-container');
80    if (!container) return;
81
82    const btn = document.createElement('button');
83    btn.id = BUTTON_IDS.pro;
84    btn.type = 'button';
85    btn.className = 'toggle-btn pp-ada-parsel-toolbar-btn';
86    btn.title = 'Ada/Parsel Sorgu';
87    btn.innerHTML = '<i class="fa fa-search" aria-hidden="true"></i><span>Ada Parsel Sorgu</span>';
88
89    const firstChild = container.firstElementChild;
90    if (firstChild && firstChild.classList && firstChild.classList.contains('btn-separator')) {
91      container.insertBefore(btn, firstChild);
92    } else {
93      const sep = document.createElement('span');
94      sep.className = 'btn-separator';
95      container.insertBefore(sep, container.firstChild);
96      container.insertBefore(btn, container.firstChild);
97    }
98
99    setupButtonListeners();
100  }
101
102  /**
103   * Butonlara click event listener'ları ekler
104   */
105  function setupButtonListeners() {
106    const buttons = getParcelQueryButtons();
107
108    // Unified bar butonu (Pro)
109    if (buttons.pro && !buttons.pro.__parcelSyncBound) {
110      buttons.pro.__parcelSyncBound = true;
111      buttons.pro.addEventListener('click', function(e) {
112        e.preventDefault();
113        e.stopPropagation();
114        if (typeof window.toggleSidebar === 'function') {
115          window.toggleSidebar();
116        }
117      });
118    }
119
120    // Dropdown butonu zaten onclick ile bağlı, ekstra listener eklemeye gerek yok
121  }
122
123  /**
124   * Sidebar durum değişikliklerini izler (MutationObserver)
125   */
126  function setupSidebarObserver() {
127    if (!sidebar) {
128      sidebar = document.getElementById("sidebar");
129    }
130    
131    if (!sidebar || observer) return; // Zaten kurulmuş
132
133    observer = new MutationObserver(function(mutations) {
134      mutations.forEach(function(mutation) {
135        if (mutation.type === 'attributes' && mutation.attributeName === 'class') {
136          const isActive = sidebar.classList.contains("active");
137          syncAllButtons(isActive);
138        }
139      });
140    });
141
142    observer.observe(sidebar, {
143      attributes: true,
144      attributeFilter: ['class']
145    });
146  }
147
148  /**
149   * toggleSidebar fonksiyonunu wrap eder ve senkronizasyon ekler
150   */
151  function wrapToggleSidebar() {
152    if (!window.toggleSidebar || window.toggleSidebar.__parcelSyncWrapped) {
153      return; // Zaten wrap edilmiş veya yok
154    }
155
156    const originalToggleSidebar = window.toggleSidebar;
157    
158    window.toggleSidebar = function() {
159      // Orijinal fonksiyonu çağır
160      const result = originalToggleSidebar.apply(this, arguments);
161      
162      // Sidebar durumu değişti, butonları senkronize et
163      // MutationObserver zaten bunu yakalayacak, ama emin olmak için burada da yapıyoruz
164      setTimeout(() => {
165        const isActive = isSidebarActive();
166        syncAllButtons(isActive);
167      }, 50); // Kısa bir gecikme ile sidebar'ın class değişikliğini yakala
168      
169      return result;
170    };
171    
172    window.toggleSidebar.__parcelSyncWrapped = true;
173  }
174
175  /**
176   * Başlangıç durumunu senkronize eder
177   */
178  function init() {
179      // Sidebar'ı bul
180      sidebar = document.getElementById("sidebar");
181      
182      if (!sidebar) {
183        // DOM henüz hazır değilse, biraz bekle
184        setTimeout(init, 100);
185        return;
186      }
187
188      // Başlangıç durumunu senkronize et
189      ensureProAdaParselButton();
190      syncAllButtons();
191
192      // Buton listener'larını kur
193      setupButtonListeners();
194
195      // Sidebar observer'ı kur
196      setupSidebarObserver();
197
198      // toggleSidebar fonksiyonunu wrap et
199      wrapToggleSidebar();
200
201      // Toolbar'dan yanlışlıkla silinirse geri ekle
202      const toolbar = document.getElementById('top-button-container');
203      if (toolbar && !toolbar.__ppAdaParselGuard) {
204        toolbar.__ppAdaParselGuard = true;
205        new MutationObserver(function () {
206          ensureProAdaParselButton();
207        }).observe(toolbar, { childList: true });
208      }
209
210  }
211
212  /**
213   * Global API
214   */
215  window.ParcelQueryButtonsSync = {
216    sync: syncAllButtons,
217    getButtons: getParcelQueryButtons,
218    isSidebarActive: isSidebarActive
219  };
220
221  // DOM hazır olduğunda başlat
222  if (document.readyState === 'loading') {
223    document.addEventListener('DOMContentLoaded', init);
224  } else {
225    // DOM zaten hazırsa, kısa bir gecikme ile başlat (diğer scriptlerin yüklenmesi için)
226    setTimeout(init, 100);
227  }
228
229})();

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.