Permalink
Browse files

demo page bugfixed.

Signed-off-by: Noritaka Horio <holy.shared.design@gmail.com>
  • Loading branch information...
1 parent 658b818 commit 20e56634ae59426eb9579b94738f0c08eb4306ad @holyshared committed May 27, 2011
Showing with 198 additions and 42 deletions.
  1. +52 −0 Build/mixin.js
  2. +9 −3 Demos/index.html
  3. +51 −0 Demos/js/mixin.js
  4. +5 −9 Demos/js/mock.js
  5. +15 −0 Demos/js/runner.js
  6. +27 −5 README.md
  7. +7 −4 Source/Class.Attachment.js
  8. +0 −17 Tests/Class.Attachment.html
  9. +28 −0 Tests/Mixin.Attachment.html
  10. +4 −4 package.yml
View
@@ -0,0 +1,52 @@
+/*
+---
+name: Attachment
+
+description: The function to be attached to the class of the event in each selector is built in.
+
+license: MIT-style
+
+authors:
+- Noritaka Horio
+
+requires:
+ - Core/Type
+ - Core/Function
+ - Core/$$
+ - Core/Element
+ - Core/Elements
+ - Core/Element.Event
+ - Core/Class
+
+provides: [Attachment]
+
+...
+*/
+
+(function($$){
+
+var Attachment = this.Attachment = new Class({
+
+ _attachHandlers: {},
+
+ attach: function(selecter){
+ if (!Type.isFunction(this.attachHandler)){
+ throw new Error('The attached event handler is not defined.');
+ }
+ var elements = $$(selecter);
+ this._attachHandlers[selecter] = elements;
+ elements.addEvent(this.attachEvent, this.attachHandler);
+ },
+
+ dettach: function(selecter){
+ if (!this._attachHandlers[selecter]){
+ throw new Error('There is no attached event handler corresponding to the selector.');
+ }
+ var elements = this._attachHandlers[selecter];
+ elements.removeEvent(this.attachEvent, this.attachHandler);
+ }
+
+});
+
+}($$));
+
View
@@ -3,19 +3,25 @@
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
- <title></title>
+ <title>Mixin</title>
<meta name="description" content="" />
- <meta name="author" content="operator" />
<script type="text/javascript" src="js/lib/mootools-core-1.3.2.js"></script>
+ <script type="text/javascript" src="js/mixin.js"></script>
<script type="text/javascript" src="js/mock.js"></script>
<script type="text/javascript" src="js/runner.js"></script>
</head>
<body>
<article class="page">
<header>
- <h1></h1>
+ <h1>Mixin</h1>
</header>
<article class="main">
+ <h2>Class.Attachment</h2>
+ <ul id="attachEvents">
+ <li><a href="#foo">click by #foo</a></li>
+ <li><a href="#bar">click by #bar</a></li>
+ </ul>
+ <p><a id="attach" title="attach" href="#">attach</a> <a id="dettach" title="dettach" href="#">dettach</a></p>
</article>
<footer>
<p>&copy; Copyright 2011 Noritaka Horio All rights reserved.</p>
View
@@ -0,0 +1,51 @@
+/*
+---
+name: Attachment
+
+description: The function to be attached to the class of the event in each selector is built in.
+
+license: MIT-style
+
+authors:
+- Noritaka Horio
+
+requires:
+ - Core/Type
+ - Core/Function
+ - Core/$$
+ - Core/Element
+ - Core/Elements
+ - Core/Element.Event
+ - Core/Class
+
+provides: [Attachment]
+
+...
+*/
+
+(function($$){
+
+var Attachment = this.Attachment = new Class({
+
+ _attachHandlers: {},
+
+ attach: function(selecter){
+ if (!Type.isFunction(this.attachHandler)){
+ throw new Error('The attached event handler is not defined.');
+ }
+ var elements = $$(selecter);
+ this._attachHandlers[selecter] = elements;
+ elements.addEvent(this.attachEvent, this.attachHandler);
+ },
+
+ dettach: function(selecter){
+ if (!this._attachHandlers[selecter]){
+ throw new Error('There is no attached event handler corresponding to the selector.');
+ }
+ var elements = this._attachHandlers[selecter];
+ elements.removeEvent(this.attachEvent, this.attachHandler);
+ }
+
+});
+
+}($$));
View
@@ -1,17 +1,13 @@
(function(){
-var Mock = new Class({
+var AttachMock = this.AttachMock = new Class({
- Implemenets: [Attachment],
+ Implements: [Attachment],
attachEvent: 'click',
- attachHandler: this.trrigerHandler,
-
- initiazlize: function(){
- },
-
- trrigerHandler: function(event){
-alert('aaa');
+ attachHandler: function(event){
+ event.preventDefault();
+ alert('attached');
}
});
View
@@ -1,4 +1,19 @@
(function($){
+ var mock = new AttachMock();
+
+ window.addEvent('domready', function(){
+
+ $('attach').addEvent('click', function(event){
+ event.preventDefault();
+ mock.attach('#attachEvents a');
+ });
+
+ $('dettach').addEvent('click', function(event){
+ event.preventDefault();
+ mock.dettach('#attachEvents a');
+ });
+
+ });
}(document.id));
View
@@ -1,25 +1,47 @@
Mixin
===========================================
+It builds in the class and crowding and a variety of Mixin classes are offered.
+It is possible to use it only by building it in the class.
+![Mixin](http://holyshared.github.com/Mixin/logo.png "Mixin")
+How to use
+-------------------------------------------
+### Class.Attachment
-![Mixin](http://holyshared.github.com/class-attachment/logo.png "Mixin")
+#### Definition of class
-How to use
------------------------------------------
+The Attachment class is built in with Implements.
+And, attachEvent and attachHandler are defined.
+ var Mock = new Class({
+ Implements: [Attachment],
+ //Generated event type.
+ attachEvent: 'click',
+ //Attached event.
+ attachHandler: function(event){
+ //do something
+ }
+ });
+#### Attachment to event
+The event is attached to the corresponding element by the use of the attach method.
+The dettach method is used to release the event.
+ var mock = Mock();
+ mock.attach('ul li a');
+ mock.attach(dettach);
+Option of build
+-------------------------------------------
-Screenshots
-------------------------------------------------------------------------
+Mixin/* +use-only Mixin
View
@@ -2,17 +2,20 @@
---
name: Attachment
-description:
+description: The function to be attached to the class of the event in each selector is built in.
license: MIT-style
authors:
- Noritaka Horio
requires:
+ - Core/Type
+ - Core/Function
- Core/$$
- Core/Element
- Core/Elements
+ - Core/Element.Event
- Core/Class
provides: [Attachment]
@@ -28,7 +31,7 @@ var Attachment = this.Attachment = new Class({
attach: function(selecter){
if (!Type.isFunction(this.attachHandler)){
-
+ throw new Error('The attached event handler is not defined.');
}
var elements = $$(selecter);
this._attachHandlers[selecter] = elements;
@@ -37,9 +40,9 @@ var Attachment = this.Attachment = new Class({
dettach: function(selecter){
if (!this._attachHandlers[selecter]){
-
+ throw new Error('There is no attached event handler corresponding to the selector.');
}
- var handler = this._attachHandlers[selecter];
+ var elements = this._attachHandlers[selecter];
elements.removeEvent(this.attachEvent, this.attachHandler);
}
@@ -1,17 +0,0 @@
-<script type="text/javascript" src="/depender/build?require=Mixin/Attachment"></script>
-<script type="text/javascript">
-(function(){
-
- window.addEventListener('load', function(){
-
-
-
-
-
-
-
-
- }, false);
-
-}());
-</script>
@@ -0,0 +1,28 @@
+<script type="text/javascript" src="/depender/build?require=Mixin/Attachment"></script>
+<script type="text/javascript">
+(function(){
+
+ var Mock = new Class({
+
+ Implements: [Attachment],
+
+ attachEvent: 'click',
+ attachHandler: function(event){
+ alert(this.get('href'));
+ }
+
+ });
+
+ window.addEventListener('load', function(){
+
+ var mock = new Mock();
+ mock.attach('#attachEvent a');
+
+ }, false);
+
+}());
+</script>
+<ul id="attachEvent">
+ <li><a href="#foo">foo</a></li>
+ <li><a href="#bar">bar</a></li>
+</ul>
View
@@ -1,8 +1,8 @@
-name: Class
+name: Mixin
web: "[http://sharedhat.com](http://sharedhat.com)"
-description: ""
+description: "It builds in the class and crowding and a variety of Mixin classes are offered."
authors: "[Noritaka Horio](http://sharedhat.com)"
@@ -21,6 +21,6 @@ tags: [utils, mixin, class]
current: 1.0
-docs: http://holyshared.github.com/class-attachment/docs
+#docs: http://holyshared.github.com/Mixin/docs
-demo: http://holyshared.github.com/class-attachment/
+demo: http://holyshared.github.com/Mixin/

0 comments on commit 20e5663

Please sign in to comment.