Changeset 31
- Timestamp:
- 07/25/08 15:07:42 (1 month ago)
- Files:
-
- chrome/songbee/songbee-sql.js (modified) (2 diffs)
- chrome/songbee/songbee.js (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
chrome/songbee/songbee-sql.js
r30 r31 181 181 182 182 PlayItem.prototype.song = function() { 183 if ( !this.type == "song") { alert("Bug: song called on playitem "+this._id+" which has type ["+this.type+"]"); }183 if (this.type() != "song") { alert("Bug: song called on playitem "+this._id+" which has type ["+this.type+"]"); } 184 184 var songlist = doSQL("SELECT song.id, song_key, title, first_line, xml FROM song WHERE id = "+this._song, Song); 185 185 if (songlist.length < 1 ) { alert("Retrieving song not in database: has it been deleted?"); } … … 194 194 fallback: function () { return "<p>[Don't know how to transform object of type "+this.type+"]</p>" } 195 195 }, 196 postDisplayHook: { 197 // song: function () { return this.song().played() }, 198 fallback: function () {} 199 }, 196 200 title: { 197 201 song: function () { return this.song().title() }, chrome/songbee/songbee.js
r26 r31 10 10 var state = { 11 11 paused: 0, 12 current SongIndex: 0,12 currentItemIndex: 0, 13 13 currentSectionIndex: 0, 14 14 consoleColor: exposedColor, … … 26 26 // Utility functions 27 27 28 function current Song() {29 if (state.current SongIndex < 0) { state.currentSongIndex = 0 }30 if (state.current SongIndex > plData.songs.length - 1) {31 state.current SongIndex = plData.songs.length - 1;32 } 33 return plData. songs[state.currentSongIndex];34 } 35 function next Song() { return plData.songs[state.currentSongIndex+1] }28 function currentItem() { 29 if (state.currentItemIndex < 0) { state.currentItemIndex = 0 } 30 if (state.currentItemIndex > plData.items.length - 1) { 31 state.currentItemIndex = plData.items.length - 1; 32 } 33 return plData.items[state.currentItemIndex]; 34 } 35 function nextItem() { return plData.items[state.currentItemIndex+1] } 36 36 function projectorSections() { return windows.projector.document.getElementById("song").getElementsByTagName("div") } 37 37 function consoleSections() {return windows.thisSong.contentDocument.getElementById("song").getElementsByTagName("div"); } … … 57 57 windows.console.addEventListener("keypress", onKeyPress, false); 58 58 plData.playlist = Playlist.retrieve(window.arguments[0]); 59 plData. songs = plData.playlist.songs(function(s) {59 plData.items = plData.playlist.items(function(s) { 60 60 var li = document.createElementNS(htmlNS, "html:li"); 61 61 var label = document.createElement("label"); 62 62 label.setAttribute("value", s.title()); 63 63 li.appendChild(label); 64 li.setAttribute("onclick", "switch Song("+c+")");64 li.setAttribute("onclick", "switchItem("+c+")"); 65 65 playlistLI.appendChild(li); 66 66 c++; … … 74 74 addUserStylesheet(windows.projector.document); 75 75 } 76 switch Song(0,1);77 } 78 79 function switch Song(s, firstTime) {80 state.current SongIndex = s;76 switchItem(0,1); 77 } 78 79 function switchItem(s, firstTime) { 80 state.currentItemIndex = s; 81 81 if (!firstTime) 82 82 unhighlightSection(); 83 display Song(currentSong());84 } 85 86 function display Song(song) {87 // Display songin browser windows88 put SongInDoc(song, windows.projector.document);83 displayItem(currentItem()); 84 } 85 86 function displayItem(item) { 87 // Display item in browser windows 88 putItemInDoc(item, windows.projector.document); 89 89 cleanProjectorWindow(); // Do this as quickly as possible 90 putSongInDoc(song, windows.thisSong.contentDocument); 91 putSongInDoc(nextSong(), windows.nextSong.contentDocument); 92 93 // Increment the counter 94 song.played(); 95 96 // Set up data structure for easy access 97 state.verses = []; 98 var cs = consoleSections(); 99 for (var i = 0; i < cs.length; i++) { 100 var section = cs[i]; 101 section.addEventListener("click", mkChangeSection(i), true); 102 if (section.className == "verse") { state.verses.push(i) } 103 } 104 // Set up the "natural order" 105 state.naturalOrder = determineNaturalOrder(song); 106 if (state.naturalOrder.length && state.naturalOrder[0] == 0) { state.naturalOrder.shift() } 107 //jsdump("Natural order was: "); 108 //for (var i in state.naturalOrder) { jsdump(state.naturalOrder[i]) }; 90 putItemInDoc(item, windows.thisSong.contentDocument); 91 putItemInDoc(nextItem(), windows.nextSong.contentDocument); 92 93 item.postDisplayHook(); 94 95 if (item.type() == "song") { 96 // Set up data structure for easy access 97 state.verses = []; 98 var cs = consoleSections(); 99 for (var i = 0; i < cs.length; i++) { 100 var section = cs[i]; 101 section.addEventListener("click", mkChangeSection(i), true); 102 if (section.className == "verse") { state.verses.push(i) } 103 } 104 // Set up the "natural order" 105 state.naturalOrder = determineNaturalOrder(item); 106 if (state.naturalOrder.length && state.naturalOrder[0] == 0) { state.naturalOrder.shift() } 107 //jsdump("Natural order was: "); 108 //for (var i in state.naturalOrder) { jsdump(state.naturalOrder[i]) }; 109 } 109 110 110 111 // Scroll things back to the beginnng … … 116 117 function mkChangeSection(i) { return function () { changeSection(i) } } 117 118 118 function put SongInDoc(song, doc) {119 function putItemInDoc(item, doc) { 119 120 var song_place = doc.getElementById("song"); 120 121 song_place.innerHTML = ""; 121 if (! song) { song_place.innerHTML="<p>End of playlist</p>"; return; }122 var frag = transformDOM(song.xmlDOM(),stylesheet, doc);122 if (!item) { song_place.innerHTML="<p>End of playlist</p>"; return; } 123 var frag = item.transformToHTML(stylesheet, doc); 123 124 song_place.appendChild(frag); 124 125 } … … 274 275 case e.DOM_VK_UP: handleUp(); return; 275 276 case e.DOM_VK_DOWN: handleDown(); return; 276 case e.DOM_VK_LEFT: switch Song(state.currentSongIndex-1); return;277 case e.DOM_VK_RIGHT: switch Song(state.currentSongIndex+1); return;277 case e.DOM_VK_LEFT: switchItem(state.currentItemIndex-1); return; 278 case e.DOM_VK_RIGHT: switchItem(state.currentItemIndex+1); return; 278 279 case e.DOM_VK_PAGE_DOWN: pageDown(); return; 279 280 case e.DOM_VK_PAGE_UP: pageUp(); return;
