(function ($) { this.Topbar = Backbone.View.extend({ events: { 'click a': 'click', 'click .username': 'clickUsername', 'click button': 'dispatchClickButton', 'dblclick button[name=openSounds]': 'toggleMute', 'dragstart .roomtab': 'dragStartRoom', 'dragend .roomtab': 'dragEndRoom', 'dragenter .roomtab': 'dragEnterRoom', 'dragover .roomtab': 'dragEnterRoom' }, initialize: function () { // April Fool's 2016 - Digimon Showdown // this.$el.html('
'); this.$el.html('
'); this.$tabbar = this.$('.maintabbar .inner'); // this.$sidetabbar = this.$('.sidetabbar'); this.$userbar = this.$('.userbar'); this.dragging = false; this.updateTabbar(); app.user.on('change', this.updateUserbar, this); this.updateUserbar(); }, // userbar updateUserbar: function () { var buf = ''; var name = ' ' + app.user.get('name'); var color = BattleLog.hashColor(app.user.get('userid')); if (!app.user.loaded) { buf = ''; } else if (app.user.get('named')) { buf = ' ' + BattleLog.escapeHTML(name) + ''; } else { buf = ''; } buf += ' '; this.$userbar.html(buf); }, login: function () { app.addPopup(LoginPopup); }, openSounds: function () { app.addPopup(SoundsPopup); }, openOptions: function () { app.addPopup(OptionsPopup); }, clickUsername: function (e) { e.preventDefault(); e.stopPropagation(); var name = $(e.currentTarget).data('name'); app.addPopup(UserPopup, {name: name, sourceEl: e.currentTarget}); }, toggleMute: function () { var muted = !Dex.prefs('mute'); Dex.prefs('mute', muted); BattleSound.setMute(muted); app.topbar.$('button[name=openSounds]').html(''); }, // tabbar renderRoomTab: function (room, id) { if (!room && id !== 'rooms') return ''; if (!id) id = room.id; var buf = '
  • Home
  • '; case 'teambuilder': return buf + '> Teambuilder'; case 'ladder': return buf + '> Ladder'; case 'battles': return buf + '> Battles'; case 'rooms': return buf + ' aria-label="Join chatroom">  '; case 'battle': var name = BattleLog.escapeHTML(room.title); var idChunks = id.substr(7).split('-'); var formatid; if (idChunks.length <= 1) { if (idChunks[0] === 'uploadedreplay') formatid = 'Uploaded Replay'; } else { formatid = idChunks[idChunks.length - 2]; } if (!name) { var p1 = (room.battle && room.battle.p1 && room.battle.p1.name) || ''; var p2 = (room.battle && room.battle.p2 && room.battle.p2.name) || ''; if (p1 && p2) { name = '' + BattleLog.escapeHTML(p1) + ' v. ' + BattleLog.escapeHTML(p2); } else if (p1 || p2) { name = '' + BattleLog.escapeHTML(p1) + BattleLog.escapeHTML(p2); } else { name = '(empty room)'; } } return buf + ' draggable="true">' + BattleLog.escapeFormat(formatid) + '' + name + ''); } if (app.rooms['']) app.rooms[''].updateRightMenu(); }, updateTabbarMini: function () { this.$('.logo').hide(); this.$('.maintabbar').addClass('minitabbar'); var notificationClass = ''; for (var i in app.rooms) { if (app.rooms[i] !== app.curRoom && app.rooms[i].notificationClass === ' notifying') notificationClass = ' notifying'; } var buf = ''; buf += ''; this.$tabbar.html(buf); if (app.rooms['']) app.rooms[''].updateRightMenu(); }, dispatchClickButton: function (e) { var target = e.currentTarget; if (target.name) { app.dismissingSource = app.dismissPopups(); app.dispatchingButton = target; e.preventDefault(); e.stopImmediatePropagation(); this[target.name](target.value, target, e); delete app.dismissingSource; delete app.dispatchingButton; } }, click: function (e) { if (e.cmdKey || e.metaKey || e.ctrlKey) return; e.preventDefault(); var $target = $(e.currentTarget); if ($target.hasClass('minilogo')) { app.addPopup(TabListPopup, {sourceEl: e.currentTarget}); return; } var id = $target.attr('href'); if (id.substr(0, app.root.length) === app.root) { id = id.substr(app.root.length); } if ($target.hasClass('closebutton')) { app.leaveRoom(id, e); } else { app.joinRoom(id); } }, closeRoom: function (roomid, button, e) { app.leaveRoom(roomid, e); }, tablist: function () { app.addPopup(TabListPopup); }, // drag and drop roomidOf: function (room) { return room.id; }, dragStartRoom: function (e) { var target = e.currentTarget; var dataTransfer = e.originalEvent.dataTransfer; var elWidth = $(e.currentTarget).outerWidth(); dataTransfer.effectAllowed = 'all'; // by default, Chrome displays links as a URL when dragging // this uses a hack to force it to drag the tab app.draggingOffsetX = Math.floor(elWidth / 2); app.draggingOffsetY = 18; dataTransfer.setDragImage(target, app.draggingOffsetX, app.draggingOffsetY); var roomRef = $(target).attr('href'); app.draggingRoomList = app.roomList.map(this.roomidOf).concat('|').concat(app.sideRoomList.map(this.roomidOf)); app.draggingLoc = app.draggingRoomList.indexOf(roomRef.slice(1)); if (app.draggingLoc < 0) { // can't drag return; } app.dragging = roomRef; app.draggingRoom = null; app.$dragging = null; var iPipe = app.draggingRoomList.indexOf('|'); app.draggingSideRoom = (app.draggingLoc > iPipe); setTimeout(function () { $(target).css('opacity', 0.5); }, 0); // console.log('dragstart: ' + app.dragging); }, dragEnterRoom: function (e) { if (!app.dragging || typeof app.dragging !== 'string') return; var roomid = $(e.currentTarget).attr('href').slice(1); if (app.dragging.slice(1) === roomid) return; var i = app.draggingRoomList.indexOf(roomid); var iPipe = app.draggingRoomList.indexOf('|'); if (iPipe < 0) return; // bug? if (!app.$dragging) { // the dragging element needs to stay in the DOM, or the dragEnd // event won't fire (at least when I tested in Chrome) app.$dragging = this.$('a.roomtab[href="' + app.dragging + '"]'); this.$el.append(app.$dragging); app.$dragging.hide(); } else if (app.draggingLastRoom === roomid) { if (app.draggingOffsetX > 0) { // dragged right, don't drag back if we're still going right if (e.originalEvent.pageX - app.draggingOffsetX >= -5) return; } else { // dragged left, don't drag back if we're still going left if (e.originalEvent.pageX + app.draggingOffsetX <= 5) return; } } if (roomid === 'rooms') i = app.draggingRoomList.length; if (i < 0) i = 0; var draggingRight = (i > app.draggingLoc); if (iPipe > app.draggingLoc && i > iPipe) draggingRight = false; app.draggingOffsetX = e.originalEvent.pageX * (draggingRight ? 1 : -1); app.draggingLastRoom = roomid; // remove tab from old position var room; if (app.draggingLoc < iPipe) { // old position is in left list room = app.roomList.splice(app.draggingLoc, 1)[0]; iPipe--; } else { // old position is in right list room = app.sideRoomList.splice(app.draggingLoc - iPipe - 1, 1)[0]; } if (app.draggingLoc < i) i--; // add tab to new position if (draggingRight) i++; // add after when dragging right if (i <= iPipe) { // insert into left list app.roomList.splice(i, 0, room); } else { // insert into right list app.sideRoomList.splice(i - iPipe - 1, 0, room); } app.draggingRoomList = app.roomList.map(this.roomidOf).concat('|').concat(app.sideRoomList.map(this.roomidOf)); app.draggingLoc = app.draggingRoomList.indexOf(app.dragging.slice(1)); this.updateTabbar(); this.$('a.roomtab[href="' + app.dragging + '"]').css('opacity', 0.5); // console.log('dragenter: /' + roomid); }, dragEndRoom: function (e) { if (!app.dragging) return; // console.log('dragend: ' + app.dragging); var room = app.rooms[app.dragging.slice(1)]; var iPipe = app.draggingRoomList.indexOf('|'); if (app.draggingLoc < iPipe && app.draggingSideRoom) { app.focusRoomLeft(room.id); } else if (app.draggingLoc > iPipe && !app.draggingSideRoom) { app.focusRoomRight(room.id); } else { this.updateTabbar(); } if (room.type === 'chat') app.updateAutojoin(); app.dragging = null; if (app.$dragging) app.$dragging.remove(); app.draggingRoomList = null; } }); var SoundsPopup = this.SoundsPopup = Popup.extend({ initialize: function (data) { var buf = ''; var muted = !!Dex.prefs('mute'); buf += '

    ' + (muted ? '(muted)' : '') + '

    '; buf += '

    ' + (muted ? '(muted)' : '') + '

    '; buf += '

    ' + (muted ? '(muted)' : '') + '

    '; buf += '

    '; this.$el.html(buf).css('min-width', 160); }, events: { 'change input[name=muted]': 'setMute', 'change input[type=range]': 'updateVolume', 'keyup input[type=range]': 'updateVolume', 'input input[type=range]': 'updateVolume' }, updateVolume: function (e) { var val = Number(e.currentTarget.value); switch (e.currentTarget.name) { case 'effectvolume': this.setEffectVolume(val); break; case 'musicvolume': this.setMusicVolume(val); break; case 'notifvolume': this.setNotifVolume(val); break; } }, setMute: function (e) { var muted = !!e.currentTarget.checked; Dex.prefs('mute', muted); BattleSound.setMute(muted); if (!muted) { this.$('.effect-volume').html(''); this.$('.music-volume').html(''); this.$('.notif-volume').html(''); } else { this.$('.effect-volume').html('(muted)'); this.$('.music-volume').html('(muted)'); this.$('.notif-volume').html('(muted)'); } app.topbar.$('button[name=openSounds]').html(''); }, setEffectVolume: function (volume) { BattleSound.setEffectVolume(volume); Dex.prefs('effectvolume', volume); }, setMusicVolume: function (volume) { BattleSound.setBgmVolume(volume); Dex.prefs('musicvolume', volume); }, setNotifVolume: function (volume) { Dex.prefs('notifvolume', volume); } }); var OptionsPopup = this.OptionsPopup = Popup.extend({ initialize: function (data) { app.user.on('change', this.update, this); app.send('/cmd userdetails ' + app.user.get('userid')); this.update(); }, events: { 'change input[name=noanim]': 'setNoanim', 'change input[name=nogif]': 'setNogif', 'change input[name=bwgfx]': 'setBwgfx', 'change input[name=nopastgens]': 'setNopastgens', 'change input[name=notournaments]': 'setNotournaments', 'change input[name=inchatpm]': 'setInchatpm', 'change input[name=dark]': 'setDark', 'change input[name=temporarynotifications]': 'setTemporaryNotifications', 'change select[name=bg]': 'setBg', 'change select[name=timestamps-lobby]': 'setTimestampsLobby', 'change select[name=timestamps-pms]': 'setTimestampsPMs', 'change select[name=onepanel]': 'setOnePanel', 'change input[name=logchat]': 'setLogChat', 'change input[name=selfhighlight]': 'setSelfHighlight', 'click img': 'avatars' }, update: function () { var name = app.user.get('name'); var avatar = app.user.get('avatar'); var buf = ''; buf += '

    ' + (avatar ? '' : '') + '' + BattleLog.escapeHTML(name) + '

    '; buf += '

    '; if (app.user.get('named')) { var registered = app.user.get('registered'); if (registered && (registered.userid === app.user.get('userid'))) { buf += '

    '; } else { buf += '

    '; } } buf += '
    '; buf += '

    Graphics

    '; var onePanel = !!Dex.prefs('onepanel'); if ($(window).width() >= 660) { buf += '

    '; } buf += '

    '; buf += '

    '; buf += '

    '; if (navigator.userAgent.includes(' Chrome/64.')) { buf += '

    '; } buf += '

    '; buf += '

    '; buf += '
    '; buf += '

    Chat

    '; buf += '

    '; buf += '

    '; buf += '

    '; if (window.Notification) { buf += '

    '; } var timestamps = this.timestamps = (Dex.prefs('timestamps') || {}); buf += '

    '; buf += '

    '; buf += '

    '; if (window.nodewebkit) { buf += '
    '; buf += '

    Desktop app

    '; buf += '

    '; buf += ''; } buf += '
    '; if (app.user.get('named')) { buf += '

    '; } else { buf += '

    '; } this.$el.html(buf).css('min-width', 160); }, openLogFolder: function () { Storage.revealFolder(); }, setLogChat: function (e) { var logchat = !!e.currentTarget.checked; if (logchat) { Storage.startLoggingChat(); $('#openLogFolderButton').show(); } else { Storage.stopLoggingChat(); } Dex.prefs('logchat', logchat); }, setNoanim: function (e) { var noanim = !!e.currentTarget.checked; Dex.prefs('noanim', noanim); Dex.loadSpriteData(noanim || Dex.prefs('bwgfx') ? 'bw' : 'xy'); }, setNogif: function (e) { var nogif = !!e.currentTarget.checked; Dex.prefs('nogif', nogif); Dex.loadSpriteData(nogif || Dex.prefs('bwgfx') ? 'bw' : 'xy'); }, setDark: function (e) { var dark = !!e.currentTarget.checked; Dex.prefs('dark', dark); $('html').toggleClass('dark', dark); }, setBwgfx: function (e) { var bwgfx = !!e.currentTarget.checked; Dex.prefs('bwgfx', bwgfx); Dex.loadSpriteData(bwgfx || Dex.prefs('noanim') ? 'bw' : 'xy'); }, setNopastgens: function (e) { var nopastgens = !!e.currentTarget.checked; Dex.prefs('nopastgens', nopastgens); }, setNotournaments: function (e) { var notournaments = !!e.currentTarget.checked; Dex.prefs('notournaments', notournaments); }, setSelfHighlight: function (e) { var noselfhighlight = !e.currentTarget.checked; Dex.prefs('noselfhighlight', noselfhighlight); }, setInchatpm: function (e) { var inchatpm = !!e.currentTarget.checked; Dex.prefs('inchatpm', inchatpm); }, setTemporaryNotifications: function (e) { var temporarynotifications = !!e.currentTarget.checked; Dex.prefs('temporarynotifications', temporarynotifications); }, background: function (e) { app.addPopup(CustomBackgroundPopup); }, setOnePanel: function (e) { app.singlePanelMode = !!e.currentTarget.value; Dex.prefs('onepanel', !!e.currentTarget.value); app.updateLayout(); }, setTimestampsLobby: function (e) { this.timestamps.lobby = e.currentTarget.value; Dex.prefs('timestamps', this.timestamps); }, setTimestampsPMs: function (e) { this.timestamps.pms = e.currentTarget.value; Dex.prefs('timestamps', this.timestamps); }, avatars: function () { app.addPopup(AvatarsPopup); }, formatting: function () { app.addPopup(FormattingPopup); }, login: function () { app.addPopup(LoginPopup); }, register: function () { app.addPopup(RegisterPopup); }, changepassword: function () { app.addPopup(ChangePasswordPopup); }, logout: function () { app.user.logout(); this.close(); } }); var FormattingPopup = this.FormattingPopup = Popup.extend({ events: { 'change input': 'setOption' }, initialize: function () { var cur = this.chatformatting = Dex.prefs('chatformatting') || {}; var buf = '

    Usable formatting:

    '; var ctrlPlus = '' + (navigator.platform === 'MacIntel' ? 'Cmd' : 'Ctrl') + ' + '; buf += '

    **bold** (' + ctrlPlus + 'B)

    '; buf += '

    __italics__ (' + ctrlPlus + 'I)

    '; buf += '

    ``code formatting``

    '; buf += '

    ~~strikethrough~~

    '; buf += '

    ^^superscript^^

    '; buf += '

    \\\\subscript\\\\

    '; buf += '

    '; buf += '

    '; buf += '

    '; buf += '

    '; buf += '

    '; buf += '

    '; this.$el.html(buf); }, setOption: function (e) { var name = $(e.currentTarget).prop('name'); this.chatformatting['hide' + name] = !!e.currentTarget.checked; Dex.prefs('chatformatting', this.chatformatting); } }); var AvatarsPopup = this.AvatarsPopup = Popup.extend({ type: 'semimodal', initialize: function () { var cur = +app.user.get('avatar'); var buf = ''; buf += '

    Choose an avatar or

    '; buf += '
    '; for (var i = 1; i <= 293; i++) { var offset = '-' + (((i - 1) % 16) * 80 + 1) + 'px -' + (Math.floor((i - 1) / 16) * 80 + 1) + 'px'; buf += ''; } buf += '
    '; buf += '

    '; this.$el.html(buf).css('max-width', 780); }, setAvatar: function (i) { app.send('/avatar ' + i); app.send('/cmd userdetails ' + app.user.get('userid')); Dex.prefs('avatar', i); this.close(); } }); var TabListPopup = this.TabListPopup = Popup.extend({ type: 'semimodal', renderRooms: function (rooms) { var buf = ''; for (var i = 0; i < rooms.length; i++) buf += app.topbar.renderRoomTab(rooms[i]); return buf; }, initialize: function () { var curId = (app.curRoom ? app.curRoom.id : ''); var curSideId = (app.curSideRoom ? app.curSideRoom.id : ''); var buf = ''; if (app.roomList.length) buf += this.renderRooms(app.roomList); var sideBuf = this.renderRooms(app.sideRoomList); sideBuf += '
  •  
  • '; if (sideBuf) { buf += ''; } this.$el.addClass('tablist').html(buf); }, events: { 'click a': 'click' }, closeRoom: function (roomid, button, e) { app.leaveRoom(roomid); this.initialize(); }, click: function (e) { if (e.cmdKey || e.metaKey || e.ctrlKey) return; e.preventDefault(); var $target = $(e.currentTarget); var id = $target.attr('href'); if (id.substr(0, app.root.length) === app.root) { id = id.substr(app.root.length); } if ($target.hasClass('closebutton')) { app.leaveRoom(id); this.initialize(); } else { this.close(); app.focusRoom(id); } } }); var CustomBackgroundPopup = this.CustomBackgroundPopup = Popup.extend({ events: { 'change input[name=bgfile]': 'setBgFile' }, initialize: function () { var buf = ''; var cur = Storage.bg.id; buf += '

    Default

    '; buf += '
    '; buf += ''; buf += '
    '; buf += '

    Official

    '; buf += '
    '; buf += ''; buf += ''; buf += ''; buf += ''; buf += ''; buf += ''; buf += '
    '; buf += '

    Custom

    '; buf += '

    Drag and drop an image to PS (the background settings don\'t need to be open), or upload:

    '; buf += '

    '; buf += '

    '; buf += '

    '; // April Fool's 2016 - background change disabling // buf = '

    Sorry, the background chooser is experiencing technical difficulties. Please try again tomorrow!

    '; this.$el.css('max-width', 448).html(buf); this.$el.html(buf); }, setBg: function (bgid) { var bgUrl = (bgid === 'solidblue' ? '#344b6c' : Dex.resourcePrefix + 'fx/client-bg-' + bgid + '.jpg'); Storage.bg.set(bgUrl, bgid); this.$('.cur').removeClass('cur'); this.$('button[value="' + bgid + '"]').addClass('cur'); }, setBgFile: function (e) { $('.bgstatus').text('Changing background image...'); var file = e.currentTarget.files[0]; CustomBackgroundPopup.readFile(file, this); } }); CustomBackgroundPopup.readFile = function (file, popup) { var reader = new FileReader(); reader.onload = function (e) { var noSave = false; if (String(e.target.result).length > 4200000) { if (popup) { $('.bgstatus').html('Image is too large and can\'t be saved. It should be under 3.5MB or so.'); } else { app.addPopupMessage("Image is too large and can't be saved. It should be under 3.5MB or so."); } noSave = true; } else if (popup) { $('.bgstatus').html('Saved'); popup.$('.cur').removeClass('cur'); } Storage.bg.set(e.target.result, 'custom', noSave); }; reader.readAsDataURL(file); }; var LoginPopup = this.LoginPopup = Popup.extend({ type: 'semimodal', initialize: function (data) { var buf = '
    '; if (data.error) { buf += '

    ' + BattleLog.escapeHTML(data.error) + '

    '; if (data.error.indexOf('inappropriate') >= 0) { buf += '

    Keep in mind these rules:

    '; buf += '
      '; buf += '
    1. Usernames may not impersonate a recognized user (a user with %, @, &, or ~ next to their name).
    2. '; buf += '
    3. Usernames may not be derogatory or insulting in nature, to an individual or group (insulting yourself is okay as long as it\'s not too serious).
    4. '; buf += '
    5. Usernames may not directly reference sexual activity, or be excessively disgusting.
    6. '; buf += '
    '; } } else if (data.reason) { buf += '

    ' + BattleLog.parseMessage(data.reason) + '

    '; } else if (!data.force) { var noRenameGames = ''; if (app.rooms[''].games) { for (var roomid in app.rooms[''].games) { var title = app.rooms[''].games[roomid]; if (title.slice(-1) === '*') { noRenameGames += '
  • ' + BattleLog.escapeHTML(title.slice(0, -1)) + '
  • '; } } } if (noRenameGames) { buf += '

    You can\'t change name in the middle of these games:

    '; buf += ''; buf += '

    '; buf += '

    '; buf += '
    '; this.$el.html(buf); return; } } var name = (data.name || ''); if (!name && app.user.get('named')) name = app.user.get('name'); buf += '

    '; if (name) { buf += '

    (Others will be able to see your name change. To change name privately, use "Log out")

    '; } buf += '

    '; buf += ''; this.$el.html(buf); }, events: { 'input .textbox': 'updateColor' }, updateColor: function (e) { var name = e.currentTarget.value; var preview = this.$('.preview'); var css = BattleLog.hashColor(toUserid(name)).slice(6, -1); preview.css('color', css); }, force: function () { var sourceEl = this.sourceEl; this.close(); app.addPopup(LoginPopup, { force: true, sourceEl: sourceEl, sourcePopup: app.popups[app.popups.length - 1] }); }, submit: function (data) { this.close(); if (!$.trim(data.username)) return; app.user.rename(data.username); } }); var ChangePasswordPopup = this.ChangePasswordPopup = Popup.extend({ type: 'semimodal', initialize: function (data) { var buf = '
    '; if (data.error) { buf += '

    ' + data.error + '

    '; } else { buf += '

    Change your password:

    '; } buf += '

    '; buf += '

    '; buf += '

    '; buf += '

    '; buf += '

    '; this.$el.html(buf); }, submit: function (data) { $.post(app.user.getActionPHP(), { act: 'changepassword', oldpassword: data.oldpassword, password: data.password, cpassword: data.cpassword }, Storage.safeJSON(function (data) { if (!data) data = {}; if (data.actionsuccess) { app.addPopupMessage("Your password was successfully changed."); } else { app.addPopup(ChangePasswordPopup, { error: data.actionerror }); } }), 'text'); } }); var RegisterPopup = this.RegisterPopup = Popup.extend({ type: 'semimodal', initialize: function (data) { var buf = '
    '; if (data.error) { buf += '

    ' + data.error + '

    '; } else if (data.reason) { buf += '

    ' + data.reason + '

    '; } else { buf += '

    Register your account:

    '; } buf += '

    '; buf += '

    '; buf += '

    '; buf += '

    '; buf += '

    '; buf += '

    '; this.$el.html(buf); }, submit: function (data) { var name = data.name; var captcha = data.captcha; $.post(app.user.getActionPHP(), { act: 'register', username: name, password: data.password, cpassword: data.cpassword, captcha: captcha, challstr: app.user.challstr }, Storage.safeJSON(function (data) { if (!data) data = {}; var token = data.assertion; if (data.curuser && data.curuser.loggedin) { app.user.set('registered', data.curuser); var name = data.curuser.username; app.send('/trn ' + name + ',1,' + token); app.addPopupMessage("You have been successfully registered."); } else { app.addPopup(RegisterPopup, { name: name, captcha: captcha, error: data.actionerror }); } }), 'text'); } }); this.LoginPasswordPopup = Popup.extend({ type: 'semimodal', initialize: function (data) { var buf = '
    '; if (data.error) { buf += '

    ' + BattleLog.escapeHTML(data.error) + '

    '; if (data.error.indexOf(' forced you to change ') >= 0) { buf += '

    Keep in mind these rules:

    '; buf += '
      '; buf += '
    1. Usernames may not be derogatory or insulting in nature, to an individual or group (insulting yourself is okay as long as it\'s not too serious).
    2. '; buf += '
    3. Usernames may not reference sexual activity, directly or indirectly.
    4. '; buf += '
    5. Usernames may not impersonate a recognized user (a user with %, @, &, or ~ next to their name).
    6. '; buf += '
    '; } } else if (data.reason) { buf += '

    ' + BattleLog.escapeHTML(data.reason) + '

    '; } else { buf += '

    The name you chose is registered.

    '; } buf += '

    If this is your account:

    '; buf += '

    '; if (data.special === '@gmail') { buf += '
    [loading Google log-in button]
    '; buf += '

    '; } else { buf += '

    '; buf += '

    '; } buf += '

    or

    '; buf += '

    If this is someone else\'s account:

    '; buf += '

    '; buf += '
    '; this.$el.html(buf); if (data.special === '@gmail') { var self = this; window.gapiRenderButton = function () { gapi.signin2.render('gapi-custom-signin', { // eslint-disable-line no-undef 'scope': 'profile email', 'width': 240, 'height': 50, 'longtitle': true, 'theme': 'dark', 'onsuccess': function (googleUser) { // var profile = googleUser.getBasicProfile(); var id_token = googleUser.getAuthResponse().id_token; self.close(); app.user.passwordRename(data.username, id_token, data.special); }, 'onfailure': function (googleUser) { alert('sign-in failed'); } }); }; if (window.gapiLoaded) return setTimeout(window.gapiRenderButton, 100); window.gapiLoaded = true; var script = document.createElement('script'); script.async = true; script.src = 'https://apis.google.com/js/platform.js?onload=gapiRenderButton'; document.getElementsByTagName('head')[0].appendChild(script); } }, login: function () { this.close(); app.addPopup(LoginPopup); }, submit: function (data) { this.close(); app.user.passwordRename(data.username, data.password); } }); }).call(this, jQuery);