Skip to content
Open

AMD #54

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions attr.built.no-oldie.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@

define('lib/attr.getters',['require','exports','module'],function(require, get){

get['class'] = function(){
return this.getAttribute('class') || this.className
}

get['for'] = function(){
return ('htmlFor' in this) ? this.htmlFor : this.getAttribute('for')
}

get.href = function(){
return ('href' in this) ? this.getAttribute('href', 2) : this.getAttribute('href')
}

get.style = function(){
return (this.style) ? this.style.cssText : this.getAttribute('style')
}

get.type = function(){
return this.getAttribute('type')
}

get.tabindex = function(){
var attributeNode = this.getAttributeNode('tabindex')
return (attributeNode && attributeNode.specified) ? attributeNode.nodeValue : null
}

get.maxlength =
get.maxLength = function(){
var attributeNode = this.getAttributeNode('maxLength')
return (attributeNode && attributeNode.specified) ? attributeNode.nodeValue : null
}

})

define('lib/attr',['require','exports','module','./attr.has','./attr.getters'],function(require, attr){

var has = require('./attr.has')

var getters = require('./attr.getters') || {}

attr.define = function(name, fn){
getters[name] = fn
return this
}

attr.lookup = function(name){
return getters[name]
}

true
?
attr.has = function(node, attribute){
return node.hasAttribute(attribute)
}
:
attr.has = function(node, attribute){
// IE6-7 (at least) doesn't implement hasAttribute
node = node.getAttributeNode(attribute)
return !!(node && (node.specified || node.nodeValue))
}

true
?
attr.get = function(node, attribute){
var getter = getters[attribute]
if (getter) return getter.call(node, attribute)
return node.getAttribute(name)
}
:
attr.get = function(node, attribute){
// in IE6-7, if a form has an input of id x, form.getAttribute(x) returns a reference to the input
var getter = this.getters[attribute]
if (getter) return getter.call(node, attribute)
var attributeNode = node.getAttributeNode(attribute)
return attributeNode ? attributeNode.nodeValue : null
}
})
34 changes: 34 additions & 0 deletions build/attr.build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// more info: https://github.com/jrburke/r.js/blob/master/build/example.build.js

module.exports = {
baseUrl: '../'
,
name: 'lib/attr'
,
out: '../attr.built.no-oldie.js'
,
paths:{
'lib/attr.has': 'empty:'
}
,
has:{
'has': false,
'dom.hasAttribute': true,
'dom.getAttribute': true
}
,
optimize:'none'
// ,
// pragmas:{// true = yes, remove
// 'has':true,
// 'oldie':true
// }
,
wrap:true
// ,
// uglify:{
// beautify:true
// }
}

if (module.id == '.') require('requirejs').optimize(module.exports, console.log)
16 changes: 16 additions & 0 deletions build/slick.build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env node
var requirejs = require('requirejs')

var configs = [
require('./attr.build')
]

configs.forEach(function(config){
requirejs.optimize(config, function (buildResponse) {
//buildResponse is just a text output of the modules
//included. Load the built file for the contents.
//Use config.out to get the optimized file contents.
// var contents = fs.readFileSync(config.out, 'utf8')
console.log(buildResponse)
})
})
24 changes: 24 additions & 0 deletions example/example.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv=Content-type content="text/html; charset=utf-8">
<title>example</title>
</head>
<body>
<script src="../node_modules/requirejs/require.js"></script>

<script>
require.config({
baseUrl: './'
});
// if (!(/debug/i).test(location.search)) {
// require.config({paths:{'../lib/attr':'../build/attr.built'}});
// }
</script>
<!--[if lte IE 7]><script>require.config({paths:{'../lib/attr':'../build/attr.built.oldie'}})</script><![endif]-->

<script>
require(['../lib/attr']);
</script>
</body>
</html>
34 changes: 34 additions & 0 deletions lib/attr.getters.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
define(function(require, get){

get['class'] = function(){
return this.getAttribute('class') || this.className
}

get['for'] = function(){
return ('htmlFor' in this) ? this.htmlFor : this.getAttribute('for')
}

get.href = function(){
return ('href' in this) ? this.getAttribute('href', 2) : this.getAttribute('href')
}

get.style = function(){
return (this.style) ? this.style.cssText : this.getAttribute('style')
}

get.type = function(){
return this.getAttribute('type')
}

get.tabindex = function(){
var attributeNode = this.getAttributeNode('tabindex')
return (attributeNode && attributeNode.specified) ? attributeNode.nodeValue : null
}

get.maxlength =
get.maxLength = function(){
var attributeNode = this.getAttributeNode('maxLength')
return (attributeNode && attributeNode.specified) ? attributeNode.nodeValue : null
}

})
14 changes: 14 additions & 0 deletions lib/attr.has.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
define(function(require, exports){
var has = exports = require('has')

has.add('dom.getAttribute', function(global, document, testEl){
return has.isHostType(testEl, 'hasAttribute')
})

has.add('dom.hasAttribute', function(global, document, testEl){
// FIXME: add hasAttribute feature test
return true
})

return has
})
45 changes: 45 additions & 0 deletions lib/attr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
define(function(require, attr){

//>>excludeStart("has", pragmas.has);
var has = require('./attr.has')
//>>excludeEnd("has");

var getters = require('./attr.getters') || {}

attr.define = function(name, fn){
getters[name] = fn
return this
}

attr.lookup = function(name){
return getters[name]
}

has('dom.hasAttribute')
?
attr.has = function(node, attribute){
return node.hasAttribute(attribute)
}
:
attr.has = function(node, attribute){
// IE6-7 (at least) doesn't implement hasAttribute
node = node.getAttributeNode(attribute)
return !!(node && (node.specified || node.nodeValue))
}

has('dom.getAttribute')
?
attr.get = function(node, attribute){
var getter = getters[attribute]
if (getter) return getter.call(node, attribute)
return node.getAttribute(name)
}
:
attr.get = function(node, attribute){
// in IE6-7, if a form has an input of id x, form.getAttribute(x) returns a reference to the input
var getter = this.getters[attribute]
if (getter) return getter.call(node, attribute)
var attributeNode = node.getAttributeNode(attribute)
return attributeNode ? attributeNode.nodeValue : null
}
})