3.0 source code

This commit is contained in:
agolybev
2015-04-28 17:59:00 +03:00
parent c69fd34bdd
commit 7b3b2248e5
16311 changed files with 1445974 additions and 3108429 deletions

View File

@@ -0,0 +1,30 @@
{
"name": "jquery.browser",
"version": "0.0.6",
"homepage": "https://github.com/gabceb/jquery-browser-plugin",
"authors": [
"Gabriel Cebrian <gabceb@gmail.com>",
"jQuery Team <https://github.com/gabceb/jquery-browser-plugin/wiki/Authors>"
],
"description": "A jQuery plugin for browser detection.",
"main": "dist/jquery.browser.js",
"keywords": [
"browser",
"jquery",
"desktop",
"detect"
],
"license": "MIT",
"dependencies": {
"jquery": ">=1.5"
},
"_release": "0.0.6",
"_resolution": {
"type": "version",
"tag": "v0.0.6",
"commit": "b9df646efeb8570cdd0ac71d8d68f3fb86668105"
},
"_source": "git://github.com/gabceb/jquery-browser-plugin.git",
"_target": "0.0.6",
"_originalSource": "jquery.browser"
}

View File

@@ -0,0 +1,17 @@
lib-cov
*.seed
*.log
*.csv
*.dat
*.out
*.pid
*.gz
pids
logs
results
npm-debug.log
node_modules
.DS_STORE

View File

@@ -0,0 +1,47 @@
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
jshint: {
files: ['gruntfile.js', 'jquery.browser.js'],
options: {
globals: {
jQuery: true,
console: true,
module: true
}
}
},
uglify: {
options: {
banner: '/*!\n * jQuery Browser Plugin <%= pkg.version %>\n * https://github.com/gabceb/jquery-browser-plugin\n *\n * Original jquery-browser code Copyright 2005, 2013 jQuery Foundation, Inc. and other contributors\n * http://jquery.org/license\n *\n * Modifications Copyright <%= grunt.template.today("yyyy") %> Gabriel Cebrian\n * https://github.com/gabceb\n *\n * Released under the MIT license\n *\n * Date: <%= grunt.template.today("dd-mm-yyyy")%>\n */'
},
dist: {
files: {
'dist/<%= pkg.name %>.min.js': 'dist/<%= pkg.name %>.js'
}
}
},
copy: {
main:{
src: "dist/<%= pkg.name %>.js",
dest: "test/src/<%= pkg.name %>.js"
}
},
exec: {
test: {
command: "casperjs test test/test.js",
stdout: true,
stderr: true
}
}
});
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-exec');
grunt.registerTask('default', ['jshint', 'uglify', 'copy']);
grunt.registerTask('test', ['exec']);
};

View File

@@ -0,0 +1,21 @@
Copyright 2013 jQuery Foundation and other contributors, http://jquery.com/
Modifications Copyright 2013 Gabriel Cebrian, https://www.github.com/gabceb
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@@ -0,0 +1,80 @@
A jQuery plugin for browser detection. jQuery removed support for browser detection on 1.9.1 so it was abstracted into a jQuery plugin
## Installation
Include script *after* the jQuery library:
<script src="/path/to/jquery.browser.js"></script>
## Usage
Returns true if the current useragent is some version of Microsoft's Internet Explorer. Supports all IE versions including IE11
$.browser.msie;
Returns true if the current useragent is some version of a Webkit browser (Safari, Chrome and Opera 15+).
$.browser.webkit;
Returns true if the current useragent is some version of Firefox.
$.browser.mozilla;
Reading the browser verion
$.browser.version
## Things not included in the original jQuery $.browser implementation
- Detect Windows, Mac, Linux, iPad, iPhone, Android and Windows Phone useragents
```javascript
$.browser.ipad
$.browser.iphone
$.browser["windows phone"]
$.browser.android
$.browser.win
$.browser.mac
$.browser.linux
```
- Detect the browser's major version
```javascript
// User Agent for Chrome
// Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1664.3 Safari/537.36
$.browser.versionNumber // Returns 32 as a number
```
- Support for new useragent on IE11
- Support for webkit based Opera browsers
- Added testing using PhantomJS and different browser user agents
## Testing
Testing for this plugin is done with [Casperjs v1.1](http://casperjs.org/) to take advantage of multiple phantomjs browsers with different user agents.
For instructions on how to install [Casperjs v1.1](http://casperjs.org/) go to http://docs.casperjs.org/en/latest/installation.html
**Note: Testing requires Casperjs v1.1**
Install the grunt-cli dependency by running `npm install -g grunt-cli`
Run `npm install` to install all dependencies including grunt and all tasks
Once Casperjs and the grunt-cli npm package is installed you can execute all the tests by using:
grunt test
## Development
- Source hosted at [GitHub](https://github.com/gabceb/jquery-browser-plugin)
- Report issues, questions, feature requests on [GitHub Issues](https://github.com/gabceb/jquery-browser-plugin/issues)
## Attributions
- [Examples and original implementation](http://api.jquery.com/jQuery.browser/)
- [Original Gist used for the plugin](https://gist.github.com/adeelejaz/4714079)
[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/gabceb/jquery-browser-plugin/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

View File

@@ -0,0 +1,13 @@
{
"name": "jquery.browser",
"version": "0.0.6",
"homepage": "https://github.com/gabceb/jquery-browser-plugin",
"authors": ["Gabriel Cebrian <gabceb@gmail.com>", "jQuery Team <https://github.com/gabceb/jquery-browser-plugin/wiki/Authors>"],
"description": "A jQuery plugin for browser detection.",
"main": "dist/jquery.browser.js",
"keywords": ["browser", "jquery", "desktop", "detect"],
"license": "MIT",
"dependencies": {
"jquery": ">=1.5"
}
}

View File

@@ -0,0 +1,37 @@
{
"name": "browser",
"title": "jQuery Browser",
"description": "A jQuery plugin for browser detection.",
"keywords": [
"browser",
"detection",
"mobile",
"html5",
"support"
],
"version": "0.0.5",
"author": {
"name": "Gabriel Cebrian. Initial implementation by the jQuery Team",
"url": "https://github.com/gabceb/jquery-browser-plugin/wiki/Authors"
},
"maintainers": [
{
"name": "Gabriel Cebrian",
"email": "gabceb@gmail.com",
"url": "http://about.me/gabceb"
}
],
"licenses": [
{
"type": "MIT",
"url": "http://opensource.org/licenses/MIT"
}
],
"bugs": "https://github.com/gabceb/jquery-browser-plugin/issues",
"homepage": "https://github.com/gabceb/jquery-browser-plugin",
"docs": "https://github.com/gabceb/jquery-browser-plugin",
"download": "https://github.com/gabceb/jquery-browser-plugin",
"dependencies": {
"jquery": ">=1.5"
}
}

View File

@@ -0,0 +1,102 @@
/*!
* jQuery Browser Plugin v0.0.5
* https://github.com/gabceb/jquery-browser-plugin
*
* Original jquery-browser code Copyright 2005, 2013 jQuery Foundation, Inc. and other contributors
* http://jquery.org/license
*
* Modifications Copyright 2013 Gabriel Cebrian
* https://github.com/gabceb
*
* Released under the MIT license
*
* Date: 2013-07-29T17:23:27-07:00
*/
(function( jQuery, window, undefined ) {
"use strict";
var matched, browser;
jQuery.uaMatch = function( ua ) {
ua = ua.toLowerCase();
var match = /(opr)[\/]([\w.]+)/.exec( ua ) ||
/(chrome)[ \/]([\w.]+)/.exec( ua ) ||
/(version)[ \/]([\w.]+).*(safari)[ \/]([\w.]+)/.exec(ua) ||
/(webkit)[ \/]([\w.]+)/.exec( ua ) ||
/(opera)(?:.*version|)[ \/]([\w.]+)/.exec( ua ) ||
/(msie) ([\w.]+)/.exec( ua ) ||
ua.indexOf("trident") >= 0 && /(rv)(?::| )([\w.]+)/.exec( ua ) ||
ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec( ua ) ||
[];
var platform_match = /(ipad)/.exec( ua ) ||
/(iphone)/.exec( ua ) ||
/(android)/.exec( ua ) ||
/(windows phone)/.exec(ua) ||
/(win)/.exec( ua ) ||
/(mac)/.exec( ua ) ||
/(linux)/.exec( ua ) ||
[];
return {
browser: match[ 3 ] || match[ 1 ] || "",
version: match[ 2 ] || "0",
platform: platform_match[0] || ""
};
};
matched = jQuery.uaMatch( window.navigator.userAgent );
browser = {};
if ( matched.browser ) {
browser[ matched.browser ] = true;
browser.version = matched.version;
browser.versionNumber = parseInt(matched.version);
}
if ( matched.platform ) {
browser[ matched.platform ] = true;
}
// Chrome, Opera 15+ and Safari are webkit based browsers
if ( browser.chrome || browser.opr || browser.safari ) {
browser.webkit = true;
}
// IE11 has a new token so we will assign it msie to avoid breaking changes
if ( browser.rv )
{
var ie = 'msie';
matched.browser = ie;
browser[ie] = true;
}
// Opera 15+ are identified as opr
if ( browser.opr )
{
var opera = 'opera';
matched.browser = opera;
browser[opera] = true;
}
// Stock Android browsers are marked as safari on Android.
if ( browser.safari && browser.android )
{
var android = 'android';
matched.browser = android;
browser[android] = true;
}
// Assign the name and platform variable
browser.name = matched.browser;
browser.platform = matched.platform;
jQuery.browser = browser;
})( jQuery, window );

View File

@@ -0,0 +1,70 @@
#!
# jQuery Browser Plugin v0.0.5
# https://github.com/gabceb/jquery-browser-plugin
#
# Original jquery-browser code Copyright 2005, 2013 jQuery Foundation, Inc. and other contributors
# http://jquery.org/license
#
# Modifications Copyright 2013 Gabriel Cebrian
# https://github.com/gabceb
#
# Released under the MIT license
#
# Date: 2013-07-29T17:23:27-07:00
#
((jQuery, window, undefined_) ->
"use strict"
matched = undefined
browser = undefined
jQuery.uaMatch = (ua) ->
ua = ua.toLowerCase()
match = /(opr)[\/]([\w.]+)/.exec(ua) or /(chrome)[ \/]([\w.]+)/.exec(ua) or /(version)[ \/]([\w.]+).*(safari)[ \/]([\w.]+)/.exec(ua) or /(webkit)[ \/]([\w.]+)/.exec(ua) or /(opera)(?:.*version|)[ \/]([\w.]+)/.exec(ua) or /(msie) ([\w.]+)/.exec(ua) or ua.indexOf("trident") >= 0 and /(rv)(?::| )([\w.]+)/.exec(ua) or ua.indexOf("compatible") < 0 and /(mozilla)(?:.*? rv:([\w.]+)|)/.exec(ua) or []
platform_match = /(ipad)/.exec(ua) or /(iphone)/.exec(ua) or /(android)/.exec(ua) or /(windows phone)/.exec(ua) or /(win)/.exec(ua) or /(mac)/.exec(ua) or /(linux)/.exec(ua) or []
browser: match[3] or match[1] or ""
version: match[2] or "0"
platform: platform_match[0] or ""
matched = jQuery.uaMatch(window.navigator.userAgent)
browser = {}
if matched.browser
browser[matched.browser] = true
browser.version = matched.version
browser.versionNumber = parseInt(matched.version)
if matched.platform
browser[matched.platform] = true
# Chrome, Opera 15+ and Safari are webkit based browsers
if browser.chrome or browser.opr or browser.safari
browser.webkit = true
# IE11 has a new token so we will assign it msie to avoid breaking changes
if browser.rv
ie = "msie"
matched.browser = ie
browser[ie] = true
# Opera 15+ are identified as opr
if browser.opr
opera = "opera"
matched.browser = opera
browser[opera] = true
# Stock Android browsers are marked as safari on Android.
if browser.safari && browser.android
var android = 'android'
matched.browser = android
browser[android] = true
# Assign the name and platform variable
browser.name = matched.browser
browser.platform = matched.platform
jQuery.browser = browser
) jQuery, window

View File

@@ -0,0 +1,14 @@
/*!
* jQuery Browser Plugin 0.0.5
* https://github.com/gabceb/jquery-browser-plugin
*
* Original jquery-browser code Copyright 2005, 2013 jQuery Foundation, Inc. and other contributors
* http://jquery.org/license
*
* Modifications Copyright 2014 Gabriel Cebrian
* https://github.com/gabceb
*
* Released under the MIT license
*
* Date: 05-01-2014
*/!function(a,b){"use strict";var c,d;if(a.uaMatch=function(a){a=a.toLowerCase();var b=/(opr)[\/]([\w.]+)/.exec(a)||/(chrome)[ \/]([\w.]+)/.exec(a)||/(version)[ \/]([\w.]+).*(safari)[ \/]([\w.]+)/.exec(a)||/(webkit)[ \/]([\w.]+)/.exec(a)||/(opera)(?:.*version|)[ \/]([\w.]+)/.exec(a)||/(msie) ([\w.]+)/.exec(a)||a.indexOf("trident")>=0&&/(rv)(?::| )([\w.]+)/.exec(a)||a.indexOf("compatible")<0&&/(mozilla)(?:.*? rv:([\w.]+)|)/.exec(a)||[],c=/(ipad)/.exec(a)||/(iphone)/.exec(a)||/(android)/.exec(a)||/(windows phone)/.exec(a)||/(win)/.exec(a)||/(mac)/.exec(a)||/(linux)/.exec(a)||[];return{browser:b[3]||b[1]||"",version:b[2]||"0",platform:c[0]||""}},c=a.uaMatch(b.navigator.userAgent),d={},c.browser&&(d[c.browser]=!0,d.version=c.version,d.versionNumber=parseInt(c.version)),c.platform&&(d[c.platform]=!0),(d.chrome||d.opr||d.safari)&&(d.webkit=!0),d.rv){var e="msie";c.browser=e,d[e]=!0}if(d.opr){var f="opera";c.browser=f,d[f]=!0}if(d.safari&&d.android){var g="android";c.browser=g,d[g]=!0}d.name=c.browser,d.platform=c.platform,a.browser=d}(jQuery,window);

View File

@@ -0,0 +1,23 @@
{
"name": "jquery.browser",
"version": "0.0.5",
"authors": [
"Gabriel Cebrian <gabceb@gmail.com>",
"jQuery Team <https://github.com/gabceb/jquery-browser-plugin/wiki/Authors>"
],
"description": "A jQuery plugin for browser detection.",
"repository": "git@github.com:gabceb/jquery-browser-plugin.git",
"devDependencies": {
"webserver": "*",
"utils": "*",
"grunt": "~0.4.0",
"grunt-contrib-jshint": "~0.1.1",
"grunt-contrib-uglify": "~0.2.7",
"grunt-contrib-copy": "~0.4.1",
"grunt-exec": "~0.4.2"
},
"license": "MIT",
"engines": {
"node": ">= 0.4.0"
}
}

View File

@@ -0,0 +1,257 @@
/*
* Proof of concept of a testserver for CasperJS.
*/
/*global CasperError exports phantom require*/
var fs = require('fs');
var webserver = require('webserver');
/**
* Creates a server instance.
*
* @param Casper casper A Casper instance
* @param Object options Server options
* @return Server
*/
exports.create = function create(casper, options) {
"use strict";
var server = new Server(casper, options);
casper.server = server;
return server;
};
/**
* Casper server: serve responses, fake them, listen to requests
*
* @param Casper casper A valid Casper instance
* @param Object|null options Options object
*/
var Server = function Server(casper, options) {
"use strict";
this.casper = casper;
options = options || {};
this.options = {};
this.options.port = options.port || 8008; // port the server will listen to
this.options.defaultStatusCode = options.defaultStatusCode || 200; // can be overrided through options
this.options.responsesDir = options.responsesDir || './'; // where to look for response content files
this.watchedPaths = {
"^/(\\?.*)?$": {filePath: 'test/index.html', permanent: true},
"/src/jquery.browser.js": {filePath: 'test/src/jquery.browser.js', permanent: true},
"/src/jquery-1.10.2.min.js": {filePath: 'test/src/jquery-1.10.2.min.js', permanent: true},
};
this.watchedRequests = {};
};
exports.Server = Server;
/**
* Start the server
*/
Server.prototype.start = function start() {
"use strict";
this.webserver = webserver.create();
var self = this;
this.service = this.webserver.listen(this.options.port, function (request, response) {self._serve(request, response);});
this.log("server started");
};
/**
* Stop the server
*/
Server.prototype.end = function start() {
"use strict";
this.webserver.close();
this.log("server closed");
};
/**
* Internal method, callback of the webserver.listen
*
* See: https://github.com/ariya/phantomjs/wiki/API-Reference#wiki-webserver-module
*/
Server.prototype._serve = function serve(request, response) {
"use strict";
response.statusCode = this.options.defaultStatusCode;
this.log("handling " + request.method + " on " + request.url, "debug");
// Handle request
if (typeof this.watchedRequests[request.url] !== "undefined") {
if (request.headers['Content-Type'] != "application/x-www-form-urlencoded") {
// phantomJS webserver does not handle multipart form, which
// is the default content-type of HTML5 FormData
this._splitFormData(request);
}
this.watchedRequests[request.url] = request;
}
// Handle response
var options = {};
for (var path in this.watchedPaths) {
if (request.url.search(path) !== -1) {
options = this.watchedPaths[path];
this.log("Build response from watched path " + request.url);
if (!options.permanent) {
// Automatically unwatch path, not to pollute tests context
this.unwatchPath(path);
}
break;
}
}
options._request = request;
this._buildResponse(response, options);
};
/*
* Modify the response according to options
*
* @param Object response the PhantomJS.webserver response instance
* @param Object options the options to use (content, filePath...)
*
*/
Server.prototype._buildResponse = function _buildResponse(response, options) {
var content,
statusCode,
filePath,
options = options || {};
if (options.content) {
if (typeof options.content === 'function') {
content = options.content(options._request);
}
else {
content = options.content;
}
}
else {
if (options.filePath) {
if (typeof options.filePath === 'function') {
filePath = options.filePath(options._request);
}
else {
filePath = options.filePath;
}
}
else {
filePath = options._request.url;
}
if (!/^(\.|\/)/.test(filePath)) {
filePath = this.options.responsesDir + filePath;
}
if (fs.exists(filePath)) {
this.log("Getting content from " + filePath);
content = fs.read(filePath);
}
else {
this.log("File not found: " + filePath, 'error');
}
}
if (options.statusCode) {
response.statusCode = options.statusCode;
}
if (!content) {
response.statusCode = 404;
content = 'No handler for the url ' + options._request.url;
}
response.write(content);
response.close();
};
/*
* Shortcut for logging with a prefix
*/
Server.prototype.log = function log(msg, level) {
if (typeof level == "undefined") {
level = "debug";
}
this.casper.log("[casperserver] " + msg, level);
};
/*
* replace the unparsed post string with a readable key/value
* EXPERIMENTAL!
* TODO: move to phantomJS or Mongoose?
*/
Server.prototype._splitFormData = function _splitFormData(request) {
// Example of raw post:
// "------WebKitFormBoundarysxecJyeWZZikD2xz\r\nContent-Disposition: form-data; name=\"name\"\r\n\r\nBirds map\r\n------WebKitFormBoundarysxecJyeWZZikD2xz\r\nContent-Disposition: form-data; name=\"description\"\r\n\r\nWhere have you seen birds?\r\n------WebKitFormBoundarysxecJyeWZZikD2xz\r\nContent-Disposition: form-data; name=\"licence\"\r\n\r\n1\r\n------WebKitFormBoundarysxecJyeWZZikD2xz\r\nContent-Disposition: form-data; name=\"center\"\r\n\r\nPOINT (15.9191894531249982 49.0018439179785261)\r\n------WebKitFormBoundarysxecJyeWZZikD2xz--\r\n"
var post = {},
rawPost = request.post.trim(),
boundary = "--" + request.headers['Content-Type'].split('boundary=')[1],
els = rawPost.split(boundary),
subels, name, value;
for (var j = 1, k = els.length; j < k; j++) {
if (!els[j] || els[j] == "--") {
continue;
}
subels = els[j].split('\r\n');
value = subels[3];
name = subels[1].match(/name="(\S+)"/i)[1];
post[name] = value;
}
request.post = post;
return request;
};
/**
* Indicate how to serve the response for some specific path
*
* @param Regex path the path to watch
* @param Object options options to use for response build
*/
Server.prototype.watchPath = function(path, options) {
this.watchedPaths[path] = options;
};
/**
* Unwatch a path
*
* @param Regex path the path to unwatch
*/
Server.prototype.unwatchPath = function(path) {
delete this.watchedPaths[path];
};
/**
* Indicate that the request for the specific path has to be stored for
* later inspection
*
* @param String path the path to watch
*/
Server.prototype.watchRequest = function(path) {
// Watch a response to be able to test its value after process
this.watchedRequests[path] = null;
};
/**
* Stop watching some path
*
* @param String path the path to watch
*/
Server.prototype.unwatchRequest = function(path) {
delete this.watchedRequests[path];
};
/**
* Indicate how to serve the response for some specific path
*
* @param String path the path to watch
* @return Object request a request instance
*/
Server.prototype.getWatchedRequest = function (path) {
if (!path) {
this.log("Can't retrieve watchedRequest for null path");
return;
}
var request = this.watchedRequests[path];
delete this.watchedRequests[path];
return request;
};

View File

@@ -0,0 +1,13 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>jQuery Browser plugin test</title>
<script type="text/javascript" src="src/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="src/jquery.browser.js"></script>
</head>
<body>
<h1>This page is left blank. Use casperjs to run tests.</h1>
</body>
</html>

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,102 @@
/*!
* jQuery Browser Plugin v0.0.5
* https://github.com/gabceb/jquery-browser-plugin
*
* Original jquery-browser code Copyright 2005, 2013 jQuery Foundation, Inc. and other contributors
* http://jquery.org/license
*
* Modifications Copyright 2013 Gabriel Cebrian
* https://github.com/gabceb
*
* Released under the MIT license
*
* Date: 2013-07-29T17:23:27-07:00
*/
(function( jQuery, window, undefined ) {
"use strict";
var matched, browser;
jQuery.uaMatch = function( ua ) {
ua = ua.toLowerCase();
var match = /(opr)[\/]([\w.]+)/.exec( ua ) ||
/(chrome)[ \/]([\w.]+)/.exec( ua ) ||
/(version)[ \/]([\w.]+).*(safari)[ \/]([\w.]+)/.exec(ua) ||
/(webkit)[ \/]([\w.]+)/.exec( ua ) ||
/(opera)(?:.*version|)[ \/]([\w.]+)/.exec( ua ) ||
/(msie) ([\w.]+)/.exec( ua ) ||
ua.indexOf("trident") >= 0 && /(rv)(?::| )([\w.]+)/.exec( ua ) ||
ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec( ua ) ||
[];
var platform_match = /(ipad)/.exec( ua ) ||
/(iphone)/.exec( ua ) ||
/(android)/.exec( ua ) ||
/(windows phone)/.exec(ua) ||
/(win)/.exec( ua ) ||
/(mac)/.exec( ua ) ||
/(linux)/.exec( ua ) ||
[];
return {
browser: match[ 3 ] || match[ 1 ] || "",
version: match[ 2 ] || "0",
platform: platform_match[0] || ""
};
};
matched = jQuery.uaMatch( window.navigator.userAgent );
browser = {};
if ( matched.browser ) {
browser[ matched.browser ] = true;
browser.version = matched.version;
browser.versionNumber = parseInt(matched.version);
}
if ( matched.platform ) {
browser[ matched.platform ] = true;
}
// Chrome, Opera 15+ and Safari are webkit based browsers
if ( browser.chrome || browser.opr || browser.safari ) {
browser.webkit = true;
}
// IE11 has a new token so we will assign it msie to avoid breaking changes
if ( browser.rv )
{
var ie = 'msie';
matched.browser = ie;
browser[ie] = true;
}
// Opera 15+ are identified as opr
if ( browser.opr )
{
var opera = 'opera';
matched.browser = opera;
browser[opera] = true;
}
// Stock Android browsers are marked as safari on Android.
if ( browser.safari && browser.android )
{
var android = 'android';
matched.browser = android;
browser[android] = true;
}
// Assign the name and platform variable
browser.name = matched.browser;
browser.platform = matched.platform;
jQuery.browser = browser;
})( jQuery, window );

View File

@@ -0,0 +1,563 @@
test_url = "http://localhost:8008"
var casper = require('casper').create({
verbose: true
});
require('casperserver.js').create(casper);
casper.server.start();
casper.on('exit', function(status){
casper.server.end();
});
ua = {
chrome : {
windows: "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1664.3 Safari/537.36",
mac: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1664.3 Safari/537.36",
android: "Mozilla/5.0 (Linux; Android 4.0.4; Galaxy Nexus Build/IMM76B) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1664.3 Mobile Safari/537.36",
linux: "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1664.3 Safari/537.36",
version : "32.0.1664.3",
versionNumber : 32,
name : "chrome"
},
safari : {
mac: "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9) AppleWebKit/537.71 (KHTML, like Gecko) Version/7.0 Safari/537.71",
ipad: "Mozilla/5.0(iPad; U; CPU iPhone OS 7_0_3 like Mac OS X; en-us) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11B508 Safari/9537.53",
iphone: "Mozilla/5.0(iPhone; CPU iPhone OS 7_0_3 like Mac OS X; en-us) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11B508 Safari/9537.53",
version: "7.0",
versionNumber: 7,
name : "safari"
},
firefox : {
windows: "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0",
mac: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:25.0) Gecko/20100101 Firefox/25.0",
linux: "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:25.0) Gecko/20100101 Firefox/25.0",
version: "25.0",
versionNumber: 25,
name : "mozilla"
},
ie : {
windows : {
v_9: "Mozilla/4.0 (compatible; MSIE 9.0; Windows NT 6.0; Trident/5.0)",
v_10: "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)",
v_11: 'Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko'
},
win_phone : {
v_10: "Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; ARM; Touch; NOKIA; Lumia 1020)"
},
name : "msie"
},
opera : {
v_15: {
mac : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.20 Safari/537.36 OPR/15.0.1147.18",
windows: "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.20 Safari/537.36 OPR/15.0.1147.18",
version: "15.0.1147.18",
versionNumber: 15
},
v_10: {
mac : "Opera/9.80 (Macintosh; Intel Mac OS X; U; en) Presto/2.2.15 Version/10.00",
windows: "Opera/9.80 (Windows NT 6.1; U; en) Presto/2.6.30 Version/10.00",
version: "10.00",
versionNumber: 10
},
v_12: {
mac : "Opera/9.80 (Macintosh; Intel Mac OS X; U; en) Presto/2.2.15 Version/12.11",
windows: "Opera/9.80 (Windows NT 6.1; U; en) Presto/2.6.30 Version/12.11",
version: "12.11",
versionNumber: 12
},
name : "opera"
},
android : {
v_4_4: {
android : "Mozilla/5.0 (Linux; Android 4.4.1; Nexus 5 Build/KOT49E) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Mobile Safari/537.36",
version: "4.0",
versionNumber: 4
},
name: "android"
}
}
casper.test.begin("when using Chrome on Windows", 6, function(test) {
casper.userAgent(ua.chrome.windows);
casper.start(test_url).then(function(){
var browser = casper.evaluate(function(){
return $.browser;
});
test.assert(browser.chrome, "Browser should be Chrome");
test.assertEquals(browser.name, ua.chrome.name,"Browser name should be " + ua.chrome.name);
test.assert(browser.webkit, "Browser should be webkit based");
test.assertEquals(browser.version, ua.chrome.version, "String version should be " + ua.chrome.version);
test.assertEquals(browser.versionNumber, ua.chrome.versionNumber, "Number version should be " + ua.chrome.versionNumber);
test.assert(browser.win, "Platform should be Windows");
}).run(function(){
test.done();
});
});
casper.test.begin("when using Chrome on Mac", 6, function(test) {
casper.userAgent(ua.chrome.mac);
casper.start(test_url).then(function(){
var browser = casper.evaluate(function(){
return $.browser;
});
test.assert(browser.chrome, "Browser should be Chrome");
test.assertEquals(browser.name, ua.chrome.name,"Browser name should be " + ua.chrome.name);
test.assert(browser.webkit, "Browser should be webkit based");
test.assertEquals(browser.version, ua.chrome.version, "Version should be " + ua.chrome.version);
test.assertEquals(browser.versionNumber, ua.chrome.versionNumber, "Number version should be " + ua.chrome.versionNumber);
test.assert(browser.mac, "Platform should be mac");
}).run(function(){
test.done();
});
});
casper.test.begin("when using Chrome on an Android device", 6, function(test) {
casper.userAgent(ua.chrome.android);
casper.start(test_url).then(function(){
var browser = casper.evaluate(function(){
return $.browser;
});
test.assert(browser.chrome, "Browser should be Chrome");
test.assertEquals(browser.name, ua.chrome.name,"Browser name should be " + ua.chrome.name);
test.assert(browser.webkit, "Browser should be webkit based");
test.assertEquals(browser.version, ua.chrome.version, "Version should be " + ua.chrome.version);
test.assertEquals(browser.versionNumber, ua.chrome.versionNumber, "Version should be " + ua.chrome.versionNumber);
test.assert(browser.android, "Platform should be android");
}).run(function(){
test.done();
});
});
casper.test.begin("when using Chrome on Linux", 6, function(test) {
casper.userAgent(ua.chrome.linux);
casper.start(test_url).then(function(){
var browser = casper.evaluate(function(){
return $.browser;
});
test.assert(browser.chrome, "Browser should be Chrome");
test.assertEquals(browser.name, ua.chrome.name,"Browser name should be " + ua.chrome.name);
test.assert(browser.webkit, "Browser should be webkit based");
test.assertEquals(browser.version, ua.chrome.version, "Version should be " + ua.chrome.version);
test.assertEquals(browser.versionNumber, ua.chrome.versionNumber, "Version should be " + ua.chrome.versionNumber);
test.assert(browser.linux, "Platform should be linux");
}).run(function(){
test.done();
});
});
casper.test.begin("when using Firefox on Windows", 6, function(test) {
casper.userAgent(ua.firefox.windows);
casper.start(test_url).then(function(){
var browser = casper.evaluate(function(){
return $.browser;
});
test.assert(browser.mozilla, "Browser should be Mozilla");
test.assertEquals(browser.name, ua.firefox.name,"Browser name should be " + ua.firefox.name);
test.assertEquals(browser.version, ua.firefox.version, "Version should be " + ua.firefox.version);
test.assertEquals(browser.versionNumber, ua.firefox.versionNumber, "Version should be " + ua.firefox.versionNumber);
test.assert(browser.win, "Platform should be Windows");
test.assertFalsy(browser.webkit, "Browser should NOT be webkit based");
}).run(function(){
test.done();
});
});
casper.test.begin("when using Firefox on Mac", 6, function(test) {
casper.userAgent(ua.firefox.mac);
casper.start(test_url).then(function(){
var browser = casper.evaluate(function(){
return $.browser;
});
test.assert(browser.mozilla, "Browser should be Mozilla");
test.assertEquals(browser.name, ua.firefox.name,"Browser name should be " + ua.firefox.name);
test.assertEquals(browser.version, ua.firefox.version, "Version should be " + ua.firefox.version);
test.assertEquals(browser.versionNumber, ua.firefox.versionNumber, "Version should be " + ua.firefox.versionNumber);
test.assert(browser.mac, "Platform should be mac");
test.assertFalsy(browser.webkit, "Browser should NOT be webkit based");
}).run(function(){
test.done();
});
});
casper.test.begin("when using Firefox on Linux", 6, function(test) {
casper.userAgent(ua.firefox.linux);
casper.start(test_url).then(function(){
var browser = casper.evaluate(function(){
return $.browser;
});
test.assert(browser.mozilla, "Browser should be Mozilla");
test.assertEquals(browser.name, ua.firefox.name,"Browser name should be " + ua.firefox.name);
test.assertEquals(browser.version, ua.firefox.version, "Version should be " + ua.firefox.version);
test.assertEquals(browser.versionNumber, ua.firefox.versionNumber, "Version should be " + ua.firefox.versionNumber);
test.assert(browser.linux, "Platform should be linux");
test.assertFalsy(browser.webkit, "Browser should NOT be webkit based");
}).run(function(){
test.done();
});
});
casper.test.begin("when using Safari on Mac", 6, function(test) {
casper.userAgent(ua.safari.mac);
casper.start(test_url).then(function(){
var browser = casper.evaluate(function(){
return $.browser;
});
test.assert(browser.safari, "Browser should be Safari");
test.assertEquals(browser.name, ua.safari.name,"Browser name should be " + ua.safari.name);
test.assert(browser.webkit, "Browser should be webkit based");
test.assertEquals(browser.version, ua.safari.version, "Version should be " + ua.safari.version);
test.assertEquals(browser.versionNumber, ua.safari.versionNumber, "Version should be " + ua.safari.versionNumber);
test.assert(browser.mac, "Platform should be mac");
}).run(function(){
test.done();
});
});
casper.test.begin("when using Safari on iPad", 6, function(test) {
casper.userAgent(ua.safari.ipad);
casper.start(test_url).then(function(){
var browser = casper.evaluate(function(){
return $.browser;
});
test.assert(browser.safari, "Browser should be Safari");
test.assertEquals(browser.name, ua.safari.name,"Browser name should be " + ua.safari.name);
test.assert(browser.webkit, "Browser should be webkit based");
test.assertEquals(browser.version, ua.safari.version, "Version should be " + ua.safari.version);
test.assertEquals(browser.versionNumber, ua.safari.versionNumber, "Version number should be " + ua.safari.versionNumber);
test.assert(browser.ipad, "Platform should be iPad");
}).run(function(){
test.done();
});
});
casper.test.begin("when using Safari on iPhone", 6, function(test) {
casper.userAgent(ua.safari.iphone);
casper.start(test_url).then(function(){
var browser = casper.evaluate(function(){
return $.browser;
});
test.assert(browser.safari, "Browser should be Safari");
test.assertEquals(browser.name, ua.safari.name,"Browser name should be " + ua.safari.name);
test.assert(browser.webkit, "Browser should be webkit based");
test.assertEquals(browser.version, ua.safari.version, "Version should be " + ua.safari.version);
test.assertEquals(browser.versionNumber, ua.safari.versionNumber, "Version number should be " + ua.safari.versionNumber);
test.assert(browser.iphone, "Platform should be iPhone");
}).run(function(){
test.done();
});
});
casper.test.begin("when using IE9", 6, function(test) {
casper.userAgent(ua.ie.windows.v_9);
casper.start(test_url).then(function(){
var browser = casper.evaluate(function(){
return $.browser;
});
test.assert(browser.msie, "Browser should be IE");
test.assertEquals(browser.name, ua.ie.name,"Browser name should be " + ua.ie.name);
test.assertEquals(browser.version, "9.0", "Version should be 9.0");
test.assertEquals(browser.versionNumber, 9, "Version should be 9");
test.assert(browser.win, "Platform should be Windows");
test.assertFalsy(browser.webkit, "Browser should NOT be webkit based");
}).run(function(){
test.done();
});
});
casper.test.begin("when using IE10", 6, function(test) {
casper.userAgent(ua.ie.windows.v_10);
casper.start(test_url).then(function(){
var browser = casper.evaluate(function(){
return $.browser;
});
test.assert(browser.msie, "Browser should be IE");
test.assertEquals(browser.name, ua.ie.name,"Browser name should be " + ua.ie.name);
test.assertEquals(browser.version, "10.0", "Version should be 10");
test.assertEquals(browser.versionNumber, 10, "Version should be 10");
test.assert(browser.win, "Platform should be Windows");
test.assertFalsy(browser.webkit, "Browser should NOT be webkit based");
}).run(function(){
test.done();
});
});
casper.test.begin("when using IE11", 6, function(test) {
casper.userAgent(ua.ie.windows.v_11);
casper.start(test_url).then(function(){
var browser = casper.evaluate(function(){
return $.browser;
});
test.assert(browser.msie, "Browser should be IE");
test.assertEquals(browser.name, ua.ie.name,"Browser name should be " + ua.ie.name);
test.assertEquals(browser.version, "11.0", "Version should be 11.0");
test.assertEquals(browser.versionNumber, 11, "Version should be 11");
test.assert(browser.win, "Platform should be Windows");
test.assertFalsy(browser.webkit, "Browser should NOT be webkit based");
}).run(function(){
test.done();
});
});
casper.test.begin("when using IE10 on a Windows Phone", 6, function(test) {
casper.userAgent(ua.ie.win_phone.v_10);
casper.start(test_url).then(function(){
var browser = casper.evaluate(function(){
return $.browser;
});
test.assert(browser.msie, "Browser should be IE");
test.assertEquals(browser.name, ua.ie.name,"Browser name should be " + ua.ie.name);
test.assertEquals(browser.version, "10.0", "Version should be 10.0");
test.assertEquals(browser.versionNumber, 10, "Version should be 10");
test.assert(browser["windows phone"], "Platform should be Windows Phone");
test.assertFalsy(browser.webkit, "Browser should NOT be webkit based");
}).run(function(){
test.done();
});
});
casper.test.begin("when using Opera 15+ on Windows", 6, function(test) {
casper.userAgent(ua.opera.v_15.windows);
casper.start(test_url).then(function(){
var browser = casper.evaluate(function(){
return $.browser;
});
test.assert(browser.opera, "Browser should be Opera");
test.assertEquals(browser.name, ua.opera.name,"Browser name should be " + ua.opera.name);
test.assertEquals(browser.version, ua.opera.v_15.version, "Version should be " + ua.opera.v_15.version);
test.assertEquals(browser.versionNumber, ua.opera.v_15.versionNumber, "Version number should be " + ua.opera.v_15.versionNumber);
test.assert(browser.win, "Platform should be Windows");
test.assert(browser.webkit, "Browser should be webkit based");
}).run(function(){
test.done();
});
});
casper.test.begin("when using Opera 15+ on Mac", 6, function(test) {
casper.userAgent(ua.opera.v_15.mac);
casper.start(test_url).then(function(){
var browser = casper.evaluate(function(){
return $.browser;
});
test.assert(browser.opera, "Browser should be Opera");
test.assertEquals(browser.name, ua.opera.name,"Browser name should be " + ua.opera.name);
test.assertEquals(browser.version, ua.opera.v_15.version, "Version should be " + ua.opera.v_15.version)
test.assertEquals(browser.versionNumber, ua.opera.v_15.versionNumber, "Version number should be " + ua.opera.v_15.versionNumber);
test.assert(browser.mac, "Platform should be Mac");
test.assert(browser.webkit, "Browser should be webkit based");
}).run(function(){
test.done();
});
});
casper.test.begin("when using Opera 10 on Windows", 6, function(test) {
casper.userAgent(ua.opera.v_10.windows);
casper.start(test_url).then(function(){
var browser = casper.evaluate(function(){
return $.browser;
});
test.assert(browser.opera, "Browser should be Opera");
test.assertEquals(browser.name, ua.opera.name,"Browser name should be " + ua.opera.name);
test.assertEquals(browser.version, ua.opera.v_10.version, "Version should be " + ua.opera.v_10.version);
test.assertEquals(browser.versionNumber, ua.opera.v_10.versionNumber, "Version number should be " + ua.opera.v_10.versionNumber);
test.assert(browser.win, "Platform should be Windows");
test.assertFalsy(browser.webkit, "Browser should NOT be webkit based");
}).run(function(){
test.done();
});
});
casper.test.begin("when using Opera 10 on Mac", 6, function(test) {
casper.userAgent(ua.opera.v_10.mac);
casper.start(test_url).then(function(){
var browser = casper.evaluate(function(){
return $.browser;
});
test.assert(browser.opera, "Browser should be Opera");
test.assertEquals(browser.name, ua.opera.name,"Browser name should be " + ua.opera.name);
test.assertEquals(browser.version, ua.opera.v_10.version, "Version should be " + ua.opera.v_10.version);
test.assertEquals(browser.versionNumber, ua.opera.v_10.versionNumber, "Version number should be " + ua.opera.v_10.versionNumber);
test.assert(browser.mac, "Platform should be Mac");
test.assertFalsy(browser.webkit, "Browser should NOT be webkit based");
}).run(function(){
test.done();
});
});
casper.test.begin("when using Opera 12.11 on Windows", 6, function(test) {
casper.userAgent(ua.opera.v_12.windows);
casper.start(test_url).then(function(){
var browser = casper.evaluate(function(){
return $.browser;
});
test.assert(browser.opera, "Browser should be Opera");
test.assertEquals(browser.name, ua.opera.name,"Browser name should be " + ua.opera.name);
test.assertEquals(browser.version, ua.opera.v_12.version, "Version should be " + ua.opera.v_12.version);
test.assertEquals(browser.versionNumber, ua.opera.v_12.versionNumber, "Version number should be " + ua.opera.v_12.versionNumber);
test.assert(browser.win, "Platform should be Windows");
test.assertFalsy(browser.webkit, "Browser should NOT be webkit based");
}).run(function(){
test.done();
});
});
casper.test.begin("when using Opera 12.11 on Mac", 6, function(test) {
casper.userAgent(ua.opera.v_12.mac);
casper.start(test_url).then(function(){
var browser = casper.evaluate(function(){
return $.browser;
});
test.assert(browser.opera, "Browser should be Opera");
test.assertEquals(browser.name, ua.opera.name,"Browser name should be " + ua.opera.name);
test.assertEquals(browser.version, ua.opera.v_12.version, "Version should be " + ua.opera.v_12.version);
test.assertEquals(browser.versionNumber, ua.opera.v_12.versionNumber, "Version number should be " + ua.opera.v_12.versionNumber);
test.assert(browser.mac, "Platform should be Mac");
test.assertFalsy(browser.webkit, "Browser should NOT be webkit based");
}).run(function(){
test.done();
});
});
casper.test.begin("when using Android 4.4 stock browser on Android", 5, function(test) {
casper.userAgent(ua.android.v_4_4.android);
casper.start(test_url).then(function(){
var browser = casper.evaluate(function(){
return $.browser;
});
test.assert(browser.android, "Browser should be Android");
test.assertEquals(browser.name, ua.android.name,"Browser name should be " + ua.android.name);
test.assertEquals(browser.version, ua.android.v_4_4.version, "Version should be " + ua.android.v_4_4.version);
test.assertEquals(browser.versionNumber, ua.android.v_4_4.versionNumber, "Version number should be " + ua.android.v_4_4.versionNumber);
test.assert(browser.webkit, "Browser should be webkit based");
}).run(function(){
test.done();
casper.exit();
});
});