Skip to content

Commit

Permalink
Merge branch 'master' of http://github.com/arian/mootools-core
Browse files Browse the repository at this point in the history
  • Loading branch information
kamicane committed May 9, 2010
2 parents 9bcfc28 + b8dc1b7 commit 3e4ec6c
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 132 deletions.
72 changes: 67 additions & 5 deletions Docs/Core/Core.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,57 @@ Copies all the properties from the second object passed in to the first object p
This method is an object-specific equivalent of *$extend* from MooTools 1.2.


Function method: extend {#extend}
---------------------------------

Add methods to a function

### Syntax:

myFunction.extend(key,value);

### Arguments:

1. key - (*string*) The key of the prototype
2. value - (*mixed*) The function or another value of the protoype

### Example:

var myFunction = function(){};
myFunction.extend('alert',function(text){
alert(text);
});
myFunction.alert('Hello!'); // Alerts Hello!


Function method: implement {#implement}
---------------------------------------

Add methods to the prototype

### Syntax:

myFunction.implement(key,value);

### Arguments:

----------------------
1. key - (*string*) The key of the prototype
2. value - (*mixed*) The function or another value of the protoype


----------------------
### Example:

var myFunction = function(){};
myFunction.implement('alert',function(text){
alert(text);
});
var myInstance = new myFunction();
myInstance.alert('Hello!'); // Alerts Hello!

### Notes:

The difference between *implement* and *extend*, is that implement adds the value to the prototype.
So with *implement* each instance of the function will have this method or property while with *extend*
the method or property is added to a single instance.

Deprecated Functions {#Deprecated-Functions}
============================================
Expand All @@ -252,15 +297,30 @@ If you really need this function you can implement it like so:
Function: $clear {#clear}
-------------------------

This method has been deprecated. Please use [Function:clear](/core/Types/Function/#clear) instead.
This method has been deprecated. Please use *clearInterval* or *clearTimeout* instead.

### See Also:

- [MDC clearTimeout][], [MDC clearInterval][]


Function: $defined {#defined}
-----------------------------

This method has been deprecated. Please use [nil](#nil) instead.
This method has been deprecated.

If you really need this function you can implement it like so:

### Example:

var $defined = function(obj){
return (obj != undefined);
};

// Or just use it like this
if(obj != undefined){
// Do something
}


Function: $arguments {#arguments}
Expand Down Expand Up @@ -411,3 +471,5 @@ This method has been deprecated. Please use [typeOf](#typeOf) instead.
[Function:bind]: /core/Types/Function/#bind
[Function:delay]: /core/Types/Function/#delay
[Function:periodical]: /core/Types/Function/#periodical
[MDC clearInterval]: https://developer.mozilla.org/en/DOM/window.clearInterval
[MDC clearTimeout]: https://developer.mozilla.org/en/DOM/window.clearTimeout
134 changes: 14 additions & 120 deletions Docs/Types/Function.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,48 +42,6 @@ This function is equivalent to the following deprecated MooTools 1.2 methods:
var fn2 = Function.from(foo); // Equivalent to var fn2 = $lambda(foo);



Function method: extend {#extend}
---------------------------------


Function method: implement {#implement}
---------------------------------------


Function method: clear {#clear}
-------------------------------

Clears a Timeout or an Interval. Useful when working with [Function:delay](#delay) and [Function:periodical](#periodical).

### Syntax:

myTimer.clear(timer);

### Arguments:

1. timer - (*number*) The identifier of the setInterval (periodical) or setTimeout (delay) to clear.

### Returns:

* (*null*) returns null.

### Example:

var myTimer = myFunction.delay(5000); //Waits 5 seconds then executes myFunction.
myTimer = myTimer.clear(); //Cancels myFunction.

### See also:

- [Function:delay][]
- [Function:periodical][]

### Notes:

This method is equivalent to *$clear* from MooTools 1.2.



Function method: Function.attempt {#attempt}
-----------------------------

Expand Down Expand Up @@ -234,78 +192,6 @@ Changes the scope of `this` within the target function to refer to the bind para
myBoundFunction(); //This will make myElement's text red.



Function method: bindWithEvent {#bindWithEvent}
-----------------------------------------------

Changes the scope of `this` within the target function to refer to the bind parameter. It also makes "space" for an event.
This allows the function to be used in conjunction with [Element:addEvent][] and arguments.

### Syntax:

myFunction.bindWithEvent([bind[, args]]);

### Arguments:

1. bind - (*object*, optional) The object that the "this" of the function will refer to.
2. args - (*mixed*, optional) The arguments to pass to the function (must be an array if passing more than one argument).

### Returns:

* (*function*) The bound function.

### Example:

var Logger = new Class({
log: function(){
console.log.apply(null, arguments);
}
});

var Log = new Logger();

$('myElement').addEvent('click', function(event, offset){
offset += event.client.x;
this.log('clicked; moving to:', offset); // this refers to myClass
event.target.setStyle('top', offset);
return false;
}.bindWithEvent(Log, 100));



Function method: attempt {#attempt}
-----------------------------------

Tries to execute the function.

### Syntax:

var result = myFunction.attempt([args[, bind]]);

### Arguments:

1. args - (*mixed*, optional) The arguments to pass to the function (must be an array if passing more than one argument).
2. bind - (*object*, optional) The object that the "this" of the function will refer to.

### Returns:

* (*mixed*) The function's return value or `null` if an exception is thrown.

### Example:

var myObject = {
'cow': 'moo!'
};

var myFunction = function(){
for (var i = 0; i < arguments.length; i++){
if(!this[arguments[i]]) throw('doh!');
}
};
var result = myFunction.attempt(['pig', 'cow'], myObject); //result = null



Function method: delay {#delay}
-------------------------------

Expand All @@ -328,16 +214,20 @@ Delays the execution of a function by a specified duration.
### Example:

var myFunction = function(){ alert('moo! Element id is: ' + this.id); };
//Wait 50 milliseconds, then call myFunction and bind myElement to it.
// Wait 50 milliseconds, then call myFunction and bind myElement to it.
myFunction.delay(50, myElement); //Alerts: 'moo! Element id is: ... '

//An anonymous function which waits a second and then alerts.
// An anonymous function which waits a second and then alerts.
(function(){ alert('one second later...'); }).delay(1000);

// To stop the delay, clearTimeout can be used like so
var timer = myFunction.delay(50);
clearTimeout(timer);


### See Also:

- [$clear][], [MDC setTimeout][]
- [MDC setTimeout][], [MDC clearTimeout][]



Expand Down Expand Up @@ -365,20 +255,24 @@ Executes a function in the specified intervals of time. Periodic execution can b
var Site = { counter: 0 };
var addCount = function(){ this.counter++; };
addCount.periodical(1000, Site); //Will add the number of seconds at the Site.


// The interval can be stopped using the clearInterval function
var timer = myFunction.periodical(1000);
clearInterval(timer);

### See Also:

- [$clear][], [MDC setInterval][]
- [MDC setInterval][], [MDC clearInterval][]



[options]: #Function:create:options
[Element:addEvent]: /core/Element/Element.Event/#Element:addEvent
[$clear]: /core/Core/Core/#clear
[MDC Function]: https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Function
[MDC setInterval]: https://developer.mozilla.org/en/DOM/window.setInterval
[MDC setTimeout]: https://developer.mozilla.org/en/DOM/window.setTimeout
[MDC clearInterval]: https://developer.mozilla.org/en/DOM/window.clearInterval
[MDC clearTimeout]: https://developer.mozilla.org/en/DOM/window.clearTimeout
[Function:delay]: /core/Types/Function/#delay
[Function:periodical]: /core/Types/Function/#periodical

14 changes: 7 additions & 7 deletions Source/Types/Event.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,22 @@ var Event = new Type('Event', function(event, win){
if (fKey > 0 && fKey < 13) key = 'f' + fKey;
}
key = key || String.fromCharCode(code).toLowerCase();
} else if (type.match(/(click|mouse|menu)/i)){
} else if (type.test(/click|mouse|menu/i)){
doc = (!doc.compatMode || doc.compatMode == 'CSS1Compat') ? doc.html : doc.body;
var page = {
x: event.pageX || event.clientX + doc.scrollLeft,
y: event.pageY || event.clientY + doc.scrollTop
x: (event.pageX != null) ? event.pageX : event.clientX + doc.scrollLeft,
y: (event.pageY != null) ? event.pageY : event.clientY + doc.scrollTop
};
var client = {
x: (event.pageX) ? event.pageX - win.pageXOffset : event.clientX,
y: (event.pageY) ? event.pageY - win.pageYOffset : event.clientY
x: (event.pageX != null) ? event.pageX - win.pageXOffset : event.clientX,
y: (event.pageY != null) ? event.pageY - win.pageYOffset : event.clientY
};
if (type.match(/DOMMouseScroll|mousewheel/)){
if (type.test(/DOMMouseScroll|mousewheel/)){
var wheel = (event.wheelDelta) ? event.wheelDelta / 120 : -(event.detail || 0) / 3;
}
var rightClick = (event.which == 3) || (event.button == 2);
var related = null;
if (type.match(/over|out/)){
if (type.test(/over|out/)){
switch (type){
case 'mouseover': related = event.relatedTarget || event.fromElement; break;
case 'mouseout': related = event.relatedTarget || event.toElement;
Expand Down

0 comments on commit 3e4ec6c

Please sign in to comment.