[Prototype-core] Re: Integration of something like ben nolan's behaviour?

2007-05-04 Thread Thomas Fuchs

To avoid possible confusion, I'd recommend a different name for apply 
(), as there's the JavaScript apply() method.

-thomas

Am 04.05.2007 um 08:51 schrieb Ben Nolan:

 I don't think the little snippet will do it.

 You want something like:

 Behaviour = {
 sheets_ : $A(),
 register : function(sheet){
   this.sheets_.push(sheet);
 },
 apply : function(){
   this.sheets_.each(** as above **);
 }
 }

 Ben

 On 5/4/07, chris [EMAIL PROTECTED] wrote:

 Would this solution be able to reapply the Behaviour rules to  
 elements
 that are dynamically added to the page?  Nolan's Behaviour.js has a
 Behaviour.apply() function that does this.

 cheers, chris

 On May 3, 7:12 pm, Mislav Marohnić [EMAIL PROTECTED]
 wrote:
 On 5/3/07, snarkyFish [EMAIL PROTECTED] wrote:

 Once, when we (the core guys) chatted working on the event  
 branch, I though
 of how easy it would be to re-implement Behaviour in Prototype:

 var Behaviour = {
   register: function(obj) {
 Event.onReady(function(){ for (sel in obj) $$(sel).each(obj 
 [sel]) })
   }

 }

 Yeah, this is it. You only need Event.onReady() for this. You can  
 find it in
 the event branch or you can copy it over from LowPro. Once  
 Event.onReady()
 gets into trunk, these 3 lines will probably be all you need.






 -- 
 Regards,
 Ben Nolan

 Moso Interactive

 skype: bennolan
 cell: +49 1577 383 7542

 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype: Core group.
To post to this group, send email to prototype-core@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~--~~~~--~~--~--~---



[Prototype-core] Re: Integration of something like ben nolan's behaviour?

2007-05-04 Thread G Jones

It would be quite useful to have the node that is passed to the
'rules' function be already extended (passed through $()).
I'm currently using a very similar bit of code:

var Behaviour = {
rulesets: [],
add: function(rules) {
Behaviour.rulesets.push(rules);
},
go: function() {
Behaviour.rulesets.each(function(ruleset) {
$H(ruleset).each(function(pair) {
$$(pair.key).each(function(node) {
pair.value($(node));
});
});
});
}
};


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype: Core group.
To post to this group, send email to prototype-core@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~--~~~~--~~--~--~---



[Prototype-core] Re: Integration of something like ben nolan's behaviour?

2007-05-04 Thread Радослав Станков

I use this for events assignment (with little extension of mine):
http://alternateidea.com/blog/articles/2006/3/21/introducing-css-event-selectors


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype: Core group.
To post to this group, send email to prototype-core@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~--~~~~--~~--~--~---



[Prototype-core] Re: Unexpected behaviour when using $A(document.getElementsByTagName(script))

2007-05-04 Thread Richard Quadling

On 03/05/07, jdalton [EMAIL PROTECTED] wrote:

 Hello Richard,

 First, this is not a $A() issue.

 When you called ''With Reporter' you wont get scritpaculous because
 your code is
 executing before scriptaculous is even rendered via the dom. (top
 down)

 The dom should be there onLoad though. If not try:

 Event.observe(window, 'load', function(){
 setTimeout(function(){
ReportJS('AfterLoad');
 }, 100);
 });

 Maybe dynamically added scripts need time to be seen in the dom,
 I used 100 miliseconds, but if that works i am sure any amount would
 like 10.


 



Hi. Thanks for the comments but I think I've not explained myself well enough.

Follow this through.

html
head
script tag with src to prototype.js
script tag with src to scriptaculous.js which will automatically load
the sub files
script tag with src to my library.js which mimics scriptaculous's
load() method for my sub files
/head
...

Nothing special in terms of timing is needed for scriptaculous to
work, even though it is dependent upon prototype.
My library is dependent upon scriptaculous and uses the SAME mechanism
to load additional sub files.
My code doesn't fail due to scriptaculous NOT being loaded (if it
couldn't find scriptaculous it would raise an error, just like
scriptaculous would if it couldn't find prototype).
In MY copy of the load() method, the result of
$A(document.getElementsByTagName(script)) does not include
MY script tag, EVEN THOUGH THE REPORTING OF THE SCRIPTS IS
ACTUALLY IN MY SCRIPT

The issue __is__ caching.

Here is my script...


raq.js
var RAQ_Common =
 {
 Version: '1.0.1',

 load: function()
  {
  if
   (
(typeof Scriptaculous=='undefined') ||
(typeof Element == 'undefined') ||
(typeof Element.Methods=='undefined') ||
parseFloat(Scriptaculous.Version.split(.)[0] + . +
Scriptaculous.Version.split(.)[1])  1.7
   )
{
throw(Richard Quadling's library requires the Scriptaculous
library = 1.7.0);
}

// This is the problem line. The CURRENT script will NOT be found.
// Instead a cached version of the results will be found.
  $A(document.getElementsByTagName(script)).findAll
   (
   function(s)
{
//Proof - the raq.js script will NOT be reported upon.
console.info(s);
return (!!s.src  s.src  s.src.match(/raq\.js(\?.*)?$/))
}
   ).each
(
function(s)
 {
 var path = s.src.replace(/raq\.js(\?.*)?$/,'');
 var includes = s.src.match(/\?.*load=([a-z,]*)/);
 (
 includes
  ? includes[1]
  : 
'additionalJS,enhanced_date,enhanced_element,enhanced_event,enhanced_math,enhanced_string'
 ).split(',').each
  (
  function(include)
   {
   Scriptaculous.require(path+include+'.js')
   }
  );
 }
  },
 }
RAQ_Common.load();


and a new HTML file

===js_write.html
html
head
script type=text/javascript
src=/global/javascript/prototype/prototype.js/script
script type=text/javascript
src=/global/javascript/script.aculo.us/scriptaculous.js/script
script type=text/javascript
src=/global/javascript/rquadling/raq.js/script
titleJS Test/title
/head
bodyHello/body
/html

With this code, my console now reads ...

script src=/global/javascript/prototype/prototype.js type=text/javascript
script src=/global/javascript/script.aculo.us/scriptaculous.js
type=text/javascript

But this is being reported from MY code which is loaded via script
type=text/javascript
src=/global/javascript/rquadling/raq.js/script

If I swap raq.js and scriptaculous around (and remove the dependency),
scriptaculous won't load all of its files as it won't be able to find
its own tag in the $A() results.




In re-reading your comments about the dynamically loaded scripts, I
think I see what I've not explained properly.

I'm not interested in the sub files that scripaculous loads. What I
have is scriptaculous makes the first call to $A to get the SCRIPTs.

When my code which is loaded via the normal mechanism of a SCRIPT tag,
the same call to get the list of loaded scripts doesn't include the
script CURRENTLY executing.

I can understand that the subscript from scriptaculous may not be
present and this I can understand as being related to the DOM needing
updating, but that is NOT the issue.

This is a caching issue.  Ideally I would like to flush the cache
prior to the my call. If I can do that, then I am confident that this
will work as expected.



-- 
-
Richard Quadling
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498r=213474731
Standing on the shoulders of some very clever giants!

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype: Core group.
To post to this group, send email to prototype-core@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en

[Prototype-core] Re: Integration of something like ben nolan's behaviour?

2007-05-04 Thread Mislav Marohnić
On 5/4/07, Радослав Станков [EMAIL PROTECTED] wrote:


 I use this for events assignment (with little extension of mine):

 http://alternateidea.com/blog/articles/2006/3/21/introducing-css-event-selectors


With the stuff we have in the event branch, you can do this:

Event.observe($$('#item li'), 'click', handler)

Feels more like a programming language than a DSL, right? I hope you look
forward to Prototype 1.6 :)

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype: Core group.
To post to this group, send email to prototype-core@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~--~~~~--~~--~--~---



[Prototype-core] Question/Suggestion

2007-05-04 Thread Tomasz R.

Hi,

I've recently started using prototype.js, but I've been doing AJAX
for long time now.

I've inspected the prototype.js code, and I think I've got an
interesting addition to the Object.extend.
I might have reinvent the wheel here, so if it's nothing new please
give me some pointers as to how to accomplish the same with the native
prototype.js code.

Basically, I was looking for a way to call the original function of an
extended object. Here is my modification:

// a new version of extend

Object.extend2 = function(destination, source) {

  for (var property in source) {
  if(destination[property]) {
  if(!destination['__super']) {
destination['__super'] = {};
  }
destination['__super'][property] = destination[property];
  }
  destination[property] = source[property];
  }
  return destination;
}

// code to be executed to see the behavior.
var a = Class.create();
a.prototype = {
initialize: function(name,link) {
this.elements = new Object();
},
test: function() {
alert('hello');
}
}

var b = Class.create();
b.prototype = Object.extend2(new a(), {
initialize: function() {

},

test: function() {
this.__super.test();
alert('hello2');
}
}
)

var B = new b();
B.test();

// END

after executing this code, you should first see the hello alert, and
then hello2.

I think this is an interesting addition, since I find myself often in
need to be able to access methods of the original object, without
having to copy/paste it's behavior to the new one.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype: Core group.
To post to this group, send email to prototype-core@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~--~~~~--~~--~--~---



[Prototype-core] Re: Unexpected behaviour when using $A(document.getElementsByTagName(script))

2007-05-04 Thread jdalton

Hello Richard,

This is the source of $A:

var $A = Array.from = function(iterable) {
  if (!iterable) return [];
  if (iterable.toArray) {
return iterable.toArray();
  } else {
var results = [];
for (var i = 0, length = iterable.length; i  length; i++)
  results.push(iterable[i]);
return results;
  }
};

Please show me where it caches values.

If you mimic scriptaculous's loader you shouldn't be having an issue.
I have done so many times with no issues. I notice you use findAll()
instead of find().
Here are my working examples:

/* * * * * * * * * * * * * * * * * * *
*
*  Load Common Classes
*
* * * * * * * * * * * * * * * * * * */

(function(){

  var require = function(libraryName) {
document.write('script type=text/javascript src='+libraryName
+'/script');
  };

  var script =
$A(document.getElementsByTagName(script)).find( function(s){
return (s.src  s.src.match(/common\.js(\?.*)?$/));
  });

  var path = script.src.replace(/common\.js(\?.*)?$/,'');
  var includes = ['script1','script2','script3'];

  includes.each(function(include){
require( path + include + '.js');
  });

})();

OR



/* * * * * * * * * * * * * * * * * * *
*
*  Controls (Singleton)
*
* * * * * * * * * * * * * * * * * * */

Controls = {

  require : function(libraryName) {
document.write('script type=text/javascript src='+libraryName
+'/script');
  },

  load : function(){

var script =
$A(document.getElementsByTagName(script)).find( function(s){
  return (s.src  s.src.match(/controls\.js(\?.*)?$/));
});

var path = script.src.replace(/controls\.js(\?.*)?$/,'');
var includes = script.src.match(/\?.*load=([a-z,]*)/i);

includes = (includes? includes[1] :
'control1,control2,control3').split(',');

includes.each(function(include){
  Controls.require( path + include + '.js');
  });
  }
};

Controls.load();


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype: Core group.
To post to this group, send email to prototype-core@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~--~~~~--~~--~--~---



[Prototype-core] Re: Question/Suggestion

2007-05-04 Thread Jerod Venema
Greetings!

Nice bit of code there! You may want to check out this:

http://www.ivy.fr/js/extend/index.html

if you're going down that road anyway...

-Jerod

On 5/4/07, Tomasz R. [EMAIL PROTECTED] wrote:


 Hi,

 I've recently started using prototype.js, but I've been doing AJAX
 for long time now.

 I've inspected the prototype.js code, and I think I've got an
 interesting addition to the Object.extend.
 I might have reinvent the wheel here, so if it's nothing new please
 give me some pointers as to how to accomplish the same with the native
 prototype.js code.

 Basically, I was looking for a way to call the original function of an
 extended object. Here is my modification:

 // a new version of extend

 Object.extend2 = function(destination, source) {

   for (var property in source) {
   if(destination[property]) {
   if(!destination['__super']) {
 destination['__super'] = {};
   }
 destination['__super'][property] = destination[property];
   }
   destination[property] = source[property];
   }
   return destination;
 }

 // code to be executed to see the behavior.
 var a = Class.create();
 a.prototype = {
 initialize: function(name,link) {
 this.elements = new Object();
 },
 test: function() {
 alert('hello');
 }
 }

 var b = Class.create();
 b.prototype = Object.extend2(new a(), {
 initialize: function() {

 },

 test: function() {
 this.__super.test();
 alert('hello2');
 }
 }
 )

 var B = new b();
 B.test();

 // END

 after executing this code, you should first see the hello alert, and
 then hello2.

 I think this is an interesting addition, since I find myself often in
 need to be able to access methods of the original object, without
 having to copy/paste it's behavior to the new one.


 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype: Core group.
To post to this group, send email to prototype-core@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~--~~~~--~~--~--~---



[Prototype-core] Object.extend() with Multiple Sources

2007-05-04 Thread Ken Snyder

Has it ever been proposed to change Object.extend() to accept multiple 
sources?


For example, instead of:

Object.extend(Object.extend(Ajax.Updater.prototype, 
Ajax.Request.prototype), {...}));


do the following:

Object.extend(Ajax.Updater.prototype, Ajax.Request.prototype, {...});


Here is a quick example rewrite:

Object.extend = function() {
  var sources = $A(arguments), destination = sources.shift();
  sources.each(function(source) {
for (var property in source) {
  destination[property] = source[property];
}
  });
  return destination;
}


Would core be interested in such a patch, or is there some drawbacks I'm 
missing?  Too much overhead maybe?

-- Ken Snyder

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype: Core group.
To post to this group, send email to prototype-core@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~--~~~~--~~--~--~---



[Prototype-core] Re: Question/Suggestion

2007-05-04 Thread Ryan Gahl
Also, check out:
http://www.someelement.com/2007/03/multiple-inheritance-with-prototypejs.html

This is my rendition of Kevin Lindsey's inheritance model, designed to
support multiple inheritance and play well with prototype.js

For what you're talking about, read the section near the bottom labeled So
how can you override base class methods and make sure that the original base
class method still gets called?

Object.extend works very well as a simple bulk property copying mechanism,
and as such does not need this extra jazz. I really think you're looking for
a true inheritance model, which Object.extend has never been, nor really
should be morphed into, IMHO.


On 5/4/07, Jerod Venema [EMAIL PROTECTED] wrote:

 Greetings!

 Nice bit of code there! You may want to check out this:

 http://www.ivy.fr/js/extend/index.html

 if you're going down that road anyway...

 -Jerod

 On 5/4/07, Tomasz R. [EMAIL PROTECTED] wrote:
 
 
  Hi,
 
  I've recently started using prototype.js, but I've been doing AJAX
  for long time now.
 
  I've inspected the prototype.js code, and I think I've got an
  interesting addition to the Object.extend.
  I might have reinvent the wheel here, so if it's nothing new please
  give me some pointers as to how to accomplish the same with the native
  prototype.js code.
 
  Basically, I was looking for a way to call the original function of an
  extended object. Here is my modification:
 
  // a new version of extend
 
  Object.extend2 = function(destination, source) {
 
for (var property in source) {
if(destination[property]) {
if(!destination['__super']) {
  destination['__super'] = {};
}
  destination['__super'][property] =
  destination[property];
}
destination[property] = source[property];
}
return destination;
  }
 
  // code to be executed to see the behavior.
  var a = Class.create();
  a.prototype = {
  initialize: function(name,link) {
  this.elements = new Object();
  },
  test: function() {
  alert('hello');
  }
  }
 
  var b = Class.create();
  b.prototype = Object.extend2(new a(), {
  initialize: function() {
 
  },
 
  test: function() {
  this.__super.test();
  alert('hello2');
  }
  }
  )
 
  var B = new b();
  B.test();
 
  // END
 
  after executing this code, you should first see the hello alert, and
  then hello2.
 
  I think this is an interesting addition, since I find myself often in
  need to be able to access methods of the original object, without
  having to copy/paste it's behavior to the new one.
 
 
 
 
 

 



-- 
Ryan Gahl
Software Architect
WebWidgetry.com / MashupStudio.com
Future Home of the World's First Complete Web Platform
Inquire: 1-262-951-6727
Blog: http://www.someElement.com

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype: Core group.
To post to this group, send email to prototype-core@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~--~~~~--~~--~--~---