Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
7 changed files
with
139 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| { | ||
| "name": "element", | ||
| "name": "seed", | ||
| "version": "0.0.1", | ||
| "dependencies": { | ||
| "component/emitter": "*" | ||
|
|
||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <title>ideal</title> | ||
| <meta charset="utf-8"> | ||
| </head> | ||
| <body> | ||
| <div id="test"> | ||
| <p>{{msg}}</p> | ||
| <p>{{msg}}</p> | ||
| <p>{{msg}}</p> | ||
| <p>{{what}}</p> | ||
| <p>{{hey}}</p> | ||
| </div> | ||
| <script> | ||
| var bindingMark = 'data-element-binding' | ||
| function Element (id, initData) { | ||
|
|
||
| var self = this, | ||
| el = self.el = document.getElementById(id) | ||
| bindings = {} // the internal copy | ||
| data = self.data = {} // the external interface | ||
| content = el.innerHTML.replace(/\{\{(.*)\}\}/g, markToken) | ||
|
|
||
| el.innerHTML = content | ||
|
|
||
| for (var variable in bindings) { | ||
| bind(variable) | ||
| } | ||
|
|
||
| if (initData) { | ||
| for (var variable in initData) { | ||
| data[variable] = initData[variable] | ||
| } | ||
| } | ||
|
|
||
| function markToken (match, variable) { | ||
| bindings[variable] = {} | ||
| return '<span ' + bindingMark + '="' + variable +'"></span>' | ||
| } | ||
|
|
||
| function bind (variable) { | ||
| bindings[variable].els = el.querySelectorAll('[' + bindingMark + '="' + variable + '"]') | ||
| ;[].forEach.call(bindings[variable].els, function (e) { | ||
| e.removeAttribute(bindingMark) | ||
| }) | ||
| Object.defineProperty(data, variable, { | ||
| set: function (newVal) { | ||
| [].forEach.call(bindings[variable].els, function (e) { | ||
| bindings[variable].value = e.textContent = newVal | ||
| }) | ||
| }, | ||
| get: function () { | ||
| return bindings[variable].value | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| var app = new Element('test', { | ||
| msg: 'hello' | ||
| }) | ||
|
|
||
| </script> | ||
| </body> | ||
| </html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <title>ideal</title> | ||
| <meta charset="utf-8"> | ||
| </head> | ||
| <body> | ||
| <div id="test"> | ||
| <p>{{msg}}</p> | ||
| <p>{{msg}}</p> | ||
| <p>{{msg}}</p> | ||
| <p>{{what}}</p> | ||
| <p>{{hey}}</p> | ||
| </div> | ||
| <script> | ||
| var bindingMark = 'data-element-binding' | ||
| function Element (id, initData) { | ||
|
|
||
| var self = this, | ||
| el = self.el = document.getElementById(id) | ||
| bindings = {} // the internal copy | ||
| data = self.data = {} // the external interface | ||
| content = el.innerHTML.replace(/\{\{(.*)\}\}/g, markToken) | ||
|
|
||
| el.innerHTML = content | ||
|
|
||
| for (var variable in bindings) { | ||
| bind(variable) | ||
| } | ||
|
|
||
| if (initData) { | ||
| for (var variable in initData) { | ||
| data[variable] = initData[variable] | ||
| } | ||
| } | ||
|
|
||
| function markToken (match, variable) { | ||
| bindings[variable] = {} | ||
| return '<span ' + bindingMark + '="' + variable +'"></span>' | ||
| } | ||
|
|
||
| function bind (variable) { | ||
| bindings[variable].els = el.querySelectorAll('[' + bindingMark + '="' + variable + '"]') | ||
| ;[].forEach.call(bindings[variable].els, function (e) { | ||
| e.removeAttribute(bindingMark) | ||
| }) | ||
| Object.defineProperty(data, variable, { | ||
| set: function (newVal) { | ||
| [].forEach.call(bindings[variable].els, function (e) { | ||
| bindings[variable].value = e.textContent = newVal | ||
| }) | ||
| }, | ||
| get: function () { | ||
| return bindings[variable].value | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| var app = new Element('test', { | ||
| msg: 'hello' | ||
| }) | ||
|
|
||
| </script> | ||
| </body> | ||
| </html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| { | ||
| "name": "element", | ||
| "name": "seed", | ||
| "version": "0.0.1", | ||
| "devDependencies": { | ||
| "grunt": "~0.4.1", | ||
|
|
||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| var Element = require('element') | ||
| var Seed = require('seed') | ||
|
|
||
| describe('Element', function () { | ||
| describe('Seed', function () { | ||
| it('should have a variable', function () { | ||
| assert.equal(Element, 123) | ||
| assert.equal(Seed, 123) | ||
| }) | ||
| }) |
871ed91There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The place where it all began. Is it just me or is anyone else trying to understand how it works ? Its cool the way he replaced the moustache msg with Hello and the other moustache are getting removed completely.
871ed91There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you are not alone
871ed91There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool vue !
871ed91There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
awesome
871ed91There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool
871ed91There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
马克
871ed91There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mark
871ed91There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
come to learn
871ed91There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool
871ed91There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just learned vue, and then left my footsteps
871ed91There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mark
871ed91There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My Conquest Is the Sea of Stars.
871ed91There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Impressive I had to take a trip to the source.
2020
871ed91There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The place where it all began.
871ed91There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fun times looking at this.
871ed91There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Come to see, how it all started
871ed91There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2023
871ed91There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't got it !
what does it mean "The place where it all began."
871ed91There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.