1 /**
  2  * This file is part of the Web Enabled Audio and Sound Enhancement Library (aka the Weasel audio library) Copyright 2011 - 2013 Warren Willmey. It is covered by the GNU General Public License version 3 as published by the Free Software Foundation, you should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
  3  */
  4 /** Namespace for Weasel Jukebox API.
  5  * @const
  6  */
  7 var jukebox = jukebox||{};
  8 
  9 
 10 /** @type {WindowObjectReference} */
 11 jukebox.oPopupWindowID = null;
 12 
 13 //---------------------------------------------------------------------------
 14 /** Get the (local) DOM Storage, mainly in a separate function so it can be mocked by tests easily.
 15  * 
 16  * @return {Storage} = The Storage object for the (local) DOM Storage.
 17  * 
 18  * @private
 19  */
 20 jukebox._getLocalStorage = function()
 21 {
 22 	return window.localStorage;
 23 };
 24 
 25 //---------------------------------------------------------------------------
 26 /** Add a module to the playlist of the jukebox via DOM Storage.
 27  * 
 28  * @param {String} sComposer = The name of the composer of the module.
 29  * @param {String} sMusicName = The display name of the module.
 30  * @param {String} sURL = The URL of the module (needs to be on the same server 
 31  * as the Jukebox (or its a XSS security issue).
 32  * 
 33  * @return {boolean} always returns false.
 34  * 
 35  * @author Warren Willmey 2012
 36  */
 37 jukebox.addToPlayList = function( sComposer, sMusicName, sURL )
 38 {
 39 	if( jukebox._getLocalStorage() )
 40 	{
 41 		var oDOMStorage = jukebox._getLocalStorage();
 42 		var oLocationDetails = { APIVersionMajor : 1, APIVersionMinor : 0, Composer : sComposer, DisplayName : sMusicName, URL : sURL };
 43 		var sLocationDetails = JSON.stringify( oLocationDetails );
 44 
 45 		oDOMStorage.setItem( 'WeaselJukebox.AddToPlayList', sLocationDetails );
 46 	}
 47 	else
 48 	{
 49 		window.alert( 'Please enable DOM Storage in order to add songs to the playlist within the jukebox, on some browsers (Firefox, Chromium) Cookies also need enabling to allow use of DOM Storage. Alternatively drag and dropping a direct link to the module may also work if your browser supports drag and drop functionality.' );
 50 	}
 51 
 52 	return false;
 53 };
 54 
 55 //---------------------------------------------------------------------------
 56 /** Open the Weasel Audio Libraries Jukebox (demo1) in a popup window, can be made
 57  * to load a play list and auto start playing music.
 58  *
 59  * @param {String} sURLToJukebox = URL to the Weasel Jukebox directory containing demo1.html ( "" for the current directory ).
 60  * @param {String} sURLToPlayList = URL to Weasel Jukebox JSON play list ( "" if no play list).
 61  * @param {bool} bAutoStart = Start playing music once the jukebox has loaded.
 62  * 
 63  * @return {boolean} always returns false.
 64  * 
 65  * @author Warren Willmey 2012
 66  */
 67 jukebox.openJukebox = function( sURLToJukebox, sURLToPlayList, bAutoStart )
 68 {
 69 	// Jukebox window not open.
 70 	//
 71 	if( undefined == sURLToJukebox )
 72 	{
 73 		sURLToJukebox = '';
 74 	}
 75 	if( undefined == sURLToPlayList )
 76 	{
 77 		sURLToPlayList = '';
 78 	}
 79 	if( undefined == bAutoStart )
 80 	{
 81 		bAutoStart = false;
 82 	}
 83 
 84 	var sParameters = '';
 85 	if( '' != sURLToPlayList )
 86 	{
 87 		sParameters = '?LoadPlayList=' + encodeURIComponent( sURLToPlayList );
 88 	}
 89 
 90 	if( bAutoStart )
 91 	{
 92 		if( '' != sParameters )
 93 		{
 94 			sParameters += '&';
 95 		}
 96 		else
 97 		{
 98 			sParameters += '?';
 99 		}
100 
101 		sParameters += 'AutoStart=True';
102 	}
103 
104 	jukebox.oPopupWindowID = window.open( sURLToJukebox + 'demo1.html' + sParameters, 'WeaselJukebox', 'toolbar=no,scrollbars=yes,resizable,width=900,height=780' );
105 
106 	return false;
107 };
108