Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing removing shadow DOM for non chrome browsers. #137

Merged
merged 3 commits into from
Aug 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ SimulationServer.prototype.start = function (platform, opts) {
this._cordovaServer = cordovaServe();

/* attach simulation host middleware */
var middlewarePath = path.join(config.simHostOptions.simHostRoot, 'server', 'server');
if (fs.existsSync(middlewarePath + '.js')) {
require(middlewarePath).attach(this._cordovaServer.app, dirs);
var middlewarePath = path.join(config.simHostOptions.simHostRoot, 'server', 'server.js');
if (fs.existsSync(middlewarePath)) {
require(middlewarePath).attach(this._cordovaServer.app, dirs, this._hostRoot);
}

/* attach CORS proxy middleware */
Expand Down
27 changes: 27 additions & 0 deletions src/sim-host/ui/polyfills.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) Microsoft Corporation. All rights reserved.

// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign

if (typeof Object.assign != 'function') {
(function () {
Object.assign = function (target) {
'use strict';
if (target === undefined || target === null) {
throw new TypeError('Cannot convert undefined or null to object');
}

var output = Object(target);
for (var index = 1; index < arguments.length; index++) {
var source = arguments[index];
if (source !== undefined && source !== null) {
for (var nextKey in source) {
if (Object.prototype.hasOwnProperty.call(source, nextKey)) {
output[nextKey] = source[nextKey];
}
}
}
}
return output;
};
})();
}
4 changes: 2 additions & 2 deletions src/sim-host/ui/server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ var path = require('path'),
replaceStream = require('replacestream'),
send = require('send-transform');

module.exports.attach = function (app, dirs) {
module.exports.attach = function (app, dirs, hostRoot) {
app.get('/simulator/sim-host.css', function (request, response, next) {
var userAgent = request.headers['user-agent'];
if (userAgent.indexOf('Chrome') > -1 && userAgent.indexOf('Edge/') === -1) {
next();
} else {
// If target browser isn't Chrome (user agent contains 'Chrome', but isn't 'Edge'), remove shadow dom stuff from
// the CSS file. Also remove any sections marked as Chrome specific.
send(request, path.resolve(dirs.hostRoot['sim-host'], 'sim-host.css'), {
send(request, path.resolve(hostRoot['sim-host'], 'sim-host.css'), {
transform: function (stream) {
return stream
.pipe(replaceStream('> ::content >', '>'))
Expand Down
1 change: 1 addition & 0 deletions src/sim-host/ui/sim-host.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<link href="sim-host.css" rel="stylesheet"/>
<script src="/simulator/thirdparty/webcomponents.min.js"></script>
<script src="/simulator/thirdparty/socket.io.js"></script>
<script src="polyfills.js"></script>
<script src="sim-host.js"></script>

<!-- For cordova-panel and cordova-dialog, the shadow is applied to the inner section, in order to prevent it
Expand Down