This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#51 2011-11-12 14:08:57

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Web-languages: Help and helper thread

Hardmath, I like the NEW! idea  smile

Last edited by sparks (2011-11-12 14:09:26)


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#52 2011-11-13 04:31:24

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: Web-languages: Help and helper thread

sparks wrote:

Hardmath, I like the NEW! idea  smile

http://www.gifanimations.com/GA/Image/Animations/Messages/New/new_003.gif


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#53 2011-11-13 04:32:14

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Web-languages: Help and helper thread

That just hurts my eyes  tongue


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#54 2011-11-13 04:45:23

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: Web-languages: Help and helper thread

sparks wrote:

That just hurts my eyes  tongue

Just an idea... It hurts mine, too. Maybe text will suffice.  tongue


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#55 2011-11-13 05:01:46

WindowsExplorer
Scratcher
Registered: 2011-02-25
Posts: 1000+

Re: Web-languages: Help and helper thread

.

Last edited by WindowsExplorer (2011-11-13 05:02:51)


http://i.imgur.com/H6LLdnK.pnghttp://i.imgur.com/VYuD7BY.png

Offline

 

#56 2011-11-13 05:07:40

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: Web-languages: Help and helper thread

WindowsExplorer wrote:

.

AAA! Seizure!

...

tongue


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#57 2011-11-13 05:11:39

ssss
Scratcher
Registered: 2007-07-29
Posts: 1000+

Re: Web-languages: Help and helper thread

Hardmath123 wrote:

WindowsExplorer wrote:

.

AAA! Seizure!

...

tongue

If that gave you a seizure check out this


Hey.  It's me SSSS, back from the dead!  smile

Offline

 

#58 2011-11-13 05:13:39

Qwiffles
Scratcher
Registered: 2011-07-13
Posts: 100+

Re: Web-languages: Help and helper thread

Wow.  This looks like it'll be really helpful!  I'll be sure to check them out, and submit my own when I am up to it!
Thanks for these, Sparks.


Don't feed a pet troll.  It will turn evil.

Offline

 

#59 2011-11-13 15:24:00

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: Web-languages: Help and helper thread

Some JS stuff:


Use MDN and not w3schools


In almost every case, it is better to use the identity operator than the equality operator[/url] because the equality operator behaves strangely. Leaving out semicolons is a bad idea, because odd things can happen:

Code:

var a;
a = 2
(a + 2).toString();
// throws a TypeError because 2 is treated as a function
// same as:
a = 2(a + 2).toString();

Self-evaluating (or self-invoking, etc.) functions are closures (functions without names) that call themselves in the expression they're created in. They're incredibly useful for controlling scope:

Code:

(function () { // construct a closure...
var a = 2;
console.log(a); // 2
})(); // ... and call it
console.log(a); // a is undefined

Method calls are really just a property access + a function call:

Code:

(function () {
var foo = window.alert; // property access
foo(2); // function call
})();

The "global scope" means the window object in most cases - it's the place variables are looked up/defined if they're not found elsewhere:

Code:

var foo = 2; // window.foo = 2
(function () {
var bar = 3;
console.log(bar); // 3
console.log(foo); // 2
})();

The "window" object actually has a "window" property, which is what is being accessed when you use window without defining it elsewhere. It is perfectly legal to do that anywhere but in the global scope:

Code:

window = 'foo';
console.log(window); // the window object
(function () {
var window = 2;
console.log(window); // 2
})();

JavaScript actually uses prototypal inheritance (a different system of inheritance than classical, which is what programming languages like Java and Smalltalk use). This means that any object can inherit from any other object:

Code:

var foo = { // object literal; constructs an Object with the properties between the braces
    a: 2
};
var bar = Object.create(foo); // create a new Object which inherits from foo

// properties which are not part of objects are looked up in their prototype, and that object's prototype, and so on
console.log(bar.a); // 2

// you can change an object's prototype's property (or add/remove) one,
// and the change is visible in the objects which inherit from it
foo.a = 8;
console.log(bar.a); // 8

// it's fine to define properties that are present in an object's prototype
bar.a = 3;
console.log(bar.a); // 3

// ... but doing this has no effect on the prototype
console.log(foo.a); // 8

The new keyword creates a new object which inherits from its argument's prototype, then calls its argument (a function) with that object as the value of "this"

Code:

function F() {
    this.a = 2;
}
var foo = new F();
// same as...
var foo = F.apply(Object.create(F.prototype));

Apply is a method of Function objects which applies the function to the given arguments (an array, the 2nd argument) using the 1st argument as the "this" value)

When making constructors, use the prototype object, because:
1) all instances of the constructor inherit their methods from one object (this uses less memory)
2) all instances' methods are identical--they are the same object, rather than being functions which have the same contents

Code:

function UsePrototype() {}
UsePrototype.aMethod = function () {
    console.log('hi');
};
function DontUsePrototype() {
    this.aMethod = function () {
        console.log('hi');
    };
}
var a = new UsePrototype();
var b = new UsePrototype();
a.aMethod === b.aMethod; // true

a = new DontUsePrototype();
b = new DontUsePrototype();
a.aMethod === b.aMethod; // false

The naming convention is to capitalize constructors:

Code:

function Constructor() {} // constructor!
new Constructor();
function someFunction() {} // not a constructor!
someFunction();

EDIT: I will probably write a prototype-based JS tutorial soon, explaining things in more detail.

Last edited by nXIII (2011-11-13 15:24:18)


nXIII

Offline

 

#60 2011-11-13 16:16:33

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Web-languages: Help and helper thread

Thanks, n, that's certainly going under "Hard" as a tutorial difficulty, I hope that's what you had in mind as a lot of things are taken for granted that you know  smile  You have a loose[/url] tag on the 4th line of text, too  smile  Otherwise, very good!


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#61 2011-11-13 19:41:18

midnightleopard
Scratcher
Registered: 2007-09-13
Posts: 1000+

Re: Web-languages: Help and helper thread

hmm this is pretty cool! I have some html things worth posting.


http://pwp.wizards.com/5103673563/Scorecards/Landscape.png

Offline

 

#62 2011-11-14 05:23:57

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: Web-languages: Help and helper thread

^ Home
HTML — False Floating Windows
Difficulty: Hard
False Floating Windows (FFWs) are fake windows within an HTML page. This can be useful if you want to, for example, bring up a pop-up with a customized interface.
To begin with, let's start with some CSS:

Code:

div.FFW
{
 position: absolute;
 top: 0;
 left: 0;
 z-index: 1000;
}

All this does is make sure FFW class divs 'float' above the page.
Now, let's add the div to a page:

Code:

<div class="FFW" id="myWin">Hey, there!</div>

Notice how the text on the window covers up text on the document. Let's add this line in our CSS to prevent that by adding a background to the whole div.

Code:

 background-color: #FFFFFF;

The div shrink-wraps into the text. Let's give it a structured width:

Code:

 width: 300px;

Now let's add a toolbar. Put this inside your <div>:

Code:

<div id="toolbar-myWin" style="background-color:blue;"><button onclick="document.getElementById('myWin').style.display='none';">(x)</button></div>

All together now:

Code:

<style type="text/css">
div.FFW
{
 position: absolute;
 top: 0;
 left: 0;
 z-index: 1000;
 width: 300px;
background-color: #FFFF99;
}
</style>
<div class="FFW" id="myWin"><div id="toolbar-myWin" style="background-color:blue;"><button onclick="document.getElementById('myWin').style.display='none';">(x)</button></div>Hey, there!</div>

^ Home

Last edited by Hardmath123 (2011-11-14 08:42:37)


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#63 2011-11-14 18:43:11

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Web-languages: Help and helper thread

Nice tutorial, Hardmath123, IDK if this is just because of my viewpoint, but I would class that as a moderate not hard tutorial  smile  It's very good!

Last edited by sparks (2011-11-14 18:44:06)


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#64 2011-11-15 08:50:30

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: Web-languages: Help and helper thread

sparks wrote:

Nice tutorial, Hardmath123, IDK if this is just because of my viewpoint, but I would class that as a moderate not hard tutorial  smile  It's very good!

Though I agree the tutorial itself is moderate, I can't really think of anything harder for just HTML. Here's how I would group HTML tutorials:

Easy
• Explains one tag or attribute's usage or special trick.
• Written for somebody with no/little background knowledge in HTML
• Does not have references to other languages (CSS/JS/PHP)
• Mainly teaches how to add visual effects (eg borders)

Moderate
• Involved grouping of many elements and attributes
• May need some background knowledge
• Uses some CSS styles
• Adds interactivity that doesn't need (much) programming (eg change anchor color on rollover)

Hard
• Involves many nested or grouped elements
• References from many languages (JS/CSS/PHP)
• Needs lots of background knowledge about how many special elements work
• Adds interactive effects that need programming (eg search bar)

EDIT: I think you need a CSS section, too.

Last edited by Hardmath123 (2011-11-15 08:54:08)


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#65 2011-11-18 17:01:28

AverageMonkey
Scratcher
Registered: 2011-11-16
Posts: 59

Re: Web-languages: Help and helper thread

I need help. (I'm PF, btw)
Um, so yes. This is a blog app that stores each post in the xml file, posts.xml.
Currently, it is not reading....

Code:

<?php
//blogify.php
//Blog App.
//Made by ProgrammingFreak
$app = "Blogify";
$style = "
#blog_app{
max-height: 600;
max-width:900;
height: 600;
width: 900;
display: none;
background-color: #4B79AD;

}
#blog_app button{
background: #1e5799;
background: -moz-linear-gradient(top,  #1e5799 0%, #2989d8 28%, #207cca 51%, #7db9e8 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#1e5799), color-stop(28%,#2989d8), color-stop(51%,#207cca), color-stop(100%,#7db9e8));
background: -webkit-linear-gradient(top,  #1e5799 0%,#2989d8 28%,#207cca 51%,#7db9e8 100%);
background: -o-linear-gradient(top,  #1e5799 0%,#2989d8 28%,#207cca 51%,#7db9e8 100%);
background: -ms-linear-gradient(top,  #1e5799 0%,#2989d8 28%,#207cca 51%,#7db9e8 100%);
background: linear-gradient(top,  #1e5799 0%,#2989d8 28%,#207cca 51%,#7db9e8 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#1e5799', endColorstr='#7db9e8',GradientType=0 );

border-style:solid;
border-color:#1e5799;
color: #fff;
}
#menu{
background-color:#1e5799;
width: 900px;
}
#menu img{
    margin-left: 5px;
    margin-top: 5px;
    margin-bottom: -5px;
}
";
echo <<<_END
    <html><head><style>$style</style>
        <script src="http://code.jquery.com/jquery-latest.js"></script>
        <script type="text/javascript">
        $(document).ready(function(){
        $.get("data.php", function(data){
                $("#blog_app").fadeIn(2000);
                $('#blog_app').html(data);
        });

        });
        if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.open("GET","pages.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;

$("#content").html(xmlDoc.childNodes[0].nodeValue); 
$("#content").html("hello"); 
    </script>
    </head><body>
    <div id='blog_app'>
    </div>

    </body></html>
_END;
?>

Code:

//posts.xml
<posts>
    <post>
    <author>%uservar%</author>
    <content>Welcome to Blogify.</content>
    </post>
</posts>

Code:

<?php
//data.php
echo <<<_END
        <div id="menu">
        <img src="logo.png" height="20px" width="20px"/>
        <button id='new'>New Post</button><button id='del' onclick>Delete Post</button>
        </div>
        <div id="content"></div>
_END;
?>

Thanks.  wink

Offline

 

#66 2011-11-18 17:55:19

AverageMonkey
Scratcher
Registered: 2011-11-16
Posts: 59

Re: Web-languages: Help and helper thread

bump

Offline

 

#67 2011-11-18 22:26:38

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: Web-languages: Help and helper thread

Has it read the xml file before? If it has, I'm not sure. If it hasn't, maybe put the file into a variable?

Offline

 

#68 2011-11-19 03:46:50

fanofcena
Scratcher
Registered: 2008-07-03
Posts: 1000+

Re: Web-languages: Help and helper thread

just go to Mozilla documentation  smile  .. its all you need for javascript / CSS / HTML


http://i53.tinypic.com/2vxr2c0.png Click whats above u might make a cute planet happy ^_^

Offline

 

#69 2011-11-19 17:31:07

AverageMonkey
Scratcher
Registered: 2011-11-16
Posts: 59

Re: Web-languages: Help and helper thread

Magnie wrote:

Has it read the xml file before? If it has, I'm not sure. If it hasn't, maybe put the file into a variable?

Okay, I'll try that...

Offline

 

#70 2011-11-19 17:53:05

MathWizz
Scratcher
Registered: 2009-08-31
Posts: 1000+

Re: Web-languages: Help and helper thread

https://developer.mozilla.org/media/img/mdn-logo-compact.png
http://4.bp.blogspot.com/-w1B-z-ZFnN0/Tmcktva8LYI/AAAAAAAAAJA/w_LYbJhc80E/s320/HTML5Rocks.png
http://www.nickawilliams.com/wp-content/uploads/2008/09/stackoverflow.png
big_smile

Last edited by MathWizz (2011-12-16 18:07:09)


http://block.site90.net/scratch.mit/text.php?size=30&amp;text=%20A%20signature!&amp;color=333333

Offline

 

#71 2012-02-27 17:26:36

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Web-languages: Help and helper thread

In true search engine guruing and great memory, I am posting this question in a relevant thread!

Does anyone know much about cookies? I wanted to get cookie based login working on my website. Then I got really confused.

See, cookies are just little text files stored on your computer. So what's to stop me storing a cookie with the username of the last login in it? Nothing. But then the user could simply change the contents of the cookie with a text-editor so that the name matches another user, then get logged in AS THEM  yikes

Similarly, if I stored the password too, that's a huge security hole for THEM as that cookie can then be used by anyone to log in, just by copying it. No web pages I have found seem to answer this problem, so how can I use cookies for logging in without posing a security risk for either myself or the user????????

Thanks,

Sparks


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#72 2012-02-27 17:33:12

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: Web-languages: Help and helper thread

sparks wrote:

In true search engine guruing and great memory, I am posting this question in a relevant thread!

Does anyone know much about cookies? I wanted to get cookie based login working on my website. Then I got really confused.

See, cookies are just little text files stored on your computer. So what's to stop me storing a cookie with the username of the last login in it? Nothing. But then the user could simply change the contents of the cookie with a text-editor so that the name matches another user, then get logged in AS THEM  yikes

Similarly, if I stored the password too, that's a huge security hole for THEM as that cookie can then be used by anyone to log in, just by copying it. No web pages I have found seem to answer this problem, so how can I use cookies for logging in without posing a security risk for either myself or the user????????

Thanks,

Sparks

You verify the name and a "key" with the database or something similar.

What I've done is, when a user logs in, a random (probably best to make a truly random) key and save it to the user's cookie and to the database. Then check the key and username against the database.

Only problem with this method, is that user's can copy the cookie onto another computer and it will work for them. But that is true for all websites.

Offline

 

#73 2012-02-27 17:50:08

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Web-languages: Help and helper thread

Right. First of all, there is no such thing as true random, so what do you mean by that? Will the php rand() function do? And in that case, wouldn't a hash of their password do as well? (thank you  smile  )


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#74 2012-02-27 17:52:21

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: Web-languages: Help and helper thread

sparks wrote:

In true search engine guruing and great memory, I am posting this question in a relevant thread!

Does anyone know much about cookies? I wanted to get cookie based login working on my website. Then I got really confused.

See, cookies are just little text files stored on your computer. So what's to stop me storing a cookie with the username of the last login in it? Nothing. But then the user could simply change the contents of the cookie with a text-editor so that the name matches another user, then get logged in AS THEM  yikes

Similarly, if I stored the password too, that's a huge security hole for THEM as that cookie can then be used by anyone to log in, just by copying it. No web pages I have found seem to answer this problem, so how can I use cookies for logging in without posing a security risk for either myself or the user????????

Thanks,

Sparks

You could hash the password and store that and the username (or use a random key, although just hashing means you don't need to store any additional data); alternatively you could store the session ID in a cookie. That way, if the cookie was copied to another computer, it would only work while the user was still logged in.


nXIII

Offline

 

#75 2012-02-27 18:39:53

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Web-languages: Help and helper thread

nXIII wrote:

sparks wrote:

In true search engine guruing and great memory, I am posting this question in a relevant thread!

Does anyone know much about cookies? I wanted to get cookie based login working on my website. Then I got really confused.

See, cookies are just little text files stored on your computer. So what's to stop me storing a cookie with the username of the last login in it? Nothing. But then the user could simply change the contents of the cookie with a text-editor so that the name matches another user, then get logged in AS THEM  yikes

Similarly, if I stored the password too, that's a huge security hole for THEM as that cookie can then be used by anyone to log in, just by copying it. No web pages I have found seem to answer this problem, so how can I use cookies for logging in without posing a security risk for either myself or the user????????

Thanks,

Sparks

You could hash the password and store that and the username (or use a random key, although just hashing means you don't need to store any additional data); alternatively you could store the session ID in a cookie. That way, if the cookie was copied to another computer, it would only work while the user was still logged in.

That's a good idea! Wouldn't the session id change when the session expires though?


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

Board footer