PageSourceSearch

https://www.urlaubsarchitektur.de/wp-content/plugins/inwendo_favorite_posts/js/main.js?ver=1.6

js urlaubsarchitektur.de collected 2026-09-24 19:15:11 UTC 7,300 bytes, 218 lines download raw bytes

1var iw_favorite_post_data_name = 'favorite-posts';
2var iw_favorite_post_cookie_name = iw_favorite_post_data_name;
3var iw_favorite_post_count_class = '.favoritesCount';
4
5var iw_favorite_post_data_local_copy = "";
6
7function iw_favorite_post_array_unique(array) {
8    var a = array.concat();
9    for (var i = 0; i < a.length; ++i) {
10        for (var j = i + 1; j < a.length; ++j) {
11            if (a[i] === a[j])
12                a.splice(j--, 1);
13        }
14    }
15    return a;
16}
17
18function iw_favorite_post_localstorage_test() {
19    var test = 'iw_test';
20    try {
21        localStorage.setItem(test, test);
22        localStorage.removeItem(test);
23        return true;
24    } catch (e) {
25        return false;
26    }
27}
28
29function btnAddFavorite(element) {
30
31    const post_id = jQuery(element).data('postid');
32    if (jQuery(element).hasClass('isFavorite')) {
33        iw_favorite_post_remove_value(post_id);
34    } else {
35        iw_favorite_post_add_value(post_id);
36    }
37    iw_favorite_post_data_changed(false);
38}
39
40function btnRemoveFavorite(element) {
41    var post_id = jQuery(element).data('postid');
42    iw_favorite_post_remove_value(post_id);
43    var count = iw_favorite_post_update_favorite_count();
44    jQuery(element).parent().prev('article').remove();
45    jQuery(element).remove();
46    if (count == 0) {
47        jQuery(".inwendo_favorite_favorites_list_wrapper").replaceWith('<p class="inwendo_favorite_no_favorites">' + iw_favpos_obj.no_favorites + '</p>');
48    }
49}
50
51/**
52 * Gets the Values from a Cookie
53 * @deprecated
54 */
55function iw_favorite_post_get_cookie_values() {
56    var value = "; " + document.cookie;
57    var parts = value.split("; " + iw_favorite_post_cookie_name + "=");
58    if (parts.length == 2) return JSON.parse(decodeURI(parts.pop().split(";").shift()));
59    else return [];
60}
61
62/**
63 * Save the Array to the cookie
64 * @deprecated
65 * @param {*} valuesArray
66 */
67function iw_favorite_post_save_cookie_values(valuesArray) {
68    var now = new Date();
69    var time = now.getTime();
70    time += 3600 * 1000 * 24 * 365 * 10;
71    now.setTime(time);
72    var cok = iw_favorite_post_cookie_name + '=' + JSON.stringify(valuesArray) + '; expires=' + now.toUTCString() + '; path=/';
73    document.cookie = cok;
74}
75
76/**
77 * Gets the Values from LocalStorage
78 */
79function iw_favorite_post_get_localstorage_values() {
80    var values = localStorage.getItem(iw_favorite_post_data_name);
81    if (values != null) {
82        return JSON.parse(values);
83    } else {
84        return [];
85    }
86}
87
88/**
89 * Save the Array to the localStorage
90 * @param {*} valuesArray
91 */
92function iw_favorite_post_save_localstorage_values(valuesArray) {
93    localStorage.setItem(iw_favorite_post_data_name, JSON.stringify(valuesArray));
94}
95
96/**
97 * Add the Value to the Array
98 *
99 * @param {*} val
100 */
101function iw_favorite_post_add_value(val) {
102    var valuesArray = iw_favorite_post_get_values();
103    valuesArray.push(val);
104    iw_favorite_post_save_values(valuesArray);
105}
106
107/**
108 * Remove the value from the Array
109 * @param {*} val
110 */
111function iw_favorite_post_remove_value(val) {
112    var valuesArray = iw_favorite_post_get_values();
113    //removes val from valuesArray
114    valuesArray = jQuery.grep(valuesArray, function(value) {
115        return value != val;
116    });
117    iw_favorite_post_save_values(valuesArray);
118}
119
120function iw_favorite_post_get_values() {
121    var valuesLocalStorage = iw_favorite_post_get_localstorage_values();
122    var valuesCookie = iw_favorite_post_get_cookie_values();
123    if (valuesCookie.length > 0) {
124        return iw_favorite_post_array_unique(valuesLocalStorage.concat(valuesCookie));
125    } else {
126        return valuesLocalStorage;
127    }
128}
129
130function iw_favorite_post_is_favorite(val) {
131    var valuesArray = iw_favorite_post_get_values();
132    var result = jQuery.inArray(val, valuesArray);
133    if (result == -1) {
134        return false;
135    } else {
136        return true;
137    }
138}
139
140function iw_favorite_post_save_values(valuesArray) {
141    if (iw_favpos_obj.async) {
142        iw_favorite_post_save_localstorage_values(valuesArray);
143        var valuesCookie = iw_favorite_post_get_cookie_values();
144        if (iw_favorite_post_localstorage_test() == false || valuesCookie.length > 0) {
145            iw_favorite_post_save_cookie_values(valuesArray);
146        }
147    } else {
148        iw_favorite_post_save_cookie_values(valuesArray);
149    }
150}
151
152function iw_favorite_post_update_favorite_count() {
153    var valuesArray = iw_favorite_post_get_values();
154    jQuery(iw_favorite_post_count_class).html(valuesArray.length);
155    if (valuesArray.length > 0) {
156        jQuery('.favoritesCount').addClass('hasFavorites');
157    } else {
158        jQuery('.favoritesCount').removeClass('hasFavorites');
159    }
160    return valuesArray.length;
161}
162
163function iw_favorite_post_data_changed(initial) {
164    // site ready
165    if (iw_favpos_obj.async) {
166        //update fav count
167        iw_favorite_post_update_favorite_count();
168        //update texts of buttons
169        jQuery('.btnAddFavorite').each(function() {
170            var post_id = jQuery(this).data('postid');
171            if (iw_favorite_post_is_favorite(post_id)) {
172                jQuery(this).addClass('isFavorite').html(iw_favpos_obj.icon+'<span>'+iw_favpos_obj.remove_favorite + '</span>');
173            } else {
174                jQuery(this).removeClass('isFavorite').html(iw_favpos_obj.icon+'<span>'+iw_favpos_obj.add_favorite + '</span>');
175            }
176        });
177        if (initial) {
178            jQuery('.inwendo_favorite_posts_loading').each(function() {
179                var newData = JSON.stringify(iw_favorite_post_get_values());
180                if (newData != iw_favorite_post_data_local_copy) {
181                    iw_favorite_post_data_local_copy = newData;
182                    var data = {
183                        action: 'shortcode_show_list',
184                        favoriteposts: iw_favorite_post_data_local_copy
185                    };
186                    var toreplace = jQuery(this);
187                    jQuery.post(iw_favpos_obj.ajax_url, data, function(response) {
188                        toreplace.replaceWith(response);
189                    });
190                }
191            });
192        }
193        if (!initial) {
194            jQuery('.inwendo_favorite_favorites_list_wrapper').each(function() {
195                var newData = JSON.stringify(iw_favorite_post_get_values());
196                if (newData != iw_favorite_post_data_local_copy) {
197                    iw_favorite_post_data_local_copy = newData;
198                    var data = {
199                        action: 'shortcode_show_list',
200                        favoriteposts: iw_favorite_post_data_local_copy
201                    };
202                    var toreplace = jQuery(this);
203                    jQuery.post(iw_favpos_obj.ajax_url, data, function(response) {
204                        toreplace.replaceWith(response);
205                    }, 'html');
206                }
207            });
208        }
209    }
210}
211
212jQuery(function() {
213    iw_favorite_post_data_changed(true);
214
215    window.addEventListener('storage', function() {
216        iw_favorite_post_data_changed(false);
217    }, false);
218});

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.