src_minplayer.async.js.html in HTML5 Media 7
1 /** The minplayer namespace. */
2 var minplayer = minplayer || {};
3
4 /**
5 * @constructor
6 * @class This class keeps track of asynchronous get requests for certain
7 * variables within the player.
8 */
9 minplayer.async = function() {
10
11 /** The final value of this asynchronous variable. */
12 this.value = null;
13
14 /** The queue of callbacks to call when this value is determined. */
15 this.queue = [];
16 };
17
18 /**
19 * Retrieve the value of this variable.
20 *
21 * @param {function} callback The function to call when the value is determined.
22 * @param {function} pollValue The poll function to try and get the value every
23 * 1 second if the value is not set.
24 */
25 minplayer.async.prototype.get = function(callback, pollValue) {
26
27 // If the value is set, then immediately call the callback, otherwise, just
28 // add it to the queue when the variable is set.
29 if (this.value !== null) {
30 callback(this.value);
31 }
32 else {
33
34 // Add this callback to the queue.
35 this.queue.push(callback);
36 }
37 };
38
39 /**
40 * Sets the value of an asynchronous value.
41 *
42 * @param {void} val The value to set.
43 */
44 minplayer.async.prototype.set = function(val) {
45
46 // Set the value.
47 this.value = val;
48
49 // Get the callback queue length.
50 var i = this.queue.length;
51
52 // Iterate through all the callbacks and call them.
53 if (i) {
54 while (i--) {
55 this.queue[i](val);
56 }
57
58 // Reset the queue.
59 this.queue = [];
60 }
61 };
62
File
player/doc/symbols/src/src_minplayer.async.js.html
View source
<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"> <style>
.KEYW {color: #933;}
.COMM {color: #bbb; font-style: italic;}
.NUMB {color: #393;}
.STRN {color: #393;}
.REGX {color: #339;}
.line {border-right: 1px dotted #666; color: #666; font-style: normal;}
</style></head><body><pre><span class='line'> 1</span> <span class="COMM">/** The minplayer namespace. */</span><span class="WHIT">
<span class='line'> 2</span> </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">minplayer</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">minplayer</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 3</span>
<span class='line'> 4</span> </span><span class="COMM">/**
<span class='line'> 5</span> * @constructor
<span class='line'> 6</span> * @class This class keeps track of asynchronous get requests for certain
<span class='line'> 7</span> * variables within the player.
<span class='line'> 8</span> */</span><span class="WHIT">
<span class='line'> 9</span> </span><span class="NAME">minplayer.async</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 10</span>
<span class='line'> 11</span> </span><span class="WHIT"> </span><span class="COMM">/** The final value of this asynchronous variable. */</span><span class="WHIT">
<span class='line'> 12</span> </span><span class="WHIT"> </span><span class="NAME">this.value</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 13</span>
<span class='line'> 14</span> </span><span class="WHIT"> </span><span class="COMM">/** The queue of callbacks to call when this value is determined. */</span><span class="WHIT">
<span class='line'> 15</span> </span><span class="WHIT"> </span><span class="NAME">this.queue</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">[</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 16</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 17</span>
<span class='line'> 18</span> </span><span class="COMM">/**
<span class='line'> 19</span> * Retrieve the value of this variable.
<span class='line'> 20</span> *
<span class='line'> 21</span> * @param {function} callback The function to call when the value is determined.
<span class='line'> 22</span> * @param {function} pollValue The poll function to try and get the value every
<span class='line'> 23</span> * 1 second if the value is not set.
<span class='line'> 24</span> */</span><span class="WHIT">
<span class='line'> 25</span> </span><span class="NAME">minplayer.async.prototype.get</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">callback</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">pollValue</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 26</span>
<span class='line'> 27</span> </span><span class="WHIT"> </span><span class="COMM">// If the value is set, then immediately call the callback, otherwise, just</span><span class="WHIT">
<span class='line'> 28</span> </span><span class="WHIT"> </span><span class="COMM">// add it to the queue when the variable is set.</span><span class="WHIT">
<span class='line'> 29</span> </span><span class="WHIT"> </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">this.value</span><span class="WHIT"> </span><span class="PUNC">!==</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 30</span> </span><span class="WHIT"> </span><span class="NAME">callback</span><span class="PUNC">(</span><span class="NAME">this.value</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 31</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 32</span> </span><span class="WHIT"> </span><span class="KEYW">else</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 33</span>
<span class='line'> 34</span> </span><span class="WHIT"> </span><span class="COMM">// Add this callback to the queue.</span><span class="WHIT">
<span class='line'> 35</span> </span><span class="WHIT"> </span><span class="NAME">this.queue.push</span><span class="PUNC">(</span><span class="NAME">callback</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 36</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 37</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 38</span>
<span class='line'> 39</span> </span><span class="COMM">/**
<span class='line'> 40</span> * Sets the value of an asynchronous value.
<span class='line'> 41</span> *
<span class='line'> 42</span> * @param {void} val The value to set.
<span class='line'> 43</span> */</span><span class="WHIT">
<span class='line'> 44</span> </span><span class="NAME">minplayer.async.prototype.set</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">val</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 45</span>
<span class='line'> 46</span> </span><span class="WHIT"> </span><span class="COMM">// Set the value.</span><span class="WHIT">
<span class='line'> 47</span> </span><span class="WHIT"> </span><span class="NAME">this.value</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">val</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 48</span>
<span class='line'> 49</span> </span><span class="WHIT"> </span><span class="COMM">// Get the callback queue length.</span><span class="WHIT">
<span class='line'> 50</span> </span><span class="WHIT"> </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">this.queue.length</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 51</span>
<span class='line'> 52</span> </span><span class="WHIT"> </span><span class="COMM">// Iterate through all the callbacks and call them.</span><span class="WHIT">
<span class='line'> 53</span> </span><span class="WHIT"> </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">i</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 54</span> </span><span class="WHIT"> </span><span class="KEYW">while</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">i</span><span class="PUNC">--</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 55</span> </span><span class="WHIT"> </span><span class="NAME">this.queue</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="PUNC">(</span><span class="NAME">val</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 56</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 57</span>
<span class='line'> 58</span> </span><span class="WHIT"> </span><span class="COMM">// Reset the queue.</span><span class="WHIT">
<span class='line'> 59</span> </span><span class="WHIT"> </span><span class="NAME">this.queue</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">[</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 60</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 61</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 62</span> </span></pre></body></html>