diff --git a/js/api.js b/js/api.js index d7c45f82af7e..2f68ca566ff8 100644 --- a/js/api.js +++ b/js/api.js @@ -16,7 +16,7 @@ window.textsecure = window.textsecure || {}; -window.textsecure.api = function() { +window.textsecure.api = function () { 'use strict'; var self = {}; @@ -27,19 +27,19 @@ window.textsecure.api = function() { // Staging server var URL_BASE = "https://textsecure-service-staging.whispersystems.org"; self.relay = "textsecure-service-staging.whispersystems.org"; - var ATTACHMENT_HOST = "whispersystems-textsecure-attachments-staging.s3.amazonaws.com" + var ATTACHMENT_HOST = "whispersystems-textsecure-attachments-staging.s3.amazonaws.com"; // This is the real server //var URL_BASE = "https://textsecure-service.whispersystems.org"; var URL_CALLS = {}; - URL_CALLS['accounts'] = "/v1/accounts"; - URL_CALLS['devices'] = "/v1/devices"; - URL_CALLS['keys'] = "/v2/keys"; - URL_CALLS['push'] = "/v1/websocket"; - URL_CALLS['temp_push'] = "/v1/temp_websocket"; - URL_CALLS['messages'] = "/v1/messages"; - URL_CALLS['attachment'] = "/v1/attachments"; + URL_CALLS.accounts = "/v1/accounts"; + URL_CALLS.devices = "/v1/devices"; + URL_CALLS.keys = "/v2/keys"; + URL_CALLS.push = "/v1/websocket"; + URL_CALLS.temp_push = "/v1/temp_websocket"; + URL_CALLS.messages = "/v1/messages"; + URL_CALLS.attachment = "/v1/attachments"; /** * REQUIRED PARAMS: @@ -54,23 +54,24 @@ window.textsecure.api = function() { * do_auth: alternative to user/password where user/password are figured out automagically * jsonData: JSON data sent in the request body */ - var doAjax = function(param) { - if (param.urlParameters === undefined) + var doAjax = function (param) { + if (param.urlParameters === undefined) { param.urlParameters = ""; + } if (param.do_auth) { param.user = textsecure.storage.getUnencrypted("number_id"); param.password = textsecure.storage.getEncrypted("password"); } - return new Promise(function(resolve, reject) { + return new Promise(function (resolve, reject) { $.ajax(URL_BASE + URL_CALLS[param.call] + param.urlParameters, { type : param.httpType, data : param.jsonData && textsecure.utils.jsonThing(param.jsonData), contentType : 'application/json; charset=utf-8', dataType : 'json', - beforeSend : function(xhr) { + beforeSend : function (xhr) { if (param.user !== undefined && param.password !== undefined) xhr.setRequestHeader("Authorization", "Basic " + btoa(getString(param.user) + ":" + getString(param.password))); @@ -82,7 +83,7 @@ window.textsecure.api = function() { error : function(jqXHR, textStatus, errorThrown) { var code = jqXHR.status; - if (code == 200) { + if (code === 200) { // happens sometimes when we get no response // (TODO: Fix server to return 204? instead) resolve(null); @@ -153,7 +154,7 @@ window.textsecure.api = function() { jsonData : { signalingKey : btoa(getString(signaling_key)), supportsSms : false, fetchesMessages : true, - registrationId : registrationId}, + registrationId : registrationId} }); }; diff --git a/js/chromium.js b/js/chromium.js index 66c73bee13db..d5874cfd46ed 100644 --- a/js/chromium.js +++ b/js/chromium.js @@ -1,3 +1,4 @@ +/*global chrome*/ /* vim: ts=4:sw=4 * * This program is free software: you can redistribute it and/or modify @@ -13,41 +14,42 @@ * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ +(function () { + 'use strict'; + window.extension = window.extension || {}; -window.extension = window.extension || {}; + window.extension.navigator = (function () { + var self = {}, + tabs = {}; + tabs.create = function (url) { + chrome.tabs.create({url: url}); + }; + self.tabs = tabs; -window.extension.navigator = function() { - var self = {}; - - var tabs = {}; - tabs.create = function(url){ - chrome.tabs.create({url: url}); - }; - self.tabs = tabs; - - self.setBadgeText = function(text){ - chrome.browserAction.setBadgeText({text: text + ""}); - }; - - return self; -}(); + self.setBadgeText = function (text) { + chrome.browserAction.setBadgeText({text: String(text)}); + }; -// Random shared utilities that are used only by chromium things + return self; + }()); -function registrationDone() { - localStorage.setItem("chromiumRegistrationDone", ""); - chrome.runtime.sendMessage('registration_done'); - window.location = '/index.html'; -} + // Random shared utilities that are used only by chromium things -function isRegistrationDone() { - return localStorage.getItem("chromiumRegistrationDone") !== null; -} + function registrationDone() { + localStorage.setItem("chromiumRegistrationDone", ""); + chrome.runtime.sendMessage('registration_done'); + window.location = '/index.html'; + } -function addRegistrationListener(callback) { - chrome.runtime.onMessage.addListener(function(message) { - if (message === 'registration_done') { - callback(); - } - }); -}; + function isRegistrationDone() { + return localStorage.getItem("chromiumRegistrationDone") !== null; + } + + function addRegistrationListener(callback) { + chrome.runtime.onMessage.addListener(function(message) { + if (message === 'registration_done') { + callback(); + } + }); + } +}()); diff --git a/js/index.js b/js/index.js index e28921c3ed7d..292ace94b130 100644 --- a/js/index.js +++ b/js/index.js @@ -1,3 +1,4 @@ +/*global $, Whisper, Backbone, textsecure, extension*/ /* vim: ts=4:sw=4:expandtab: * * This program is free software: you can redistribute it and/or modify @@ -13,61 +14,63 @@ * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ +(function () { + 'use strict'; + Whisper.Layout = new (Backbone.View.extend({ + initialize: function () { + this.gutter = $('#gutter'); + this.contacts = $('#contacts'); + this.resize(); -Whisper.Layout = new (Backbone.View.extend({ - initialize: function() { - this.gutter = $('#gutter'); - this.contacts = $('#contacts'); - this.resize(); + new Whisper.ConversationListView({el: $('#contacts')}); + window.addEventListener('resize', this.resize.bind(this)); + window.addEventListener('storage', function () {Whisper.Threads.fetch(); }); + Whisper.Threads.fetch({reset: true}); + }, + events: { + 'click #new-message': 'new_message', + 'click #new-group': 'new_group' + }, - new Whisper.ConversationListView({el: $('#contacts')}); - window.addEventListener('resize', this.resize.bind(this)); - window.addEventListener('storage', function(){Whisper.Threads.fetch();}); - Whisper.Threads.fetch({reset: true}); - }, - events: { - 'click #new-message': 'new_message', - 'click #new-group': 'new_group' - }, + new_message: function (e) { + e.preventDefault(); + $('.conversation').hide().trigger('close'); // detach any existing conversation views + this.view = new Whisper.NewConversationView(); + //todo: less new + }, - new_message: function(e) { - e.preventDefault(); - $('.conversation').hide().trigger('close'); // detach any existing conversation views - this.view = new Whisper.NewConversationView(); - //todo: less new - }, - - new_group: function(e) { - e.preventDefault(); - $('.conversation').trigger('close'); // detach any existing conversation views - new Whisper.NewGroupView(); - }, - resize: function (e) { - var windowheight = window.innerHeight; - var form = $('.send-message-area').outerHeight(); - var gutter_offset = this.gutter.offset().top; - var contacts_offset = this.contacts.offset().top; - if (window.innerWidth < 480) { - this.gutter.css('height', windowheight - gutter_offset - form); - this.contacts.css('height', windowheight - contacts_offset - form); - } else { - this.gutter.css('height', windowheight - gutter_offset); - this.contacts.css('height', windowheight - contacts_offset); + new_group: function (e) { + e.preventDefault(); + $('.conversation').trigger('close'); // detach any existing conversation views + new Whisper.NewGroupView(); + }, + resize: function (e) { + var windowheight = window.innerHeight, + form = $('.send-message-area').outerHeight(), + gutter_offset = this.gutter.offset().top, + contacts_offset = this.contacts.offset().top; + if (window.innerWidth < 480) { + this.gutter.css('height', windowheight - gutter_offset - form); + this.contacts.css('height', windowheight - contacts_offset - form); + } else { + this.gutter.css('height', windowheight - gutter_offset); + this.contacts.css('height', windowheight - contacts_offset); + } + $('.discussion').css('height', windowheight - gutter_offset - form); + }, + setContent: function (content) { + $(content).insertAfter(this.gutter); + this.resize(); } - $('.discussion').css('height', windowheight - gutter_offset - form); - }, - setContent: function(content) { - $(content).insertAfter(this.gutter); - this.resize(); - } -}))({el: document}); + }))({el: document}); -if (textsecure.storage.getUnencrypted("number_id") === undefined) { - window.location = '/options.html'; -} else { - textsecure.storage.putUnencrypted("unreadCount", 0); - extension.navigator.setBadgeText(""); - if (Whisper.Threads.length) { - Whisper.Threads.at(0).trigger('render'); + if (textsecure.storage.getUnencrypted("number_id") === undefined) { + window.location = '/options.html'; + } else { + textsecure.storage.putUnencrypted("unreadCount", 0); + extension.navigator.setBadgeText(""); + if (Whisper.Threads.length) { + Whisper.Threads.at(0).trigger('render'); + } } -} +}());