Fade an Element





ranking Sort Sort   |   date Sort Sort   |   member Sort Sort
Syndication

« Previous 1 2  ...  5 6 7 8 9 10 11 12 13 Next »
10
Date Submitted Mon. Jun. 4th, 2007 2:37 PM
Revision 1
Scripter Fordiman
Tags createElement | JavaScript | kiss
Comments 1 comments
This is a function I created to ease headaches caused by creating and inserting new stuff in an HTML document dynamically. Essentially, it allows you to specify an HTML tag, in its entirety (attributes, styles, event handling, etc), via a single command. You can nest it, so as to create an entire element tree programmatically in a lot less time as with document.createElement.

Don't let the goofy function acronym fool you; this is damned powerful.

First, the function spec:
HTMLElement acne(type[,attributes[,styles[,events[,children[,parent[,document]]]]]]);

Arguments:
String type: type of element to create; same information as the argument of document.createElement
mixed Object attributes: attributes you want the new element to have (ie: href, src)
mixed Object styles: styles for the new element (ie: width, borderLeft)
(function|function Array) Object events: event handlers for the new element
HTMLElement|HTMLElement Array children: elements you want to be in the new element (ie: nesting is possible)
HTMLElement parent: parent node of object
HTMLDocument document: document to create element in

Return value: The newly created/configured element
6
Date Submitted Mon. Jun. 4th, 2007 3:06 PM
Revision 1
Scripter Fordiman
Tags "object passing" | JavaScript | PHP | serialize
Comments 6 comments
This is a quick set of overrides for Javascript so that any variable can be passed to PHP in a GET/POST activity. Just call myVar.toPHP();

I use this little set of functions extensively in a little Javascript/PHP RPC handler I wrote. I don't have the reverse function, as I pass JSON back to the browser for the return value.

Note: This lib is not safe for binaries or HTML Elements. The former will come out similar to FTP ASCII breaks, and the latter will cause infinite recursion. If you want to make a speical case for HTML Elements, do so; you could probably just test for parentNode and create a 'safe' object from that. I didn't need it, so I didn't code it.

As for binary safety, at some point between toPHP/escape/post/urldecode/unserialize, the object breaks. Rather than create a huge fix for something I didn't need to do, I put in a quick match/hack. Don't like it? Write the fix yourself.
5
Date Submitted Sat. Jun. 16th, 2007 6:07 AM
Revision 1
Scripter Fordiman
Tags Class | HTML | JavaScript
Comments 1 comments
Simple set of functions for capturing and manipulating the className member of an HTMLElement
7
Date Submitted Fri. Jul. 20th, 2007 11:12 PM
Revision 1
Helper lavaramano
Tags Array | getelementsby | JavaScript
Comments 1 comments
Returns an array with all the objects with certain class. tested on IE 6 and Firefox 2
6
Date Submitted Fri. Jul. 20th, 2007 11:17 PM
Revision 1
Helper lavaramano
Tags DOM | JavaScript | Key | onkeyup
Comments 0 comments
Returns the keycode of the key we wrote on a textarea/input. works on IE and Firefox
6
Date Submitted Fri. Jul. 20th, 2007 11:42 PM
Revision 1
Helper lavaramano
Tags DOM | JavaScript | mouse | onclick | pointer
Comments 1 comments
it give us the position of the mouse. works on IE and Firefox

use:
onclick="posicion_mouse(event)"
3
Date Submitted Tue. Sep. 25th, 2007 10:50 AM
Revision 1
Helper chaos
Tags "form input" | "input focus" | autofocus | JavaScript
Comments 0 comments
This script performs reliable, cross-browser input autofocus that often can be used simply by dropping it in, with no modifications to the form or HTML body. It refuses to switch focus if it detects that the user has interacted with the form (avoiding a major source of annoyance with autofocus scripts) and correctly handles Firefox tabs opened "in the background", which most autofocus scripts fail on. Official home is on the Lost Souls MUD Grimoire.
5
Date Submitted Thu. Sep. 27th, 2007 8:02 AM
Revision 1
Scripter Fordiman
Tags JavaScript | PHP | Prototype | serialize
Comments 2 comments
This is the final version of my Javascript serializer targetted at PHP.

The point:
Objects are most easily passed over the network as serialized strings. Between serialization and unserialization, serialization is by far the easier of the two. Since object passing can sometimes be a process-hungry thing, we want to do things as quickly as possible.

My solution is to always do the hard part in compiled code, while doing the easy part in script. That is, whichever way you're passing an Object, you want to pass it in a natively decoded format for the target.

Since I work mostly in PHP, this meant writing a module that would be able to generate a string that can be decoded with PHP's unserialize() function into a PHP Associative Array (or other applicable type).

Notes:
This lib REQUIRES the Prototype lib. You can hack prototype out of it, of course (by replacing the references to Object.extend() with explicit assignments), but I can't imagine why you'd want to bother; it's used mostly with Ajax.Request anyway.

Previous versions of this code would add the .toPHP() member to the Object prototype. After trying to enumerate things, I found that this is a REALLY bad thing to do, as toPHP springs up where it's not wanted in ALL objects. As a result, I've opted to go the Prototype route and apply it as a member of the Object object.

Please note that if you pass a serialized string to PHP via GET or POST, you'll need to stripslashes() before unserialization.



Javascript sample of use:

var myObject = {
name:'value',
test:['Array','of','strings'],
bool:false,
timestamp: new Date(),
float: 3.1415926539,
number: 42,
func: function () {
alert('Member functions are always omitted from serialization');
}
}
alert(Object.toPHP(myObject));

Output:
a:7:{s:4:"name";s:5:"value";s:4:"test";a:3:{i:0;s:5:"Array";i:1;s:2:"of";i:2;s:7:"strings";}s:4:"bool";b:0;s:9:"timestamp";i:1190897619824;s:5:"float";d:3.1415926539;s:6:"number";i:42;s:4:"func";null}


Sample of subsequent unserialization in PHP (passed via POST as 'myobject')

$myObject=unserialize(stripslashes($_POST['myobject']));
var_dump($myObject);

Output:
array(7) {
["name"]=>
string(5) "value"
["test"]=>
array(3) {
[0]=>
string(5) "Array"
[1]=>
string(2) "of"
[2]=>
string(7) "strings"
}
["bool"]=>
bool(false)
["timestamp"]=>
int(1192296601)
["float"]=>
float(3.1415926539)
["number"]=>
int(42)
["func"]=>
NULL
}
6
Date Submitted Fri. Sep. 28th, 2007 2:08 AM
Revision 1
Scripter Fordiman
Tags JavaScript | promise | Prototype
Comments 6 comments
Here's a quick lil' addon for Prototype that I use often.

Prototype.Promise(condition, action, interval)
condition is a string that you want met before an action is run.
action is a function that does the action.
interval is the polling rate for condition in seconds, and defaults to 1

So, for example, you may want function foo to run, but only once bar has been set:

function foo(a,b) {
this.retVal=a+b;
}
var thingy = {
retVal:0
};
Prototype.Promise(
'thingy.retVal=5',
foo.bind(thingy,5,10),
5
);


Then, in some point in the mysterious future, thingy.retVal gets set to 5, at which point, the Promise goes into effect, and thingy.retVal becomes 10.

Where I find this particularly useful is in making sure that a document is loaded before doing something (condition="$$('body').length>=1), as you can see it used for the include functions.

Speaking of which, the following include functions are great for getting scripts and stylesheets into your page. I won't bother with examples, as they're pretty straightforward.

Meanwhile, Prototype.scriptPath will point to wherever in your server's heirarchy Prototype was loaded from. The regex, you'll note allows for names like prototype.compressed.js, prototype.modified.js, 2007-09-28.prototype.js, etc - just in case you want to keep track of your various hacks of Prototype, as I do.
3
Date Submitted Sun. Oct. 7th, 2007 3:47 AM
Revision 1
Helper chaos
Tags "diminishing returns" | formula | JavaScript | math
Comments 0 comments
A simple, flexible formula for generating diminishing returns out of input numbers. Full explanation and home, with sample calculators and versions of the code in other languages, on the Lost Souls MUD Grimoire.
« Previous 1 2  ...  5 6 7 8 9 10 11 12 13 Next »