You are here

src_minplayer.flags.js.html in HTML5 Media 7

  1 /** The minplayer namespace. */
  2 var minplayer = minplayer || {};
  3 
  4 /**
  5  * @constructor
  6  * @class This is a class used to keep track of flag states
  7  * which is used to control the busy cursor, big play button, among other
  8  * items in which multiple components can have an interest in hiding or
  9  * showing a single element on the screen.
 10  *
 11  * <p>
 12  * <strong>Usage:</strong>
 13  * <pre><code>
 14  *   // Declare a flags variable.
 15  *   var flags = new minplayer.flags();
 16  *
 17  *   // Set the flag based on two components interested in the flag.
 18  *   flags.setFlag("component1", true);
 19  *   flags.setFlag("component2", true);
 20  *
 21  *   // Print out the value of the flags. ( Prints 3 )
 22  *   console.log(flags.flags);
 23  *
 24  *   // Now unset a single components flag.
 25  *   flags.setFlag("component1", false);
 26  *
 27  *   // Print out the value of the flags.
 28  *   console.log(flags.flags);
 29  *
 30  *   // Unset the other components flag.
 31  *   flags.setFlag("component2", false);
 32  *
 33  *   // Print out the value of the flags.
 34  *   console.log(flags.flags);
 35  * </code></pre>
 36  * </p>
 37  */
 38 minplayer.flags = function() {
 39 
 40   /** The flag. */
 41   this.flag = 0;
 42 
 43   /** Id map to reference id with the flag index. */
 44   this.ids = {};
 45 
 46   /** The number of flags. */
 47   this.numFlags = 0;
 48 };
 49 
 50 /**
 51  * Sets a flag based on boolean logic operators.
 52  *
 53  * @param {string} id The id of the controller interested in this flag.
 54  * @param {boolean} value The value of this flag ( true or false ).
 55  */
 56 minplayer.flags.prototype.setFlag = function(id, value) {
 57 
 58   // Define this id if it isn't present.
 59   if (!this.ids.hasOwnProperty(id)) {
 60     this.ids[id] = this.numFlags;
 61     this.numFlags++;
 62   }
 63 
 64   // Use binary operations to keep track of the flag state
 65   if (value) {
 66     this.flag |= (1 << this.ids[id]);
 67   }
 68   else {
 69     this.flag &= ~(1 << this.ids[id]);
 70   }
 71 };
 72 

File

player/doc/symbols/src/src_minplayer.flags.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 is a class used to keep track of flag states
<span class='line'>  7</span>  * which is used to control the busy cursor, big play button, among other
<span class='line'>  8</span>  * items in which multiple components can have an interest in hiding or
<span class='line'>  9</span>  * showing a single element on the screen.
<span class='line'> 10</span>  *
<span class='line'> 11</span>  * &lt;p>
<span class='line'> 12</span>  * &lt;strong>Usage:&lt;/strong>
<span class='line'> 13</span>  * &lt;pre>&lt;code>
<span class='line'> 14</span>  *   // Declare a flags variable.
<span class='line'> 15</span>  *   var flags = new minplayer.flags();
<span class='line'> 16</span>  *
<span class='line'> 17</span>  *   // Set the flag based on two components interested in the flag.
<span class='line'> 18</span>  *   flags.setFlag("component1", true);
<span class='line'> 19</span>  *   flags.setFlag("component2", true);
<span class='line'> 20</span>  *
<span class='line'> 21</span>  *   // Print out the value of the flags. ( Prints 3 )
<span class='line'> 22</span>  *   console.log(flags.flags);
<span class='line'> 23</span>  *
<span class='line'> 24</span>  *   // Now unset a single components flag.
<span class='line'> 25</span>  *   flags.setFlag("component1", false);
<span class='line'> 26</span>  *
<span class='line'> 27</span>  *   // Print out the value of the flags.
<span class='line'> 28</span>  *   console.log(flags.flags);
<span class='line'> 29</span>  *
<span class='line'> 30</span>  *   // Unset the other components flag.
<span class='line'> 31</span>  *   flags.setFlag("component2", false);
<span class='line'> 32</span>  *
<span class='line'> 33</span>  *   // Print out the value of the flags.
<span class='line'> 34</span>  *   console.log(flags.flags);
<span class='line'> 35</span>  * &lt;/code>&lt;/pre>
<span class='line'> 36</span>  * &lt;/p>
<span class='line'> 37</span>  */</span><span class="WHIT">
<span class='line'> 38</span> </span><span class="NAME">minplayer.flags</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'> 39</span> 
<span class='line'> 40</span> </span><span class="WHIT">  </span><span class="COMM">/** The flag. */</span><span class="WHIT">
<span class='line'> 41</span> </span><span class="WHIT">  </span><span class="NAME">this.flag</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 42</span> 
<span class='line'> 43</span> </span><span class="WHIT">  </span><span class="COMM">/** Id map to reference id with the flag index. */</span><span class="WHIT">
<span class='line'> 44</span> </span><span class="WHIT">  </span><span class="NAME">this.ids</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'> 45</span> 
<span class='line'> 46</span> </span><span class="WHIT">  </span><span class="COMM">/** The number of flags. */</span><span class="WHIT">
<span class='line'> 47</span> </span><span class="WHIT">  </span><span class="NAME">this.numFlags</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 48</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 49</span> 
<span class='line'> 50</span> </span><span class="COMM">/**
<span class='line'> 51</span>  * Sets a flag based on boolean logic operators.
<span class='line'> 52</span>  *
<span class='line'> 53</span>  * @param {string} id The id of the controller interested in this flag.
<span class='line'> 54</span>  * @param {boolean} value The value of this flag ( true or false ).
<span class='line'> 55</span>  */</span><span class="WHIT">
<span class='line'> 56</span> </span><span class="NAME">minplayer.flags.prototype.setFlag</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">id</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">value</span><span class="PUNC">)</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">// Define this id if it isn't present.</span><span class="WHIT">
<span class='line'> 59</span> </span><span class="WHIT">  </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">this.ids.hasOwnProperty</span><span class="PUNC">(</span><span class="NAME">id</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 60</span> </span><span class="WHIT">    </span><span class="NAME">this.ids</span><span class="PUNC">[</span><span class="NAME">id</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">this.numFlags</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 61</span> </span><span class="WHIT">    </span><span class="NAME">this.numFlags</span><span class="PUNC">++</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 62</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 63</span> 
<span class='line'> 64</span> </span><span class="WHIT">  </span><span class="COMM">// Use binary operations to keep track of the flag state</span><span class="WHIT">
<span class='line'> 65</span> </span><span class="WHIT">  </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">value</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 66</span> </span><span class="WHIT">    </span><span class="NAME">this.flag</span><span class="WHIT"> </span><span class="PUNC">|</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NUMB">1</span><span class="WHIT"> </span><span class="PUNC">&lt;&lt;</span><span class="WHIT"> </span><span class="NAME">this.ids</span><span class="PUNC">[</span><span class="NAME">id</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 67</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 68</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'> 69</span> </span><span class="WHIT">    </span><span class="NAME">this.flag</span><span class="WHIT"> </span><span class="PUNC">&</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">~</span><span class="PUNC">(</span><span class="NUMB">1</span><span class="WHIT"> </span><span class="PUNC">&lt;&lt;</span><span class="WHIT"> </span><span class="NAME">this.ids</span><span class="PUNC">[</span><span class="NAME">id</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 70</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 71</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 72</span> </span></pre></body></html>