Changeset 24714 for lang/javascript

Show
Ignore:
Timestamp:
11/24/08 04:58:47 (4 years ago)
Author:
anekos
Message:

トグルボタンの実装を変更

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/javascript/vimperator-plugins/trunk/stella.js

    r24713 r24714  
    3030  *********************************************************************************/ 
    3131 
    32   const ID_PREFIX = 'ank-nico-status-'; 
    33  
     32  const ID_PREFIX = 'anekos-stela-'; 
     33 
     34  // }}} 
    3435 
    3536  /********************************************************************************* 
     
    6970  Player.ST_OTHER   = 'other'; 
    7071 
    71   // rwx で機能の有無を表す 
     72  // rwxt で機能の有無を表す 
     73  // r = read 
     74  // w = write 
     75  // x = function 
     76  // t = toggle 
    7277  Player.prototype = { 
    7378    functions: { 
     
    8186    }, 
    8287 
     88    icon: null, 
     89 
    8390    initialize: function () void null, 
    84  
    85     icon: null, 
    8691 
    8792    get currentTime () undefined, 
     
    97102    is: function (state) (this.state == state), 
    98103 
    99     has: function (name, ms) !Array.some(ms, function (m) this.functions[name].indexOf(m) < 0), 
     104    has: function (name, ms) 
     105            let (f = this.functions[name]) 
     106              (f && !Array.some(ms, function (m) f.indexOf(m) < 0)), 
    100107 
    101108    playOrPause: function () { 
     
    134141  }; 
    135142 
    136  
    137   /********************************************************************************* 
    138   * YouTubePlayer                                                                   {{{ 
     143  // }}} 
     144 
     145  /********************************************************************************* 
     146  * YouTubePlayer                                                                {{{ 
    139147  *********************************************************************************/ 
    140148 
     
    152160      play: 'x', 
    153161      pause: 'x', 
    154       muted: 'rw', 
     162      muted: 'rwt', 
    155163      repeating: 'rw', 
    156164    }, 
     165 
     166    toggles: ['muted'], 
    157167 
    158168    icon: 'http://www.youtube.com/favicon.ico', 
     
    213223      play: 'x', 
    214224      pause: 'x', 
    215       muted: 'rw', 
    216       repeating: 'rw', 
    217       comment: 'rw' 
     225      muted: 'rwt', 
     226      repeating: 'rwt', 
     227      comment: 'rwt' 
    218228    }, 
    219229 
     
    272282 
    273283  /********************************************************************************* 
    274   * ContextMenu 
     284  * ContextMenu                                                                  {{{ 
    275285  *********************************************************************************/ 
    276286 
     
    334344 
    335345  /********************************************************************************* 
    336   * NicoStatusLine                                                               {{{ 
    337   *********************************************************************************/ 
    338  
    339   function NicoStatusLine () { 
     346  * Stella                                                                       {{{ 
     347  *********************************************************************************/ 
     348 
     349  function Stella () { 
    340350    this.initialize.apply(this, arguments); 
    341351  } 
    342352 
    343   NicoStatusLine.MAIN_PANEL_ID  = ID_PREFIX + 'panel', 
    344   NicoStatusLine.MAIN_MENU_ID   = ID_PREFIX + 'main-menu', 
    345   NicoStatusLine.VOLUME_MENU_ID = ID_PREFIX + 'volume-menu', 
    346  
    347   NicoStatusLine.prototype = { 
     353  Stella.MAIN_PANEL_ID  = ID_PREFIX + 'panel', 
     354  Stella.MAIN_MENU_ID   = ID_PREFIX + 'main-menu', 
     355  Stella.VOLUME_MENU_ID = ID_PREFIX + 'volume-menu', 
     356 
     357  Stella.prototype = { 
    348358    // new 時に呼ばれる 
    349359    initialize: function () { 
     
    406416      } 
    407417 
     418      function createLabel (store, name, l, r) { 
     419          let label = store[name] = document.createElement('label'); 
     420          label.setAttribute('value', '-'); 
     421          label.style.marginLeft = (l || 0) + 'px'; 
     422          label.style.marginRight = (r || 0) + 'px'; 
     423          label.__defineGetter__('text', function () this.getAttribute('value')); 
     424          label.__defineSetter__('text', function (v) this.setAttribute('value', v)); 
     425          setClickEvent(name, label); 
     426      } 
     427 
    408428      let panel = this.panel = document.createElement('statusbarpanel'); 
    409429      panel.setAttribute('id', this.panelId); 
     
    418438 
    419439      let labels = this.labels = {}; 
    420       ['main', 'volume', 'comment', 'repeat'].forEach(function (name, index) { 
    421         let label = labels[name] = document.createElement('label'); 
    422         label.setAttribute('value', '-'); 
    423         label.style.marginLeft = (index < 2 ? 2 : 0) + 'px'; 
    424         (index < 3) && (label.style.marginRight = '0px'); 
    425         setClickEvent(name, label); 
    426       }); 
     440      let toggles = this.toggles = {}; 
     441      createLabel(labels, 'main', 2, 2); 
     442      createLabel(labels, 'volume', 0, 2); 
     443      for each (let player in this.players) { 
     444        for (let func in player.functions) { 
     445          if (player.has(func, 't')) 
     446            (func in labels) || createLabel(toggles, func); 
     447        } 
     448      } 
    427449 
    428450      panel.appendChild(hbox); 
    429451      hbox.appendChild(icon); 
    430452      [hbox.appendChild(label) for each (label in labels)]; 
     453      [hbox.appendChild(toggle) for each (toggle in toggles)]; 
    431454 
    432455      let menu = this.mainMenu = buildContextMenu({ 
    433         id: NicoStatusLine.MAIN_MENU_ID, 
     456        id: Stella.MAIN_MENU_ID, 
    434457        parent: panel, 
    435458        set: hbox, 
     
    438461      }); 
    439462 
    440       let volMenu = this.volumeMenu = buildContextMenu({ 
    441         id: NicoStatusLine.VOLUME_MENU_ID, 
    442         parent: panel, 
    443         set: labels.volume, 
    444         tree: ContextMenuVolume, 
    445         onAppend: function (elem, menu) setClickEvent(capitalize(menu.name), elem) 
    446       }); 
    447  
    448       labels.volume.setAttribute('context', volMenu.id); 
    449  
    450       liberator.log(menu.id) 
    451  
    452463      let stbar = document.getElementById('status-bar'); 
    453464      stbar.insertBefore(panel, document.getElementById('liberator-statusline').nextSibling); 
     
    460471    update: function () { 
    461472      try { 
    462         this.setLabelText('main', this.player.statusText); 
    463         this.setLabelText('comment', this.player.comment ? 'C' : 'c'); 
    464         this.setLabelText('repeat', this.player.repeating ? 'R' : 'r'); 
    465         this.setLabelText('volume', this.player.muted ? 'M' : this.player.volume); 
     473        this.labels.main.text       = this.player.statusText; 
     474        this.labels.volume.text     = this.player.volume; 
     475        this.toggles.comment.text   = this.player.comment ? 'C' : 'c'; 
     476        this.toggles.repeating.text = this.player.repeating ? 'R' : 'r'; 
     477        this.toggles.muted.text     = this.player.muted ? 'M' : 'm'; 
    466478      } catch (e) { 
    467479        liberator.log(e); 
     
    472484      this.hidden = false; 
    473485      this.icon.setAttribute('src', this.player.icon); 
    474       ['comment', 'repeat', 'volume'].forEach(bindr(this, function (name) { 
    475         this.labels[name].hidden = !this.player.functions[name]; 
    476       })); 
     486      for (let name in this.toggles) { 
     487        this.toggles[name].hidden = !this.player.has(name, 't'); 
     488      } 
    477489      if (!this.timerHandle) { 
    478490        this.timerHandle = setInterval(bindr(this, this.update), 500); 
     
    498510    onPauseClick: function () this.player.pause(), 
    499511 
    500     onVolumeClick: function (event) (this.player.muted = !this.player.muted), 
    501  
    502     onSetVolumeClick: function (event) (this.player.volume = event.target.getAttribute('volume')), 
     512    onMutedClick: function (event) (this.player.muted = !this.player.muted), 
     513 
     514    onSetMutedClick: function (event) (this.player.volume = event.target.getAttribute('volume')), 
    503515 
    504516    onCommentClick: function () (this.player.comment = !this.player.comment), 
    505517 
    506     onRepeatClick: function () (this.player.repeating = !this.player.repeating), 
     518    onRepeatingClick: function () (this.player.repeating = !this.player.repeating), 
    507519 
    508520    onMainClick: function (event) { 
     
    545557    if (nsl) { 
    546558      nsl.finalize(); 
    547       liberator.plugins.nico_statusline = new NicoStatusLine(); 
     559      liberator.plugins.nico_statusline = new Stella(); 
    548560    } else { 
    549561      window.addEventListener( 
     
    551563        function () { 
    552564          window.removeEventListener('DOMContentLoaded', arguments.callee, false); 
    553           liberator.plugins.nico_statusline = new NicoStatusLine(); 
     565          liberator.plugins.nico_statusline = new Stella(); 
    554566        }, 
    555567        false