/* * Spreed Speak Freely. * Copyright (C) 2013-2014 struktur AG * * This file is part of Spreed Speak Freely. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . * */ define([ 'require', 'jquery', 'underscore', 'angular', 'modernizr', 'moment', 'services/services', 'directives/directives', 'filters/filters', 'controllers/controllers', 'translation/languages', 'ui-bootstrap', 'angular-sanitize', 'angular-animate', 'angular-humanize', 'angular-route', 'mobile-events', 'dialogs' ], function(require, $, _, angular, modernizr, moment, services, directives, filters, controllers, languages) { // Simple and fast split based URL query parser based on location.search. We require this before the // angular App is bootstrap to control initialization parameters like translation based on URL parameters. var urlQuery = (function() { return (function(a) { if (a === "") { return {}; } var b = {}; for (var i = 0; i < a.length; ++i) { var p = a[i].split('='); if (p.length != 2) { continue; } b[p[0]] = window.decodeURIComponent(p[1].replace(/\+/g, " ")); } return b; })(window.location.search.substr(1).split("&")); }()); var initialize = function(ms) { var modules = ['ui.bootstrap', 'ngSanitize', 'ngAnimate', 'ngHumanize', 'ngRoute', 'dialogs']; if (ms && ms.length) { _.each(ms, function(module) { modules.push(module); }); } var app = angular.module('app', modules); services.initialize(app); directives.initialize(app); filters.initialize(app); controllers.initialize(app); app.config(["$compileProvider", "$locationProvider", "$routeProvider", function($compileProvider, $locationProvider, $routeProvider) { // Allow angular to use filesystem: hrefs which would else be prefixed with unsafe:. $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|ftp|mailto|tel|file|filesystem|blob):/); $compileProvider.imgSrcSanitizationWhitelist(/^\s*(https?|ftp|file|filesystem|blob):|data:image\//); // Setup routing $routeProvider.when("/:room", {}); // Use HTML5 routing. $locationProvider.html5Mode(true); }]); app.run(["$rootScope", "mediaStream", "translation", function($rootScope, mediaStream, translation) { translation.inject($rootScope); console.log("Initializing ..."); mediaStream.initialize($rootScope, translation); }]); app.constant("availableLanguages", languages); angular.element(document).ready(function() { var globalContext = JSON.parse($("#globalcontext").text()); app.constant("globalContext", globalContext); // Configure language. var lang = (function() { var lang = "en"; var wanted = []; var html = document.getElementsByTagName("html")[0]; // Get from storage. if (modernizr.localstorage) { var lsl = localStorage.getItem("mediastream-language"); if (lsl && lsl !== "undefined") { wanted.push(lsl); } } // Get from query. var qsl = urlQuery.lang; if (qsl) { wanted.push(qsl); } // Expand browser languages with combined fallback. _.each(globalContext.Languages, function(l) { wanted.push(l); if (l.indexOf("-") != -1) { wanted.push(l.split("-")[0]); } }); // Loop through browser languages and use first one we got. for (var i=0; i