当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript chat.ChatCtrl类代码示例

本文整理汇总了TypeScript中chat.ChatCtrl的典型用法代码示例。如果您正苦于以下问题:TypeScript ChatCtrl类的具体用法?TypeScript ChatCtrl怎么用?TypeScript ChatCtrl使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ChatCtrl类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: function

export default function(opts: RoundOpts, element: HTMLElement): void {
  const data: RoundData = opts.data;
  li.openInMobileApp(data.game.id);
  let round: RoundApi, chat: ChatCtrl | undefined;
  if (data.tournament) $('body').data('tournament-id', data.tournament.id);
  li.socket = li.StrongSocket(
    data.url.socket,
    data.player.version, {
      options: { name: 'round' },
      params: { userTv: data.userTv && data.userTv.id },
      receive(t: string, d: any) { round.socketReceive(t, d); },
      events: {
        crowd(e: { watchers: number }) {
          $watchers.watchers("set", e.watchers);
        },
        tvSelect(o: any) {
          if (data.tv && data.tv.channel == o.channel) li.reload();
          else $('#tv_channels a.' + o.channel + ' span').html(
            o.player ? [
              o.player.title,
              o.player.name,
              '(' + o.player.rating + ')'
            ].filter(x => x).join('&nbsp') : 'Anonymous');
        },
        end() {
          $.ajax({
            url: [(data.tv ? '/tv/'  + data.tv.channel : ''), data.game.id, data.player.color, 'sides'].join('/'),
            success: function(html) {
              const $html = $(html);
              $('#site_header div.side').replaceWith($html.find('.side'));
              $('#lichess div.crosstable').replaceWith($html.find('.crosstable'));
              li.pubsub.emit('content_loaded')();
              startTournamentClock();
            }
          });
        },
        tourStanding(s: TourPlayer[]) {
          if (opts.chat && opts.chat.plugin && chat) {
            (opts.chat.plugin as TourStandingCtrl).set(s);
            chat.redraw();
          }
        }
      }
    });

  function startTournamentClock() {
    $("div.game_tournament div.clock").each(function(this: HTMLElement) {
      $(this).clock({
        time: parseFloat($(this).data("time"))
      });
    });
  };
  function getPresetGroup(d: RoundData) {
    if (d.player.spectator) return;
    if (d.steps.length < 4) return 'start';
    else if (d.game.status.id >= 30) return 'end';
    return;
  };
  opts.element = element.querySelector('.round') as HTMLElement;
  opts.socketSend = li.socket.send;
  if (!opts.tour && !data.simul) opts.onChange = (d: RoundData) => {
    if (chat) chat.preset.setGroup(getPresetGroup(d));
  };
  opts.crosstableEl = element.querySelector('.crosstable') as HTMLElement;

  let $watchers: JQuery;
  function letsGo() {
    round = (window['LichessRound'] as RoundMain).app(opts);
    if (opts.chat) {
      if (opts.tour) {
        opts.chat.plugin = tourStandingCtrl(opts.tour, opts.i18n.standing);
        opts.chat.alwaysEnabled = true;
      } else if (!data.simul) {
        opts.chat.preset = getPresetGroup(opts.data);
        opts.chat.parseMoves = true;
      }
      li.makeChat('chat', opts.chat, function(c) {
        chat = c;
      });
    }
    $watchers = $('#site_header div.watchers').watchers();
    startTournamentClock();
    $('#now_playing').find('.move_on input').change(function() {
      round.moveOn.toggle();
    }).prop('checked', round.moveOn.get()).on('click', 'a', function() {
      li.hasToReload = true;
      return true;
    });
    $('#now_playing').find('.zen input').change(function() {
      li.loadCss('/assets/stylesheets/zen.css');
      $('body').toggleClass('zen');
    });
    if (location.pathname.lastIndexOf('/round-next/', 0) === 0)
      history.replaceState(null, '', '/' + data.game.id);
    if (!data.player.spectator && data.game.status.id < 25) li.topMenuIntent();
  };
  if (window.navigator.userAgent.indexOf('Trident/') > -1) setTimeout(letsGo, 150);
  else letsGo();
}
开发者ID:lexisvar,项目名称:lila,代码行数:99,代码来源:boot.ts

示例2: function

export default function(opts: RoundOpts): void {
  const li = window.lichess;
  const element = document.querySelector('.round__app') as HTMLElement,
  data: RoundData = opts.data;
  let round: RoundApi, chat: ChatCtrl | undefined;
  if (data.tournament) $('body').data('tournament-id', data.tournament.id);
  li.socket = li.StrongSocket(
    data.url.socket,
    data.player.version, {
      options: { name: 'round' },
      params: { userTv: data.userTv && data.userTv.id },
      receive(t: string, d: any) { round.socketReceive(t, d); },
      events: {
        tvSelect(o: any) {
          if (data.tv && data.tv.channel == o.channel) li.reload();
          else $('.tv-channels .' + o.channel + ' .champion').html(
            o.player ? [
              o.player.title,
              o.player.name,
              '(' + o.player.rating + ')'
            ].filter(x => x).join('&nbsp') : 'Anonymous');
        },
        end() {
          $.ajax({
            url: [(data.tv ? '/tv' : ''), data.game.id, data.player.color, 'sides'].join('/'),
            success: function(html) {
              const $html = $(html), $meta = $html.find('.game__meta');
              $meta.length && $('.game__meta').replaceWith($meta);
              $('.crosstable').replaceWith($html.find('.crosstable'));
              li.pubsub.emit('content_loaded')();
            }
          });
        },
        tourStanding(s: TourPlayer[]) {
          if (opts.chat && opts.chat.plugin && chat) {
            (opts.chat.plugin as TourStandingCtrl).set(s);
            chat.redraw();
          }
        }
      }
    });

  function startTournamentClock() {
    $('.game__tournament .clock').each(function(this: HTMLElement) {
      $(this).clock({
        time: parseFloat($(this).data('time'))
      });
    });
  };
  function getPresetGroup(d: RoundData) {
    if (d.player.spectator) return;
    if (d.steps.length < 4) return 'start';
    else if (d.game.status.id >= 30) return 'end';
    return;
  };
  opts.element = element;
  opts.socketSend = li.socket.send;
  if (!opts.tour && !data.simul) opts.onChange = (d: RoundData) => {
    if (chat) chat.preset.setGroup(getPresetGroup(d));
  };

  round = (window['LichessRound'] as RoundMain).app(opts);
  if (opts.chat) {
    if (opts.tour) {
      opts.chat.plugin = tourStandingCtrl(opts.tour, opts.i18n.standing);
      opts.chat.alwaysEnabled = true;
    } else if (!data.simul) {
      opts.chat.preset = getPresetGroup(opts.data);
      opts.chat.parseMoves = true;
    }
    li.makeChat(opts.chat, function(c) {
      chat = c;
    });
  }
  startTournamentClock();
  $('.round__now-playing .move-on input')
  .change(round.moveOn.toggle)
  .prop('checked', round.moveOn.get())
  .on('click', 'a', function() {
    li.hasToReload = true;
    return true;
  });
  if (location.pathname.lastIndexOf('/round-next/', 0) === 0)
  history.replaceState(null, '', '/' + data.game.id);
  $('#zentog').click(li.pubsub.emit('zen'));
  li.storage.make('reload-round-tabs').listen(li.reload);
}
开发者ID:ornicar,项目名称:lila,代码行数:87,代码来源:boot.ts


注:本文中的chat.ChatCtrl类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。