Touchgui/plugins/org.apache.cordova.splashscreen/www/windows8/SplashScreenProxy.js

Thu, 04 Jun 2015 14:50:33 +0200

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 04 Jun 2015 14:50:33 +0200
changeset 0
e8ccd40d0ef6
permissions
-rw-r--r--

Genesis of lecture sources for Droidcon Berlin 2015 in Postbahnhof.

     1 /*
     2  *
     3  * Licensed to the Apache Software Foundation (ASF) under one
     4  * or more contributor license agreements.  See the NOTICE file
     5  * distributed with this work for additional information
     6  * regarding copyright ownership.  The ASF licenses this file
     7  * to you under the Apache License, Version 2.0 (the
     8  * "License"); you may not use this file except in compliance
     9  * with the License.  You may obtain a copy of the License at
    10  *
    11  *   http://www.apache.org/licenses/LICENSE-2.0
    12  *
    13  * Unless required by applicable law or agreed to in writing,
    14  * software distributed under the License is distributed on an
    15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    16  * KIND, either express or implied.  See the License for the
    17  * specific language governing permissions and limitations
    18  * under the License.
    19  *
    20 */
    22 /*jslint sloppy:true */
    23 /*global Windows:true, require, module, window, document, WinJS */
    25 var cordova = require('cordova'),
    26     channel = require('cordova/channel');
    28 /* This is the actual implementation part that returns the result on Windows 8
    29 */
    31 var position = { x: 0, y: 0, width: 0, height: 0 };  // defined by evt.detail.splashScreen.imageLocation
    32 var splash = null; //
    33 var localSplash; // the image to display
    34 var localSplashImage;
    35 var bgColor = "#464646";
    39 function updateImageLocation() {
    40     localSplash.style.width = window.innerWidth + "px";
    41     localSplash.style.height = window.innerHeight + "px";
    42     localSplash.style.top = "0px";
    43     localSplash.style.left = "0px";
    45     localSplashImage.style.top = position.y + "px";
    46     localSplashImage.style.left = position.x + "px";
    47     localSplashImage.style.height = position.height + "px";
    48     localSplashImage.style.width = position.width + "px";
    49 }
    51 function onResize(evt) {
    52     if (splash) {
    53         position = splash.imageLocation;
    54         updateImageLocation();
    55     }
    56 }
    58 var SplashScreen = {
    59     setBGColor: function (cssBGColor) {
    60         bgColor = cssBGColor;
    61         if (localSplash) {
    62             localSplash.style.backgroundColor = bgColor;
    63         }
    64     },
    65     show: function () {
    66         window.addEventListener("resize", onResize, false);
    67         localSplash = document.createElement("div");
    68         localSplash.style.backgroundColor = bgColor;
    69         localSplash.style.position = "absolute";
    71         localSplashImage = document.createElement("img");
    72         localSplashImage.src = "ms-appx:///images/splashscreen.png";
    73         localSplashImage.style.position = "absolute";
    75         updateImageLocation();
    77         localSplash.appendChild(localSplashImage);
    78         document.body.appendChild(localSplash);
    79     },
    80     hide: function () {
    81         window.removeEventListener("resize", onResize, false);
    82         document.body.removeChild(localSplash);
    83         localSplash = null;
    84     }
    85 };
    87 module.exports = SplashScreen;
    89 function activated(evt) {
    90     if (evt.detail.kind === Windows.ApplicationModel.Activation.ActivationKind.launch) {
    91         splash = evt.detail.splashScreen;
    92         position = evt.detail.splashScreen.imageLocation;
    93     }
    94 }
    99 channel.onCordovaReady.subscribe(function (evt) {
   100     document.addEventListener("DOMContentLoaded", function (evt) {
   101         WinJS.Application.addEventListener("activated", activated, false);
   102     }, false);
   103 });
   105 require("cordova/exec/proxy").add("SplashScreen", SplashScreen);

mercurial