Skip to content
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
16 changes: 6 additions & 10 deletions editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -409,19 +409,15 @@ <h2 id="modal-msg-title"></h2>
</div>
</div>
</div>
<script src="ace/ace.js" type="application/javascript"
charset="utf-8"></script>
<script src="ace/ext-language_tools.js" type="application/javascript"
charset="utf-8"></script>
<script src="static/js/jquery-2.1.4.min.js"
type="application/javascript"></script>
<script src="ace/ace.js" type="application/javascript" charset="utf-8"></script>
<script src="ace/ext-language_tools.js" type="application/javascript" charset="utf-8"></script>
<script src="static/js/jquery-2.1.4.min.js" type="application/javascript"></script>
<script src="static/js/jquery.browser.min.js" type="application/javascript"></script>
<script src="static/js/forge.min.js" type="application/javascript"></script>
<script src="static/js/FileSaver.min.js" type="application/javascript"></script>
<script src="static/js/vex.combined.min.js"
type="application/javascript"></script>
<script src="static/js/vex.combined.min.js" type="application/javascript"></script>
<script src="static/js/encoding.min.js" type="application/javascript"></script>
<script src="static/js/mustache.min.js"
type="application/javascript"></script>
<script src="static/js/mustache.min.js" type="application/javascript"></script>
<script src="static/js/ResizeSensor.js"></script>
<script src="static/js/ElementQueries.min.js"></script>
<script src="static/js/custom-event-polyfill.js"></script>
Expand Down
33 changes: 18 additions & 15 deletions python-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -797,18 +797,20 @@ function web_editor(config) {

// Downloads a file from the filesystem, main.py is renamed to the script name
function downloadFileFromFilesystem(filename) {
var output = micropythonFs.readBytes(filename);
var ua = navigator.userAgent.toLowerCase();
if ((ua.indexOf('safari/') > -1) && (ua.indexOf('chrome') == -1)) {
// Safari before v10 had issues downloading a file blob
if ($.browser.safari && ($.browser.versionNumber < 10)) {
alert(config.translate.alerts.save);
var output = micropythonFs.read(filename);
window.open('data:application/octet;charset=utf-8,' + encodeURIComponent(output), '_newtab');
} else {
var blob = new Blob([output], {type: 'text/plain'});
if (filename === 'main.py'){
filename = getSafeName() + '.py';
}
saveAs(blob, filename);
return;
}
// This works in all other browsers
var output = micropythonFs.readBytes(filename);
var blob = new Blob([output], { 'type': 'text/plain' });
if (filename === 'main.py') {
filename = getSafeName() + '.py';
}
saveAs(blob, filename);
}

// Update the widget that shows how much space is used in the filesystem
Expand Down Expand Up @@ -924,15 +926,16 @@ function web_editor(config) {
alert(config.translate.alerts.error + e.message);
return;
}
var ua = navigator.userAgent.toLowerCase();
if((ua.indexOf('safari/') > -1) && (ua.indexOf('chrome') == -1)) {
// Safari before v10 had issues downloading the file blob
if ($.browser.safari && ($.browser.versionNumber < 10)) {
alert(config.translate.alerts.download);
window.open('data:application/octet;charset=utf-8,' + encodeURIComponent(output), '_newtab');
} else {
var filename = getSafeName();
var blob = new Blob([output], {type: "application/octet-stream"});
saveAs(blob, filename + ".hex");
return;
}
// This works in all other browser
var filename = getSafeName();
var blob = new Blob([output], { 'type': 'application/octet-stream' });
saveAs(blob, filename + '.hex');
}

function invalidFileWarning(fileType){
Expand Down
193 changes: 193 additions & 0 deletions static/js/jquery.browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
/*!
* jQuery Browser Plugin 0.1.0
* https://github.com/gabceb/jquery-browser-plugin
*
* Original jquery-browser code Copyright 2005, 2015 jQuery Foundation, Inc. and other contributors
* http://jquery.org/license
*
* Modifications Copyright 2015 Gabriel Cebrian
* https://github.com/gabceb
*
* Released under the MIT license
*
* Date: 05-07-2015
*/
/*global window: false */

(function (factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['jquery'], function ($) {
return factory($);
});
} else if (typeof module === 'object' && typeof module.exports === 'object') {
// Node-like environment
module.exports = factory(require('jquery'));
} else {
// Browser globals
factory(window.jQuery);
}
}(function(jQuery) {
"use strict";

function uaMatch( ua ) {
// If an UA is not provided, default to the current browser UA.
if ( ua === undefined ) {
ua = window.navigator.userAgent;
}
ua = ua.toLowerCase();

var match = /(edge)\/([\w.]+)/.exec( ua ) ||
/(opr)[\/]([\w.]+)/.exec( ua ) ||
/(chrome)[ \/]([\w.]+)/.exec( ua ) ||
/(iemobile)[\/]([\w.]+)/.exec( ua ) ||
/(version)(applewebkit)[ \/]([\w.]+).*(safari)[ \/]([\w.]+)/.exec( ua ) ||
/(webkit)[ \/]([\w.]+).*(version)[ \/]([\w.]+).*(safari)[ \/]([\w.]+)/.exec( ua ) ||
/(webkit)[ \/]([\w.]+)/.exec( ua ) ||
/(opera)(?:.*version|)[ \/]([\w.]+)/.exec( ua ) ||
/(msie) ([\w.]+)/.exec( ua ) ||
ua.indexOf("trident") >= 0 && /(rv)(?::| )([\w.]+)/.exec( ua ) ||
ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec( ua ) ||
[];

var platform_match = /(ipad)/.exec( ua ) ||
/(ipod)/.exec( ua ) ||
/(windows phone)/.exec( ua ) ||
/(iphone)/.exec( ua ) ||
/(kindle)/.exec( ua ) ||
/(silk)/.exec( ua ) ||
/(android)/.exec( ua ) ||
/(win)/.exec( ua ) ||
/(mac)/.exec( ua ) ||
/(linux)/.exec( ua ) ||
/(cros)/.exec( ua ) ||
/(playbook)/.exec( ua ) ||
/(bb)/.exec( ua ) ||
/(blackberry)/.exec( ua ) ||
[];

var browser = {},
matched = {
browser: match[ 5 ] || match[ 3 ] || match[ 1 ] || "",
version: match[ 2 ] || match[ 4 ] || "0",
versionNumber: match[ 4 ] || match[ 2 ] || "0",
platform: platform_match[ 0 ] || ""
};

if ( matched.browser ) {
browser[ matched.browser ] = true;
browser.version = matched.version;
browser.versionNumber = parseInt(matched.versionNumber, 10);
}

if ( matched.platform ) {
browser[ matched.platform ] = true;
}

// These are all considered mobile platforms, meaning they run a mobile browser
if ( browser.android || browser.bb || browser.blackberry || browser.ipad || browser.iphone ||
browser.ipod || browser.kindle || browser.playbook || browser.silk || browser[ "windows phone" ]) {
browser.mobile = true;
}

// These are all considered desktop platforms, meaning they run a desktop browser
if ( browser.cros || browser.mac || browser.linux || browser.win ) {
browser.desktop = true;
}

// Chrome, Opera 15+ and Safari are webkit based browsers
if ( browser.chrome || browser.opr || browser.safari ) {
browser.webkit = true;
}

// IE11 has a new token so we will assign it msie to avoid breaking changes
if ( browser.rv || browser.iemobile) {
var ie = "msie";

matched.browser = ie;
browser[ie] = true;
}

// Edge is officially known as Microsoft Edge, so rewrite the key to match
if ( browser.edge ) {
delete browser.edge;
var msedge = "msedge";

matched.browser = msedge;
browser[msedge] = true;
}

// Blackberry browsers are marked as Safari on BlackBerry
if ( browser.safari && browser.blackberry ) {
var blackberry = "blackberry";

matched.browser = blackberry;
browser[blackberry] = true;
}

// Playbook browsers are marked as Safari on Playbook
if ( browser.safari && browser.playbook ) {
var playbook = "playbook";

matched.browser = playbook;
browser[playbook] = true;
}

// BB10 is a newer OS version of BlackBerry
if ( browser.bb ) {
var bb = "blackberry";

matched.browser = bb;
browser[bb] = true;
}

// Opera 15+ are identified as opr
if ( browser.opr ) {
var opera = "opera";

matched.browser = opera;
browser[opera] = true;
}

// Stock Android browsers are marked as Safari on Android.
if ( browser.safari && browser.android ) {
var android = "android";

matched.browser = android;
browser[android] = true;
}

// Kindle browsers are marked as Safari on Kindle
if ( browser.safari && browser.kindle ) {
var kindle = "kindle";

matched.browser = kindle;
browser[kindle] = true;
}

// Kindle Silk browsers are marked as Safari on Kindle
if ( browser.safari && browser.silk ) {
var silk = "silk";

matched.browser = silk;
browser[silk] = true;
}

// Assign the name and platform variable
browser.name = matched.browser;
browser.platform = matched.platform;
return browser;
}

// Run the matching process, also assign the function to the returned object
// for manual, jQuery-free use if desired
window.jQBrowser = uaMatch( window.navigator.userAgent );
window.jQBrowser.uaMatch = uaMatch;

// Only assign to jQuery.browser if jQuery is loaded
if ( jQuery ) {
jQuery.browser = window.jQBrowser;
}

return window.jQBrowser;
}));
14 changes: 14 additions & 0 deletions static/js/jquery.browser.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tests.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<script src="ace/ext-language_tools.js" type="application/javascript"
charset="utf-8"></script>
<script src="static/js/jquery-2.1.4.min.js"></script>
<script src="static/js/jquery.browser.min.js"></script>
<script src="static/js/forge.min.js"></script>
<script src="static/js/microbit-fs.umd.js"></script>
<script src="micropythonapi.js" type="application/javascript"></script>
Expand Down