私は、この要旨に見られるように、ポリマーで動作するようにロード画面を取得しようとしているで動作するようにロードscrenを取得:https://gist.github.com/SlicedSilver/f2e93a5995f84d9cd512は、ポリマー
アイデアは非常に単純です:エントリポイントがレンダリング軽量HTMLファイルであります本体に軽量ページがレンダリングされた後にDOMを介してPolymerアプリケーションをロードするonloadコールバックを含む読み込み画面。
これはデスクトップブラウザでうまく機能します。モバイルブラウザでは、filestoload.htmlがロードされることはありませんが(エラーは発生しません)、読み込み画面はそのまま残り、アプリケーションはロードされません。完全なコードは次のとおりですが、この行に特に注意してください。
tag.setAttribute('onload', 'polymerLoader.insertPolymerApplication()');
onloadイベントは決して起動せず、エラーをスローしません。私は、DOMと適切なイベントハンドラの両方を利用してそれを捕まえることを試みました。私はそうであっても同様にHTMLファイルへのリンクを追加し、健全性チェックとして完全にJSの手からそれを取って試してみた:
<link rel="import" href="/filestoload.html" onload="polymerLoader.insertPolymerApplication()" >
同じ結果 - デスクトップ上のアプリを表示しますが、ちょうど示し携帯端末に画面を読み込む。私はアイデアが新鮮です。どんな助け?
....
はここで軽量なエントリーポイント(index.htmlを)
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, minimum-scale=1, initial-scale=1, user-scalable=yes">
<link rel="shortcut icon" type="image/png" href="/assets/images/favicon.ico"/>
<title>GreenMaven</title>
<meta name="description" content="greenmaven description">
<script src="assets/js/polymerAppLoader.js"></script>
<style type="text/css">
.loading {
position: fixed;
top: 50%;
left: 50%;
/* bring your own prefixes */
transform: translate(-50%, -50%);
z-index: -500;
display: block;
}
</style>
</head>
<body onload="polymerLoader.loadPolymerApplication()">
<div id="loader" class="loading">
<img src="assets/images/gears.svg" />
</div>
</body>
</html>
だと、ここでポリマーアプリの残りの部分をロードするJSです:
'use strict';
/* global polymerLoader */
/*jshint unused:false*/
/*jshint -W079*/
// This is the normal conditional loader for the Web components Polyfill
if ('registerElement' in document && 'createShadowRoot' in HTMLElement.prototype && 'import' in document.createElement('link') && 'content' in document.createElement('template')) {
// We're using a browser with native WC support!
} else {
// Add web components polyfill...
document.write('<script src="bower_components/webcomponentsjs/webcomponents.lite.js"><\/script>');
}
var polymerLoader = (function() {
// Function for creating a link element and inserting it into the <head> of the html document
function addLinkTag(elementType, address, shim, loadTrigger) {
var tag = document.createElement('link');
tag.rel = elementType;
tag.href = address;
if (shim) {
// add the shim-shadowdom attribute
tag.setAttribute('shim-shadowdom', '');
}
if (loadTrigger) {
// This file needs to be loaded before inserting the Polymer Application
// when finished loading it will call the polymerLoader.insertPolymerApplication() function
tag.setAttribute('onload', 'polymerLoader.insertPolymerApplication()');
expectedCalls++;
}
document.getElementsByTagName('head')[0].appendChild(tag);
}
var pgApploaded = false;
function loadPolymerApplication() {
// Only insert once.
if (!pgApploaded) {
addLinkTag('import', 'filestoload.html', false, true);
pgApploaded = true;
}
}
// Counter variable for insertPolymerApplication() calls
var callCount = 0;
var expectedCalls = 0;
function insertPolymerApplication() {
callCount++;
// Only when callCount >= expectedCalls
// The application is only inserted after all required files have loaded
// for the application to work.
if (callCount >= expectedCalls) {
// here is the html that is inserted when everything is loaded.
document.querySelector('body').innerHTML += '<template is="auto-binding" id="app"><polymer-app id="main-app"></polymer-app></template>';
document.getElementById('loader').style.display = 'none';
}
}
return {
insertPolymerApplication: function() {
insertPolymerApplication();
},
loadPolymerApplication: function() {
loadPolymerApplication();
}
};
})(document);
そして最後に、ここでは通常、ポリマーのindex.htmlに見られるのリンクやスクリプトを持ってfilestoload.htmlファイルです:
<!doctype html>
<!-- Here is where you put the scripts required by the page, that would normally be -->
<!-- included in the index.html page, you can still use grunt/gulp build functions on these -->
<!-- will be replaced with elements/elements.vulcanized.html -->
<link rel="manifest" href="/manifest.json">
<link rel="import" href="/src/greenmaven-app/greenmaven-app.html">
<link rel="stylesheet" href="assets/css/main.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
<!-- endreplace-->
<!-- build:js scripts/app.js -->
<script src="properties_base/farmhacker-properties.js"></script>
<!-- endbuild-->
<!-- build:js scripts/thirdparty.js -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script>
<script>
$(function() {
$('a[href*="#"]:not([href="#"])').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html, body').animate({
scrollTop: target.offset().top - $('#navbar').height()
}, 1000);
return false;
}
}
});
});
</script>
<!-- endbuild-->