4 * @module MultimediaPlayerApplication
8 * This class provides basic methods to operate with media content carousel (carouFredSel) like load and fill carousel with supplied audio content, scroll carousel to a given position, get current carousel position.
9 * Media content carousel represents a playlist of audio tracks and allows user to browse tracks by swiping to left (next track) or right (previous track). Each carousel's item contains thumbnail, artist name and title.
14 var Carousel = function() {
16 this.initializeSwipe();
19 * This property holds audio media content array that carousel is filled with.
20 * @property callHistory {Array}
23 Carousel.prototype.allMediaContent = [];
25 * This property holds carouFredSel object for internal use in carousel.
26 * @property swipe {Object}
29 Carousel.prototype.swipe = null;
31 * This property holds callback function which is called after current element/position in carousel is changed.
32 * @property indexChangeCallback {Object}
35 Carousel.prototype.indexChangeCallback = null;
37 * This method adds listener that will be called right after the carousel finished scrolling and current element/position is changed.
39 * @method addIndexChangeListener
40 * @param indexChangeCallback {function()} Callback function to be invoked when current element/position of carousel is changed.
42 Carousel.prototype.addIndexChangeListener = function(indexChangeCallback) {
45 this.indexChangeCallback = indexChangeCallback;
49 * Initializes and configures carouFredSel carousel object.
51 * @method initializeSwipe
54 Carousel.prototype.initializeSwipe = function() {
59 this.swipe = $('#carouselList').carouFredSel({
76 onAfter : function(data) {
77 if (!!self.indexChangeCallback) {
78 self.indexChangeCallback(self.getCurrentPosition());
83 if (!this.swipe.length) {
90 * Gets the position of selected carousel item.
92 * @method getCurrentPosition
94 Carousel.prototype.getCurrentPosition = function() {
98 var pos = parseInt(self.swipe.triggerHandler("currentPosition"), 10);
105 * Scrolls the carousel to given index.
108 * @param index {Integer} New position to be scrolled to.
110 Carousel.prototype.slideTo = function(index) {
112 if (!!this.swipe && index >= 0 && index < this.allMediaContent.length) {
113 this.swipe.trigger("slideTo", index);
117 * This method fills carousel with audio media content and scrolls immediately the carousel to the designated position.
119 * @method loadMediaContent
120 * @param allMediaContent {Array} Audio media content array to be filled in the carousel.
121 * @param index {Integer} Position to be scrolled to.
123 Carousel.prototype.loadMediaContent = function(allMediaContent, index) {
125 this.removeAllItems();
126 this.allMediaContent = allMediaContent;
127 this.insertPagesToSwipe();
128 if (index >= 0 && index < this.allMediaContent.length && !!this.swipe) {
129 this.swipe.trigger("slideTo", [ index, 0, {
136 * Creates an HTML snippet representing one carousel item to be inserted into the carousel.
138 * @method createSwipeItem
139 * @param mediaItem {Object} Object representing audio media item's information.
140 * @param index {Integer} Position of item in carousel used to identify supplied audio media item's HTML DOM representation.
141 * @return {Object} jQuery DOM object representation of audio media item.
144 Carousel.prototype.createSwipeItem = function(mediaItem, index) {
149 var thumbnail = Utils.getThumbnailPath(mediaItem);
150 var artist = Utils.getArtistName(mediaItem);
151 var album = Utils.getAlbumName(mediaItem);
152 var title = Utils.getMediaItemTitle(mediaItem);
154 carouselItem = '<li><div id="item_' + index + '" class="carouselItem">';
155 carouselItem += '<img class="carouselImage albumThumbnail carouselImageReflect" src="' + thumbnail + '" alt="">';
156 carouselItem += '<div class="albumCarouselDescription">';
157 carouselItem += '<div class="albumCarouselDescriptionText oneLineEllipsis fontColorNormal fontSizeLarge fontWeightBold">' + artist + '</div>';
158 carouselItem += '<div class="albumCarouselDescriptionText twoLinesEllipsis fontColorDimmedLight fontSizeXSmall fontWeightBold">' + title + '</div>';
159 carouselItem += '</div>';
160 carouselItem += '</div></li>';
162 carouselItem = $(carouselItem);
170 * Inserts new carousel item into carousel.
172 * @method insertPagesToSwipe
175 Carousel.prototype.insertPagesToSwipe = function() {
179 var clickHandler = function() {
180 self.swipe.trigger("slideTo", [ $(this), -1 ]);
183 for ( var index = this.allMediaContent.length - 1; index >= 0; --index) {
184 carouselItem = this.createSwipeItem(this.allMediaContent[index], index);
185 if (!!carouselItem && !!this.swipe) {
186 this.swipe.trigger("insertItem", [ carouselItem, 0 ]);
187 carouselItem.click(clickHandler);
190 this.addCarouselEdges();
194 * Removes all items from the carousel.
196 * @method removeAllItems
198 Carousel.prototype.removeAllItems = function() {
203 for ( var index = this.allMediaContent.length + 1; index >= 0; --index) {
204 this.swipe.trigger("removeItem", index);
210 * Adds emty carousel items to the beginning and the end of the carousel
211 * (to make sure first and last visible items appear in the middle of screen instead of at the edges when swiped to edges of carousel).
212 * @method addCarouselEdges
214 Carousel.prototype.addCarouselEdges = function() {
217 var html = "<li><div class='carouselItem'></div></li>";
218 this.swipe.trigger("insertItem", [ html, 0 ]);
219 this.swipe.trigger("insertItem", [ html, "end", true ]);