Changeset 12255
- Timestamp:
- 10/20/2018 02:38:18 PM (6 years ago)
- Location:
- trunk/src/bp-templates/bp-legacy
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-templates/bp-legacy/buddypress-functions.php
r12198 r12255 284 284 285 285 /** 286 * Filters whether directory filter settings ('scope', etc) should be stored in a persistent cookie. 287 * 288 * @since 4.0.0 289 * 290 * @param bool $store_filter_settings Whether to store settings. Defaults to true for logged-in users. 291 */ 292 $store_filter_settings = apply_filters( 'bp_legacy_store_filter_settings', is_user_logged_in() ); 293 294 /** 286 295 * Filters core JavaScript strings for internationalization before AJAX usage. 287 296 * … … 291 300 */ 292 301 $params = apply_filters( 'bp_core_get_js_strings', array( 302 // Strings for display. 293 303 'accepted' => __( 'Accepted', 'buddypress' ), 294 304 'close' => __( 'Close', 'buddypress' ), … … 304 314 'unsaved_changes' => __( 'Your profile has unsaved changes. If you leave the page, the changes will be lost.', 'buddypress' ), 305 315 'view' => __( 'View', 'buddypress' ), 316 317 // Settings. 318 'store_filter_settings' => $store_filter_settings, 306 319 ) ); 307 320 wp_localize_script( $asset['handle'], 'BP_DTheme', $params ); -
trunk/src/bp-templates/bp-legacy/js/buddypress.js
r12182 r12255 10 10 var newest_activities = ''; 11 11 var activity_last_recorded = 0; 12 13 var directoryPreferences = {} 12 14 13 15 jq(document).ready( function() { … … 849 851 } 850 852 851 bp_filter_request( object, jq.cookie('bp-' + object + '-filter'), jq.cookie('bp-' + object + '-scope') , 'div.' + object, search_terms, 1, jq.cookie('bp-' + object + '-extras'), null, template ); 853 var scope = bp_get_directory_preference( object, 'scope' ); 854 var filter = bp_get_directory_preference( object, 'filter' ); 855 var extras = bp_get_directory_preference( object, 'extras' ); 856 857 bp_filter_request( object, filter, scope, 'div.' + object, search_terms, 1, extras, null, template ); 852 858 853 859 return false; … … 884 890 search_terms = jq('#' + object + '_search').val(); 885 891 886 bp_filter_request( object, filter, scope, 'div.' + object, search_terms, 1, jq.cookie('bp-' + object + '-extras') ); 892 var extras = bp_get_directory_preference( object, 'extras' ); 893 894 bp_filter_request( object, filter, scope, 'div.' + object, search_terms, 1, extras ); 887 895 888 896 return false; … … 932 940 } 933 941 934 bp_filter_request( object, filter, scope, 'div.' + object, search_terms, 1, jq.cookie('bp-' + object + '-extras'), null, template ); 942 var extras = bp_get_directory_preference( object, 'extras' ); 943 944 bp_filter_request( object, filter, scope, 'div.' + object, search_terms, 1, extras, null, template ); 935 945 936 946 return false; … … 1020 1030 } 1021 1031 1022 bp_filter_request( object, jq.cookie('bp-' + object + '-filter'), jq.cookie('bp-' + object + '-scope'), 'div.' + object, search_terms, page_number, jq.cookie('bp-' + object + '-extras'), caller, template ); 1032 var scope = bp_get_directory_preference( object, 'scope' ); 1033 var filter = bp_get_directory_preference( object, 'filter' ); 1034 var extras = bp_get_directory_preference( object, 'extras' ); 1035 1036 bp_filter_request( object, filter, scope, 'div.' + object, search_terms, page_number, extras, caller, template ); 1023 1037 1024 1038 return false; … … 1388 1402 object = 'messages'; 1389 1403 1404 var scope = bp_get_directory_preference( object, 'scope' ); 1405 var filter = bp_get_directory_preference( object, 'filter' ); 1406 var extras = bp_get_directory_preference( object, 'extras' ); 1407 1390 1408 bp_filter_request( 1391 1409 object, 1392 jq.cookie('bp-' + object + '-filter'),1393 jq.cookie('bp-' + object + '-scope'),1410 filter, 1411 scope, 1394 1412 'div.' + object, jq('#messages_search').val(), 1395 1413 1, 1396 jq.cookie('bp-' + object + '-extras')1414 extras 1397 1415 ); 1398 1416 … … 1724 1742 }); 1725 1743 1744 /** 1745 * Gets the user's current preference for a directory option. 1746 */ 1747 function bp_get_directory_preference( directoryType, pref ) { 1748 var defaultPrefs = { 1749 filter: '', 1750 scope: '', 1751 extras: '' 1752 } 1753 1754 if ( ! directoryPreferences.hasOwnProperty( directoryType ) ) { 1755 var newPreferences = {}; 1756 for ( var prefName in defaultPrefs ) { 1757 if ( defaultPrefs.hasOwnProperty( prefName ) ) { 1758 newPreferences[ prefName ] = defaultPrefs[ prefName ]; 1759 } 1760 } 1761 directoryPreferences[ directoryType ] = newPreferences; 1762 } 1763 1764 if ( BP_DTheme.store_filter_settings ) { 1765 directoryPreferences[ directoryType ][ pref ] = jq.cookie( 'bp-' + directoryType + '-' + pref ); 1766 } 1767 1768 return directoryPreferences[ directoryType ][ pref ]; 1769 } 1770 1771 /** 1772 * Sets the user's current preference for a directory option. 1773 */ 1774 function bp_set_directory_preference( directoryType, pref, value ) { 1775 var defaultPrefs = { 1776 filter: '', 1777 scope: '', 1778 extras: '' 1779 } 1780 1781 if ( ! directoryPreferences.hasOwnProperty( directoryType ) ) { 1782 var newPreferences = {}; 1783 for ( var prefName in defaultPrefs ) { 1784 if ( defaultPrefs.hasOwnProperty( prefName ) ) { 1785 newPreferences[ prefName ] = defaultPrefs[ prefName ]; 1786 } 1787 } 1788 directoryPreferences[ directoryType ] = newPreferences; 1789 } 1790 1791 if ( BP_DTheme.store_filter_settings ) { 1792 jq.cookie( 'bp-' + directoryType + '-' + pref, value, { 1793 path: '/', 1794 secure: ( 'https:' === window.location.protocol ) 1795 } ); 1796 } 1797 1798 directoryPreferences[ directoryType ][ pref ] = value 1799 } 1800 1726 1801 /* Setup activity scope and filter based on the current cookie settings. */ 1727 1802 function bp_init_activity() { 1728 if ( undefined !== jq.cookie('bp-activity-filter') && jq('#activity-filter-select').length ) { 1729 jq('#activity-filter-select select option[value="' + jq.cookie('bp-activity-filter') + '"]').prop( 'selected', true ); 1803 var scope = bp_get_directory_preference( 'activity', 'scope' ); 1804 var filter = bp_get_directory_preference( 'activity', 'filter' ); 1805 1806 if ( undefined !== filter && jq('#activity-filter-select').length ) { 1807 jq('#activity-filter-select select option[value="' + filter + '"]').prop( 'selected', true ); 1730 1808 } 1731 1809 1732 1810 /* Activity Tab Set */ 1733 if ( undefined !== jq.cookie('bp-activity-scope')&& jq('.activity-type-tabs').length ) {1811 if ( undefined !== scope && jq('.activity-type-tabs').length ) { 1734 1812 jq('.activity-type-tabs li').each( function() { 1735 1813 jq(this).removeClass('selected'); 1736 1814 }); 1737 jq('#activity-' + jq.cookie('bp-activity-scope')+ ', .item-list-tabs li.current').addClass('selected');1815 jq('#activity-' + scope + ', .item-list-tabs li.current').addClass('selected'); 1738 1816 } 1739 1817 } … … 1742 1820 function bp_init_objects(objects) { 1743 1821 jq(objects).each( function(i) { 1744 if ( undefined !== jq.cookie('bp-' + objects[i] + '-filter') && jq('#' + objects[i] + '-order-select select').length ) { 1745 jq('#' + objects[i] + '-order-select select option[value="' + jq.cookie('bp-' + objects[i] + '-filter') + '"]').prop( 'selected', true ); 1746 } 1747 1748 if ( undefined !== jq.cookie('bp-' + objects[i] + '-scope') && jq('div.' + objects[i]).length ) { 1822 var scope = bp_get_directory_preference( objects[i], 'scope' ); 1823 var filter = bp_get_directory_preference( objects[i], 'filter' ); 1824 1825 if ( undefined !== filter && jq('#' + objects[i] + '-order-select select').length ) { 1826 jq('#' + objects[i] + '-order-select select option[value="' + filter + '"]').prop( 'selected', true ); 1827 } 1828 1829 if ( undefined !== scope && jq('div.' + objects[i]).length ) { 1749 1830 jq('.item-list-tabs li').each( function() { 1750 1831 jq(this).removeClass('selected'); 1751 1832 }); 1752 jq('#' + objects[i] + '-' + jq.cookie('bp-' + objects[i] + '-scope')+ ', #object-nav li.current').addClass('selected');1833 jq('#' + objects[i] + '-' + scope + ', #object-nav li.current').addClass('selected'); 1753 1834 } 1754 1835 }); … … 1765 1846 } 1766 1847 1767 /* Save the settings we want to remain persistent to a cookie */ 1768 jq.cookie( 'bp-' + object + '-scope', scope, { 1769 path: '/', 1770 secure: ( 'https:' === window.location.protocol ) 1771 } ); 1772 jq.cookie( 'bp-' + object + '-filter', filter, { 1773 path: '/', 1774 secure: ( 'https:' === window.location.protocol ) 1775 } ); 1776 jq.cookie( 'bp-' + object + '-extras', extras, { 1777 path: '/', 1778 secure: ( 'https:' === window.location.protocol ) 1779 } ); 1848 /* Save the settings we want to remain persistent */ 1849 bp_set_directory_preference( object, 'scope', scope ); 1850 bp_set_directory_preference( object, 'filter', filter ); 1851 bp_set_directory_preference( object, 'extras', extras ); 1780 1852 1781 1853 /* Set the correct selected nav and filter */
Note: See TracChangeset
for help on using the changeset viewer.