Changeset 7262
- Timestamp:
- 06/01/2018 05:35:03 PM (7 years ago)
- Location:
- sites/trunk/wordcamp.org/public_html/wp-content/plugins/wc-post-types
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordcamp.org/public_html/wp-content/plugins/wc-post-types/css/shortcodes.css
r7261 r7262 130 130 bottom: 50px; 131 131 right: 100px; 132 width: 200px;132 width: 350px; 133 133 background: #dcdcdc; 134 134 font-size: 12px; -
sites/trunk/wordcamp.org/public_html/wp-content/plugins/wc-post-types/js/favourite-sessions.js
r7261 r7262 1 1 jQuery( document ).ready( function ( $ ) { 2 var favSessionsUrlSlug = 'fav-sessions='; 3 4 function getUrlParams() { 5 var url = decodeURIComponent( window.location.search ), 6 urlParams = {}; 7 8 url.replace( /[?&]+([^=&]+)=([^&]*)/gi, function( str, key, value ) { 9 urlParams[ key ] = value; 10 } ); 11 12 return urlParams; 13 } 14 2 15 var FavSessions = { 3 16 favSessKey: 'favourite_sessions', 4 5 get: function () { 6 var favSessions = JSON.parse( localStorage.getItem( this.favSessKey ) ); 7 8 if ( ! favSessions ) { 9 favSessions = {}; 17 useLocalStorage: 'local_storage', 18 useUrlSessions: 'URL', 19 20 get: function() { 21 if ( this.primarySource == this.useLocalStorage ) { 22 var favSessions = JSON.parse( localStorage.getItem( this.favSessKey ) ); 23 24 if ( ! favSessions ) { 25 favSessions = {}; 26 } 27 } else { 28 favSessions = this.favSessionsFromUrl(); 10 29 } 11 30 … … 14 33 15 34 toggleSession: function ( sessionId ) { 35 if ( this.primarySource !== this.useLocalStorage ) { 36 return; 37 } 38 16 39 var favSessions = this.get(); 17 40 … … 24 47 localStorage.setItem( this.favSessKey, JSON.stringify( favSessions ) ); 25 48 }, 49 50 getSessionsForLink: function() { 51 var favSessions = this.get(); 52 53 return Object.keys( favSessions ).join(); 54 }, 55 56 favSessionsFromUrl: function() { 57 var urlParams = getUrlParams(), 58 urlSlugPosition = favSessionsUrlSlug.slice( 0, favSessionsUrlSlug.length - 1 ), 59 favSessionIds = urlParams[ urlSlugPosition ].split( ',' ), 60 favSessions = {}; 61 62 for ( var i = 0; i < favSessionIds.length; i++ ) { 63 favSessions[ favSessionIds[ i ] ] = true; 64 } 65 66 return favSessions; 67 }, 68 69 updateBasedOnLink: function() { 70 favSessions = this.favSessionsFromUrl(); 71 72 localStorage.setItem( this.favSessKey, JSON.stringify( favSessions ) ); 73 74 return this.get(); 75 }, 26 76 }; 77 78 // Use local storage for session source for fetching & target for saving by default. 79 FavSessions.primarySource = FavSessions.useLocalStorage; 27 80 28 81 function switchCellAppearance( sessionId ) { … … 50 103 } 51 104 105 function updateShareLink() { 106 var favSessionIds = FavSessions.getSessionsForLink(), 107 urlParams = getUrlParams(), 108 baseURL = window.location.href, 109 paramsPosition = baseURL.indexOf( '?' ), 110 urlSlugPosition = favSessionsUrlSlug.slice( 0, favSessionsUrlSlug.length - 1 ); 111 112 if ( -1 !== paramsPosition ) { 113 baseURL = baseURL.slice( 0, paramsPosition ); 114 } 115 116 urlParams[ urlSlugPosition ] = favSessionIds; 117 118 // Don't include empty URL parameter. 119 if ( '' === favSessionIds ) { 120 delete urlParams[ urlSlugPosition ]; 121 } 122 123 var favSessionsLink = baseURL + '?' + $.param( urlParams ); 124 125 $( '#fav-sessions-link' ).text( favSessionsLink ); 126 $( '#fav-sessions-link' ).prop( 'href', favSessionsLink ); 127 } 128 52 129 function switchSessionFavourite( sessionId ) { 53 130 FavSessions.toggleSession( sessionId ); 54 131 switchCellAppearance( sessionId ); 55 132 switchEmailFavButton(); 133 updateShareLink(); 56 134 } 57 135 … … 63 141 } 64 142 143 /* 144 * The user has already saved some sessions in local storage, but is now 145 * loading a shared link. We need to determine whether they intend to overwrite 146 * their saved sessions with those in the link, or if they just want to view 147 * the link's sessions and then discard them, so that their saved sessions remain 148 * in tact. 149 */ 150 var currentUrl = window.location.href; 151 152 if ( currentUrl.indexOf( favSessionsUrlSlug ) > -1 ) { 153 var overwrite = confirm( favSessionsPhpObject.i18n.overwriteFavSessions ); 154 155 if ( true === overwrite ) { 156 FavSessions.primarySource = FavSessions.useLocalStorage; 157 favSessions = FavSessions.updateBasedOnLink( currentUrl ); 158 159 $( '.fav-session-button' ).attr( 'title', '' ); 160 $( '.fav-session-button' ).fadeTo( 0, 1 ); 161 } else { 162 FavSessions.primarySource = FavSessions.useUrlSessions; 163 favSessions = FavSessions.get(); 164 165 /* 166 * Deactivate interaction with favourite session buttons, 167 * since the use chose to not overwrite their saved sessions. 168 */ 169 $( '.fav-session-button' ).attr( 'title', favSessionsPhpObject.i18n.buttonDisabledNote ); 170 $( '.fav-session-button' ).fadeTo( 0, 0.5 ); 171 $( '.fav-session-button' ).css( 'color', '#e7e7e7' ); 172 } 173 } 174 175 if ( {} === favSessions ) { 176 return; 177 } 178 65 179 // Highlight favourite sessions in table. 66 180 var sessionIds = Object.keys( favSessions ); … … 75 189 76 190 switchEmailFavButton(); 191 updateShareLink(); 77 192 } 78 193 … … 119 234 event.preventDefault(); 120 235 121 var elem = $( this ); 122 var sessionId = elem.parent().parent().data( 'session-id' ); 123 switchSessionFavourite( sessionId ); 236 if ( FavSessions.primarySource == FavSessions.useLocalStorage ) { 237 var elem = $( this ), 238 sessionId = elem.parent().parent().data( 'session-id' ); 239 240 switchSessionFavourite( sessionId ); 241 } else { 242 alert( favSessionsPhpObject.i18n.buttonDisabledAlert ); 243 } 124 244 125 245 return false; -
sites/trunk/wordcamp.org/public_html/wp-content/plugins/wc-post-types/wc-post-types.php
r7261 r7262 732 732 'reqTimeOut' => esc_html__( 'Sorry, the email request timed out.', 'wordcamporg' ), 733 733 'otherError' => esc_html__( 'Sorry, the email request failed.', 'wordcamporg' ), 734 'overwriteFavSessions' => esc_html__( 'You already have some sessions saved. Would you like to overwrite those with the shared sessions that you are viewing?', 'wordcamporg' ), 735 'buttonDisabledAlert' => esc_html__( 'Interaction with favorite sessions disabled in share sessions view. Please click on schedule menu link to pick sessions.', 'wordcamporg' ), 736 'buttonDisabledNote' => esc_html__( 'Button disabled.', 'wordcamporg' ), 734 737 ), 735 738 ) … … 765 768 <?php endif; ?> 766 769 770 <div class="fav-session-tablinks" id="fav-session-btn-link"> 771 <?php esc_html_e( 'Link', 'wordcamporg' ); ?> 772 </div> 773 767 774 <div class="fav-session-tablinks" id="fav-session-btn-print"> 768 775 <?php esc_html_e( 'Print', 'wordcamporg' ); ?> … … 786 793 </div> 787 794 <?php endif; ?> 795 796 <div id="fav-session-tab-link" class="fav-session-share-tabcontent"> 797 <?php esc_html_e( 'Shareable link:', 'wordcamporg' ); ?><br /> 798 <a id="fav-sessions-link" href=""></a> 799 </div> 788 800 789 801 <div id="fav-session-tab-print" class="fav-session-share-tabcontent">
Note: See TracChangeset
for help on using the changeset viewer.