bharvey wrote:
scimonster wrote:
AJAX+JS+PHP.
Does it have to be that complicated? I'm pretty sure there were download buttons on web pages before there was Ajax.
Yeah, you can just redirect the browser to a URL that it would normally download (or one where you've set the content-disposition in the header). However, that requires PHP, which defeats the purpose of allowing Snap to run offline.
What you can do (what I was talking about above) is use a data: URL. The problem is, browsers don't know the filename and substitute fairly awful things. Firefox uses a (seemingly random) filename that ends in ".part" and Safari just uses "Unknown". I got around this by creating an "a" element and setting its 'download' attribute to the filename. Then, I created and dispatched a mouse event on the anchor (so the user doesn't have to click it). In all browsers, this downloads the file as something, but only Chrome pays attention to the 'download' attribute; the rest of the browsers just use the filenames described above.
Last edited by nXIII (2012-02-12 15:36:24)
Offline
bharvey wrote:
scimonster wrote:
AJAX+JS+PHP.
Does it have to be that complicated? I'm pretty sure there were download buttons on web pages before there was Ajax.
you could just have a php page that you send the information for the file as a post header, the php file could then spit out a text file (or whatever) using PHP Headers
edit: that page isn't helpful at all, let me find another.
edit2: try this one
Basically, you put something like this in a php page:
<?php header('Content-Type: application/octet-stream'); //octet stream is the download mime type. header('Content-Disposition: attachment; filename="example.txt"'); //specifies the filename that the user will download and how it will be accessed (use attachment basically) header('Content-Transfer-Encoding: 8bit'); //whether the file is binary or other types such as 8-bit and base 64. echo('contents of whatever you want example.txt to be') ?>
There is more stuff you can do such as caching, but you won't really need to do that as the output is going to be pretty dynamic.
Last edited by rookwood101 (2012-02-12 16:39:39)
Offline
nXIII wrote:
Firefox uses a (seemingly random) filename that ends in ".part"
I've seen those ".part" files, but for me, once the download is complete the file is renamed to whatever name I gave in the file dialog. (When I download a file from cnet or someplace like that, I don't even have to give a filename; it just works. But for saving projects, we want the user to give a name, at least the first time.)
I'd be happy with PHP on the snap.berkeley.edu site, if that'll let users click on a SAVE button without having any extra software on their own computer.
Offline
rookwood101 wrote:
you could just have a php page that you send the information for the file as a post header...
Awesome, write it and send Jens a changeset. (Don't post it here, send it to jens atsign moenig.org) The goal is that when you click on "save as" or when you click on "save" and the project doesn't have a name, it puts up a file browser or a morphic dialog, whatever works, to get the project name, then calls nXIII's serialization code and downloads the result into project.snap. And if you click on "save" and the project does have a name, it uses that.
Last edited by bharvey (2012-02-12 16:56:32)
Offline
bharvey wrote:
rookwood101 wrote:
you could just have a php page that you send the information for the file as a post header...
Awesome, write it and send Jens a changeset. (Don't post it here, send it to jens atsign moenig.org) The goal is that when you click on "save as" or when you click on "save" and the project doesn't have a name, it puts up a file browser or a morphic dialog, whatever works, to get the project name, then calls nXIII's serialization code and downloads the result into project.snap. And if you click on "save" and the project does have a name, it uses that.
I think one of you guys are probably best off doing it. My JavaScript skills are nowhere near as advanced as your's, Jens' or nXIII's and it would probably take me several days just to work out where to put everything and which function does what etc.
And I'm sure you can set up the php page to do that (if not I will) and also I'm sure you can send post headers to pages from within javascript. I quite like hanging around on this thread because I'm interested to see what you guys are doing, but I'm not at the level of actually being able to do anything yet
Offline
bharvey wrote:
rookwood101 wrote:
I think one of you guys are probably best off doing it.
OK, n, that's your cue.
I think we should work on a host for uploading projects that can be set up by schools, etc. instead of just making a file download mirror (which is the same as clicking "Share..." and saving the resulting text file). I can start to work on that after I finish the project importer (which, by the way, now works for all Scratch projects! )
Offline
Bug: the mod block is incorrect; it uses JS's % operator, which returns a number with the sign of its dividend, not its divisor like the BYOB mod block. For example, (-4 mod 3) should return 2, and (4 mod -3) should return -2.
Offline
Maybe it could use PHP to save the xml file on the internet and it will give you a unique project ID that you could use to open the project later.
Offline
I just managed to make a forever-looping block-- it was atomic too, so if you make an atomic block run forever BYOB crashes... any way to fix this?
Offline
rdococ wrote:
I just managed to make a forever-looping block-- it was atomic too, so if you make an atomic block run forever BYOB crashes... any way to fix this?
In BYOB 3 you can click the stop sign (may need to hold for a second or two). We don't have a stop sign in Snap! yet, but it's coming. Maybe you can stop your script by clicking on it again.
Last edited by bharvey (2012-02-13 10:16:54)
Offline
bharvey wrote:
rdococ wrote:
I just managed to make a forever-looping block-- it was atomic too, so if you make an atomic block run forever BYOB crashes... any way to fix this?
In BYOB 3 you can click the stop sign (may need to hold for a second or two). We don't have a stop sign in Snap! yet, but it's coming. Maybe you can stop your script by clicking on it again.
No, it was atomic, so Squeak wouldn't respond. I couldn't even change block categories or click anything.
Offline
rdococ wrote:
No, it was atomic, so Squeak wouldn't respond. I couldn't even change block categories or click anything.
Yes you can, you can click the stop sign. You may have to hold it down for a couple of seconds.
Offline
roijac wrote:
what's actually bad in this?
http://www.webmasterworld.com/forum91/3463.htm
just make it download a Snap! URI
That has to be a whole separate page, I think. We want to stay on the Snap! page after the save is complete.
Offline
joefarebrother wrote:
Maybe it could use PHP to save the xml file on the internet and it will give you a unique project ID that you could use to open the project later.
One of my colleagues suggested that unique-ID idea, but the user shouldn't have to remember a string of gibberish to retrieve the project later. It should be saved under the user-supplied name, or maybe something like userid_projectname.
Offline
bharvey wrote:
rdococ wrote:
No, it was atomic, so Squeak wouldn't respond. I couldn't even change block categories or click anything.
Yes you can, you can click the stop sign. You may have to hold it down for a couple of seconds.
i think you have to hold escape
Offline
bharvey wrote:
rdococ wrote:
No, it was atomic, so Squeak wouldn't respond. I couldn't even change block categories or click anything.
Yes you can, you can click the stop sign. You may have to hold it down for a couple of seconds.
Actually, I tried that when I accidentally put a small condition in to replace a really big condition, and I held the stop sign and it worked!
Offline
Another (fairly serious) bug: custom blocks don't show up in the palette when a project is opened. This is because the 'sprite' variable is closed into the action of each palette button, so it uses the old sprite to populate the palette.
Offline
Hi guys, its 14God, I decided to get a new profile to celebrate *&$*#^$^@*$*&#^@*$^$%# (censored for political correctness )
Offline
joefarebrother wrote:
i think you have to hold escape
That was true a couple of years ago, but not any more. As I said, if you're running an atomic script you may have to hold down the stop sign a second or so before BYOB notices, but it should always work.
Offline
Google Sites somehow is able to force the browser to download the file. They do that when you add ?d=1 at the end of an attachment URL. Without it, if it's an image or other browser-readable attachment, it doesn't download. Anyone know how to do that?
Offline