Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/charsleysa/zepto into cha…
Browse files Browse the repository at this point in the history
…rsleysa-master
  • Loading branch information
madrobby committed Sep 13, 2013
2 parents 015ee4a + aaf6b31 commit 7414407
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 2 deletions.
2 changes: 1 addition & 1 deletion make
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ target.dist = ->
target.build = ->
cd __dirname
mkdir '-p', 'dist'
modules = (env['MODULES'] || 'polyfill zepto detect event ajax form fx').split(' ')
modules = (env['MODULES'] || 'ie polyfill zepto detect event ajax form fx').split(' ')
module_files = ( "src/#{module}.js" for module in modules )
intro = "/* Zepto #{describe_version()} - #{modules.join(' ')} - zeptojs.com/license */\n"
dist = intro + cat(module_files).replace(/^\/[\/*].*$/mg, '').replace(/\n{3,}/g, "\n\n")
Expand Down
2 changes: 2 additions & 0 deletions src/detect.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
playbook = ua.match(/PlayBook/),
chrome = ua.match(/Chrome\/([\d.]+)/) || ua.match(/CriOS\/([\d.]+)/),
firefox = ua.match(/Firefox\/([\d.]+)/),
ie = ua.match(/MSIE ([\d.]+)/),
safari = webkit && ua.match(/Mobile\//) && !chrome,
webview = ua.match(/(iPhone|iPod|iPad).*AppleWebKit(?!.*Safari)/) && !chrome

Expand All @@ -46,6 +47,7 @@
if (!silk && os.android && ua.match(/Kindle Fire/)) browser.silk = true
if (chrome) browser.chrome = true, browser.version = chrome[1]
if (firefox) browser.firefox = true, browser.version = firefox[1]
if (ie) browser.ie = true, browser.version = ie[1]
if (safari && (ua.match(/Safari/) || !!os.ios)) browser.safari = true
if (webview) browser.webview = true

Expand Down
20 changes: 20 additions & 0 deletions src/ie.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// IE Support
// This module provides a IE Support to all __proto__ dependant libraries by adding the __proto__ property to objects.
;(function(undefined){
if (!('__proto__' in {})) {
Object.defineProperty(Object.prototype, '__proto__', {
set: function (x) {
for (var prop in x) {
// Stops stack overflow errors
if (prop == '__proto__') continue;
this[prop] = x[prop];
}
},
get: function () {
return this;
},
enumerable: false,
configurable: true
});
}
})()
8 changes: 8 additions & 0 deletions test/detect.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ <h1>Browser detection</h1>
Firefox_6_0_2: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:6.0.2) Gecko/20100101 Firefox/6.0.2",
Firefox_Mobile_Simulator: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:2.1.1) Gecko/ Firefox/4.0.2pre Fennec/4.0.1",

Windows_IE: "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)",
Windows_RT_Surface: "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; ARM; Trident/6.0; Touch)",
Windows_Phone_8: "Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; ARM; Touch; HTC; Windows Phone 8X by HTC)"
}
Expand Down Expand Up @@ -365,6 +366,13 @@ <h1>Browser detection</h1>
t.assertFalse(os.tablet)
t.assertTrue(browser.chrome)
})
},

testIE: function(t) {
detect(UA.Windows_IE, function(os, browser){
t.assertTrue(browser.ie)
t.assertEqual("10.0", browser.version)
})
}
})
})()
Expand Down
63 changes: 63 additions & 0 deletions test/ie.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<link rel="stylesheet" href="test.css">
<title>__proto__ requirement checking</title>
<script src="../vendor/evidence.js"></script>
<script src="evidence_runner.js"></script>
<script src="../src/ie.js"></script>
</head>
<body>
<h1>__proto__ requirement</h1>
<p id="results">
Running… see browser console for results
</p>

<script>
(function () {
Evidence('ZeptoDetectTest', {
testProtoExistance: function (t) {
var testObj = {}
t.assertFalse(testObj.__proto__ === undefined)
},

testProtoAssignment: function (t) {
var myProto = {
myFunc: function () {
return "hello "
},
myProperty: "world"
}

var testObj = {}
t.assertTrue(testObj.myFunc === undefined)
t.assertTrue(testObj.myProperty === undefined)

testObj.__proto__ = myProto

var testVar = testObj.myFunc()
t.assertEqual("hello ", testVar)

testVar += testObj.myProperty
t.assertEqual("hello world", testVar)
},

testProtoNesting: function (t) {
var myProto1 = { property1: "hello" }
var myProto2 = { property2: "world" }
var testObj = {}

myProto2.__proto__ = myProto1
t.assertEqual("hello", myProto2.property1)

testObj.__proto__ = myProto2
t.assertEqual("hello", testObj.property1)
t.assertEqual("world", testObj.property2)
}
})
})()
</script>
</body>
</html>
2 changes: 1 addition & 1 deletion test/runner.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ if args.length > 0
suites = args
else
# by default, run all test/*.html pages
modules = 'zepto ajax data detect event form fx selector stack'.split /\s+/
modules = 'ie zepto ajax data detect event form fx selector stack'.split /\s+/
suites = modules.map (name)-> "test/#{name}.html"

page = require('webpage').create()
Expand Down

0 comments on commit 7414407

Please sign in to comment.