Add Modello web sample applications; version up
[profile/ivi/sdk/web-sample-build.git] / samples / web / Sample / Tizen / Web App / Modello_Multimediaplayer / project / components / timeProgressBar / timeProgressBar.js
1 //audio time progress bar JQuery Plugin
2 /**
3  * @module MultimediaPlayerApplication
4  */
5 (function ($) {
6         "use strict";
7         /**
8          * Class which provides methods to fill content of time progress bar for JQuery plugin.
9          * @class TimeProgressBarObj
10          * @static
11          */
12         var TimeProgressBarObj = {
13                         /**
14                          * Holds current object of this JQuery plugin.
15                          * @property thisObj {Object}
16                          */
17                         thisObj: null,
18                         /**
19                          * Holds current object of position indicator.
20                          * @property positionIndicator {Object}
21                          */
22                         positionIndicator: null,
23                         /**
24                          * Holds current text of top right caption.
25                          * @property rightText {String}
26                          */
27                         rightText: null,
28                         /**
29                          * Holds current text of top left caption.
30                          * @property leftText {String}
31                          */
32                         leftText: null,
33                         /**
34                          * Holds current count of songs in playlist.
35                          * @property count {Integer}
36                          */
37                         count: 0,
38                         /**
39                          * Holds current index of song from playlist.
40                          * @property index {Integer}
41                          */
42                         index: 0,
43                         /**
44                          * Holds current estimation of song from playlist.
45                          * @property estimation {String}
46                          */
47                         estimation: "",
48                         /**
49                          * Holds current position of song from playlist.
50                          * @property position {Integer}
51                          */
52                         position: 0,
53                         /**
54                          * Method is initializing time progress bar.
55                          * @method init
56                          */
57                         init: function () {
58                                 this.empty();
59                                 this.append('<div id="songIndex" class="leftText fontColorNormal fontSizeLarge fontWeightBold">' +
60                                                 '0/0' +
61                                                 '</div>' +
62                                                 '<div id="songTime" class="rightText fontColorTheme fontSizeLarge fontWeightBold">' +
63                                                 '-0:00' +
64                                                 '</div>' +
65                                                 '<div id="songProgress" class="progressBar borderColorTheme">' +
66                                                 '<div id="songSeek"     class="progressPot bgColorTheme boxShadow3"></div>' +
67                                         '</div>');
68
69                                 TimeProgressBarObj.positionIndicator = $('#songProgress #songSeek');
70                                 TimeProgressBarObj.leftText = $('#songIndex');
71                                 TimeProgressBarObj.rightText = $('#songTime');
72                                 TimeProgressBarObj.positionIndicator.css({width: '0 %'});
73                                 TimeProgressBarObj.thisObj = this;
74
75                                 $("#songProgress").click(function (e) {
76                                         var elWidth = $(this).width(),
77                                                 parentOffset = $(this).parent().offset(),
78                                                 relativeXPosition = (e.pageX - parentOffset.left), //offset -> method allows you to retrieve the current position of an element 'relative' to the document
79                                                 progress = 0.00;
80                                         if (elWidth > 0) {
81                                                 progress = relativeXPosition / elWidth;
82                                         }
83                                         TimeProgressBarObj.thisObj.trigger('positionChanged', {position: (progress * 100)});
84                                 });
85                         },
86                         /**
87                          * Method is rendering position bar and position information from song.
88                          * @method show
89                          */
90                         show: function (objSong) {
91                                 $("#songIndex").empty();
92                                 $("#songIndex").append(objSong.index + '/' + objSong.count);
93                                 $("#songTime").empty();
94                                 $("#songTime").append(objSong.estimation);
95                                 TimeProgressBarObj.count = objSong.count;
96                                 TimeProgressBarObj.index = objSong.index;
97                                 TimeProgressBarObj.estimation = objSong.estimation;
98                                 TimeProgressBarObj.positionIndicator.css({width:  objSong.position + '%'});
99                                 TimeProgressBarObj.position = objSong.position;
100                         }
101                 };
102         /**
103          * Class which provides acces to TimeProgressBarObj methods.
104          * @class timeProgressBar
105          * @constructor
106          * @param method {Object} Identificator (name) of method.
107          * @return Result of called method.
108          */
109         $.fn.timeProgressBar = function (method) {
110                 // Method calling logic
111                 if (TimeProgressBarObj[method]) {
112                         return TimeProgressBarObj[method].apply(this, Array.prototype.slice.call(arguments, 1));
113                 } else if (typeof method === 'object' || !method) {
114                         return TimeProgressBarObj.init.apply(this, arguments);
115                 } else {
116                         $.error('Method ' +  method + ' does not exist on jQuery.infoPanelAPI');
117                 }
118         };
119 }(jQuery));