michael@0: /* michael@0: * michael@0: * Licensed to the Apache Software Foundation (ASF) under one michael@0: * or more contributor license agreements. See the NOTICE file michael@0: * distributed with this work for additional information michael@0: * regarding copyright ownership. The ASF licenses this file michael@0: * to you under the Apache License, Version 2.0 (the michael@0: * "License"); you may not use this file except in compliance michael@0: * with the License. You may obtain a copy of the License at michael@0: * michael@0: * http://www.apache.org/licenses/LICENSE-2.0 michael@0: * michael@0: * Unless required by applicable law or agreed to in writing, michael@0: * software distributed under the License is distributed on an michael@0: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY michael@0: * KIND, either express or implied. See the License for the michael@0: * specific language governing permissions and limitations michael@0: * under the License. michael@0: * michael@0: */ michael@0: michael@0: /*jslint sloppy:true */ michael@0: /*global Windows:true, require, module, window, document, WinJS */ michael@0: michael@0: var cordova = require('cordova'), michael@0: channel = require('cordova/channel'); michael@0: michael@0: /* This is the actual implementation part that returns the result on Windows 8 michael@0: */ michael@0: michael@0: var position = { x: 0, y: 0, width: 0, height: 0 }; // defined by evt.detail.splashScreen.imageLocation michael@0: var splash = null; // michael@0: var localSplash; // the image to display michael@0: var localSplashImage; michael@0: var bgColor = "#464646"; michael@0: michael@0: michael@0: michael@0: function updateImageLocation() { michael@0: localSplash.style.width = window.innerWidth + "px"; michael@0: localSplash.style.height = window.innerHeight + "px"; michael@0: localSplash.style.top = "0px"; michael@0: localSplash.style.left = "0px"; michael@0: michael@0: localSplashImage.style.top = position.y + "px"; michael@0: localSplashImage.style.left = position.x + "px"; michael@0: localSplashImage.style.height = position.height + "px"; michael@0: localSplashImage.style.width = position.width + "px"; michael@0: } michael@0: michael@0: function onResize(evt) { michael@0: if (splash) { michael@0: position = splash.imageLocation; michael@0: updateImageLocation(); michael@0: } michael@0: } michael@0: michael@0: var SplashScreen = { michael@0: setBGColor: function (cssBGColor) { michael@0: bgColor = cssBGColor; michael@0: if (localSplash) { michael@0: localSplash.style.backgroundColor = bgColor; michael@0: } michael@0: }, michael@0: show: function () { michael@0: window.addEventListener("resize", onResize, false); michael@0: localSplash = document.createElement("div"); michael@0: localSplash.style.backgroundColor = bgColor; michael@0: localSplash.style.position = "absolute"; michael@0: michael@0: localSplashImage = document.createElement("img"); michael@0: localSplashImage.src = "ms-appx:///images/splashscreen.png"; michael@0: localSplashImage.style.position = "absolute"; michael@0: michael@0: updateImageLocation(); michael@0: michael@0: localSplash.appendChild(localSplashImage); michael@0: document.body.appendChild(localSplash); michael@0: }, michael@0: hide: function () { michael@0: window.removeEventListener("resize", onResize, false); michael@0: document.body.removeChild(localSplash); michael@0: localSplash = null; michael@0: } michael@0: }; michael@0: michael@0: module.exports = SplashScreen; michael@0: michael@0: function activated(evt) { michael@0: if (evt.detail.kind === Windows.ApplicationModel.Activation.ActivationKind.launch) { michael@0: splash = evt.detail.splashScreen; michael@0: position = evt.detail.splashScreen.imageLocation; michael@0: } michael@0: } michael@0: michael@0: michael@0: michael@0: michael@0: channel.onCordovaReady.subscribe(function (evt) { michael@0: document.addEventListener("DOMContentLoaded", function (evt) { michael@0: WinJS.Application.addEventListener("activated", activated, false); michael@0: }, false); michael@0: }); michael@0: michael@0: require("cordova/exec/proxy").add("SplashScreen", SplashScreen); michael@0: