Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
rename
  • Loading branch information
yyx990803 committed Jul 28, 2013
1 parent 83fac01 commit 871ed91
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Gruntfile.js
Expand Up @@ -5,7 +5,7 @@ module.exports = function( grunt ) {
component_build: {
build: {
output: './dist/',
name: 'element',
name: 'seed',
styles: false,
scripts: true,
verbose: true
Expand Down
2 changes: 1 addition & 1 deletion component.json
@@ -1,5 +1,5 @@
{
"name": "element",
"name": "seed",
"version": "0.0.1",
"dependencies": {
"component/emitter": "*"
Expand Down
66 changes: 66 additions & 0 deletions explorations/getset-revits-style.html
@@ -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>
66 changes: 66 additions & 0 deletions explorations/getset.html
@@ -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>
2 changes: 1 addition & 1 deletion package.json
@@ -1,5 +1,5 @@
{
"name": "element",
"name": "seed",
"version": "0.0.1",
"devDependencies": {
"grunt": "~0.4.1",
Expand Down
2 changes: 1 addition & 1 deletion test/test.html
Expand Up @@ -13,7 +13,7 @@
mocha.setup('bdd')
var assert = chai.assert
</script>
<script src="../dist/element.js"></script>
<script src="../dist/seed.js"></script>
<script src="test.js"></script>
<script>
if (navigator.userAgent.indexOf('PhantomJS') < 0) {
Expand Down
6 changes: 3 additions & 3 deletions test/test.js
@@ -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)
})
})

19 comments on commit 871ed91

@devyash
Copy link

@devyash devyash commented on 871ed91 Apr 25, 2017

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.

@yuzai
Copy link

@yuzai yuzai commented on 871ed91 May 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are not alone

@yanlee26
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool vue !

@babeliao
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome

@chengkj99
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool

@qinouz
Copy link

@qinouz qinouz commented on 871ed91 Aug 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

马克

@nancy09
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mark

@zpbc007
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

come to learn

@acfasj
Copy link

@acfasj acfasj commented on 871ed91 Sep 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool

@bingo-keith
Copy link

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

@udbbbn
Copy link

@udbbbn udbbbn commented on 871ed91 Apr 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mark

@zhouzhonghao
Copy link

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.

@gabeta
Copy link

@gabeta gabeta commented on 871ed91 Jun 19, 2020

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

@xlz122
Copy link

@xlz122 xlz122 commented on 871ed91 Mar 16, 2022

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.

@aaroncrockett
Copy link

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.

@shailstar
Copy link

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

@WangNingning1994
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2023

@moHaHa
Copy link

@moHaHa moHaHa commented on 871ed91 Feb 25, 2023

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."

@zhaoyi-1995
Copy link

@zhaoyi-1995 zhaoyi-1995 commented on 871ed91 Feb 25, 2023 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.