mirror of
https://github.com/scratchfoundation/scratchx.git
synced 2024-11-28 18:45:49 -05:00
Organize JS
This commit is contained in:
parent
9b68d8a7ec
commit
2ccb6c1c76
2 changed files with 107 additions and 110 deletions
112
index.html
112
index.html
|
@ -9,116 +9,6 @@
|
|||
<link href="css/scratchx.css" rel="stylesheet" type="text/css">
|
||||
<script type="text/javascript" src="libs/swfobject.js"></script>
|
||||
<script type="text/javascript" src="libs/jquery-1.11.2.min.js"></script>
|
||||
<script type="text/javascript" src="scratch_extensions/scratch_ext.js"></script>
|
||||
<script type="text/javascript">
|
||||
// Simulate the bare minimum of the view that exists on the main site
|
||||
var Scratch = Scratch || {};
|
||||
Scratch.FlashApp = Scratch.FlashApp || {};
|
||||
|
||||
function handleEmbedStatus(e) {
|
||||
$('#scratch-loader').hide();
|
||||
var scratch = $('#scratch');
|
||||
if (!e.success) {
|
||||
scratch.css('marginTop', '10');
|
||||
scratch.find('IMG.proj_thumb').css('width', '179px');
|
||||
scratch.find('DIV.scratch_unsupported').show();
|
||||
scratch.find('DIV.scratch_loading').hide();
|
||||
} else {
|
||||
Scratch.FlashApp.ASobj = scratch[0];
|
||||
}
|
||||
}
|
||||
|
||||
// enables the SWF to log errors
|
||||
function JSthrowError(e) {
|
||||
if (window.onerror) window.onerror(e, 'swf', 0);
|
||||
else console.error(e);
|
||||
}
|
||||
|
||||
function JSeditorReady() {
|
||||
console.log('swfReady');
|
||||
try {
|
||||
handleParameters();
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error(error.message, "\n", error.stack);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
function JSprojectLoaded() {
|
||||
loadExtensionQueue();
|
||||
}
|
||||
|
||||
var extensionQueue = [];
|
||||
function handleParameters() {
|
||||
var project;
|
||||
var queryString = window.location.search.substring(1);
|
||||
var queryVars = queryString.split(/[&;]/);
|
||||
for (var i = 0; i < queryVars.length; i++) {
|
||||
var nameVal = queryVars[i].split('=');
|
||||
switch(nameVal[0]){
|
||||
case 'ext':
|
||||
extensionQueue.push(nameVal[1]);
|
||||
break;
|
||||
case 'proj':
|
||||
project = nameVal[1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (project) {
|
||||
Scratch.FlashApp.ASobj.ASloadSBXFromURL(project);
|
||||
}
|
||||
else {
|
||||
loadExtensionQueue();
|
||||
}
|
||||
}
|
||||
|
||||
function loadExtensionQueue() {
|
||||
for (var i = 0; i < extensionQueue.length; ++i) {
|
||||
var extensionURL = extensionQueue[i];
|
||||
ScratchExtensions.loadExternalJS(extensionURL);
|
||||
}
|
||||
extensionQueue = [];
|
||||
}
|
||||
|
||||
var flashVars = {
|
||||
autostart: 'false',
|
||||
extensionDevMode: 'true',
|
||||
server: encodeURIComponent(location.host),
|
||||
cloudToken: '4af4863d-a921-4004-b2cb-e0ad00ee1927',
|
||||
cdnToken: '34f16bc63e8ada7dfd7ec12c715d0c94',
|
||||
urlOverrides: {
|
||||
sitePrefix: "http://scratch.mit.edu/",
|
||||
siteCdnPrefix: "http://cdn.scratch.mit.edu/",
|
||||
assetPrefix: "http://assets.scratch.mit.edu/",
|
||||
assetCdnPrefix: "http://cdn.assets.scratch.mit.edu/",
|
||||
projectPrefix: "http://projects.scratch.mit.edu/",
|
||||
projectCdnPrefix: "http://cdn.projects.scratch.mit.edu/",
|
||||
internalAPI: "internalapi/",
|
||||
siteAPI: "site-api/",
|
||||
staticFiles: "scratchr2/static/"
|
||||
},
|
||||
inIE: (navigator.userAgent.indexOf('MSIE') > -1)
|
||||
};
|
||||
|
||||
var params = {
|
||||
allowscriptaccess: 'always',
|
||||
allowfullscreen: 'true',
|
||||
wmode: 'direct',
|
||||
menu: 'false'
|
||||
};
|
||||
|
||||
$.each(flashVars, function (prop, val) {
|
||||
if ($.isPlainObject(val))
|
||||
flashVars[prop] = encodeURIComponent(JSON.stringify(val));
|
||||
});
|
||||
|
||||
swfobject.switchOffAutoHideShow();
|
||||
|
||||
swfobject.embedSWF('Scratch.swf', 'scratch', '100%', '100%', '11.7.0', 'libs/expressInstall.swf',
|
||||
flashVars, params, null, handleEmbedStatus);
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body class="editor scratchx">
|
||||
|
||||
|
@ -134,5 +24,7 @@
|
|||
</div>
|
||||
<div class="scratch_loading"></div>
|
||||
</div>
|
||||
<script type="text/javascript" src="scratch_extensions/scratch_ext.js"></script>
|
||||
<script type="text/javascript" src="js/scratchx.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
105
js/scratchx.js
Normal file
105
js/scratchx.js
Normal file
|
@ -0,0 +1,105 @@
|
|||
// Simulate the bare minimum of the view that exists on the main site
|
||||
var Scratch = Scratch || {};
|
||||
Scratch.FlashApp = Scratch.FlashApp || {};
|
||||
|
||||
function handleEmbedStatus(e) {
|
||||
$('#scratch-loader').hide();
|
||||
var scratch = $('#scratch');
|
||||
if (!e.success) {
|
||||
scratch.css('marginTop', '10');
|
||||
scratch.find('IMG.proj_thumb').css('width', '179px');
|
||||
scratch.find('DIV.scratch_unsupported').show();
|
||||
scratch.find('DIV.scratch_loading').hide();
|
||||
} else {
|
||||
Scratch.FlashApp.ASobj = scratch[0];
|
||||
}
|
||||
}
|
||||
|
||||
// enables the SWF to log errors
|
||||
function JSthrowError(e) {
|
||||
if (window.onerror) window.onerror(e, 'swf', 0);
|
||||
else console.error(e);
|
||||
}
|
||||
|
||||
function JSeditorReady() {
|
||||
try {
|
||||
handleParameters();
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error(error.message, "\n", error.stack);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
function JSprojectLoaded() {
|
||||
loadExtensionQueue();
|
||||
}
|
||||
|
||||
var extensionQueue = [];
|
||||
function handleParameters() {
|
||||
var project;
|
||||
var queryString = window.location.search.substring(1);
|
||||
var queryVars = queryString.split(/[&;]/);
|
||||
for (var i = 0; i < queryVars.length; i++) {
|
||||
var nameVal = queryVars[i].split('=');
|
||||
switch(nameVal[0]){
|
||||
case 'ext':
|
||||
extensionQueue.push(nameVal[1]);
|
||||
break;
|
||||
case 'proj':
|
||||
project = nameVal[1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (project) {
|
||||
Scratch.FlashApp.ASobj.ASloadSBXFromURL(project);
|
||||
}
|
||||
else {
|
||||
loadExtensionQueue();
|
||||
}
|
||||
}
|
||||
|
||||
function loadExtensionQueue() {
|
||||
for (var i = 0; i < extensionQueue.length; ++i) {
|
||||
var extensionURL = extensionQueue[i];
|
||||
ScratchExtensions.loadExternalJS(extensionURL);
|
||||
}
|
||||
extensionQueue = [];
|
||||
}
|
||||
|
||||
var flashVars = {
|
||||
autostart: 'false',
|
||||
extensionDevMode: 'true',
|
||||
server: encodeURIComponent(location.host),
|
||||
cloudToken: '4af4863d-a921-4004-b2cb-e0ad00ee1927',
|
||||
cdnToken: '34f16bc63e8ada7dfd7ec12c715d0c94',
|
||||
urlOverrides: {
|
||||
sitePrefix: "http://scratch.mit.edu/",
|
||||
siteCdnPrefix: "http://cdn.scratch.mit.edu/",
|
||||
assetPrefix: "http://assets.scratch.mit.edu/",
|
||||
assetCdnPrefix: "http://cdn.assets.scratch.mit.edu/",
|
||||
projectPrefix: "http://projects.scratch.mit.edu/",
|
||||
projectCdnPrefix: "http://cdn.projects.scratch.mit.edu/",
|
||||
internalAPI: "internalapi/",
|
||||
siteAPI: "site-api/",
|
||||
staticFiles: "scratchr2/static/"
|
||||
},
|
||||
inIE: (navigator.userAgent.indexOf('MSIE') > -1)
|
||||
};
|
||||
|
||||
var params = {
|
||||
allowscriptaccess: 'always',
|
||||
allowfullscreen: 'true',
|
||||
wmode: 'direct',
|
||||
menu: 'false'
|
||||
};
|
||||
|
||||
$.each(flashVars, function (prop, val) {
|
||||
if ($.isPlainObject(val))
|
||||
flashVars[prop] = encodeURIComponent(JSON.stringify(val));
|
||||
});
|
||||
|
||||
swfobject.switchOffAutoHideShow();
|
||||
|
||||
swfobject.embedSWF('Scratch.swf', 'scratch', '100%', '100%', '11.7.0', 'libs/expressInstall.swf',
|
||||
flashVars, params, null, handleEmbedStatus);
|
Loading…
Reference in a new issue