Skip to content
This repository was archived by the owner on Nov 30, 2017. It is now read-only.

Commit 79f22dd

Browse files
committed
Built WhichBrowser from commit 3cdf907 on WhichBrowser/WhichBrowser on branch dev
1 parent 823fecd commit 79f22dd

File tree

2 files changed

+5
-321
lines changed

2 files changed

+5
-321
lines changed

README.md

+4-320
Original file line numberDiff line numberDiff line change
@@ -1,324 +1,8 @@
1-
WhichBrowser/Server
1+
WhichBrowser/Legacy
22
===================
33

4-
A server for the WhichBrowser/Parser library that exposes an API for use in the browser.
4+
This project contains the legacy version of WhichBrowser project.
55

6+
Please consider moving to the current version of WhichBrowser. Installing WhichBrowser using Git or Bower is no longer supported. If you want to continue getting updates please reinstall WhichBrowser using Composer. If you previously installed the `whichbrowser/whichbrowser` package using Composer, please also consider moving to the current version of WhichBrowser.
67

7-
8-
Requirements
9-
-----------------
10-
11-
The server should be able to handle PHP and included is a `.htaccess` file that instructs the server to use `detect.js` as an alias for `detect.php`. This is not required, but if your server does not support `.htaccess` files you may want to find a way to make your server do the same. Alternatively you could use the `detect.php` directly.
12-
13-
14-
15-
How to install it
16-
-----------------
17-
18-
You can install WhichBrowser by using Composer - the standard package manager for PHP. The package is called `whichbrowser/server`. This sets up all dependancies like the PHP parser library.
19-
20-
composer require whichbrowser/server
21-
22-
You can easily update WhichBrowser by running a simple command.
23-
24-
composer update
25-
26-
You should run this command as often as possible. You might even want to consider setting up a cron job for this purpose.
27-
28-
After installing with Composer you may need to create a symlink to the vendor directory in which WhichBrowser was installed:
29-
30-
ln -s vendor/whichbrowser/server whichbrowser
31-
32-
Or create a `.htaccess` file in the root of your site and add an `Alias` command:
33-
34-
Alias /whichbrowser vendor/whichbrowser/server
35-
36-
37-
38-
How to use it
39-
-------------
40-
41-
The first step is to place a snippet of code on you webpage.
42-
43-
<script>
44-
(function(){var p=[],w=window,d=document,e=f=0;p.push('ua='+encodeURIComponent(navigator.userAgent));e|=w.ActiveXObject?1:0;e|=w.opera?2:0;e|=w.chrome?4:0;
45-
e|='getBoxObjectFor' in d || 'mozInnerScreenX' in w?8:0;e|=('WebKitCSSMatrix' in w||'WebKitPoint' in w||'webkitStorageInfo' in w||'webkitURL' in w)?16:0;
46-
e|=(e&16&&({}.toString).toString().indexOf("\n")===-1)?32:0;p.push('e='+e);f|='sandbox' in d.createElement('iframe')?1:0;f|='WebSocket' in w?2:0;
47-
f|=w.Worker?4:0;f|=w.applicationCache?8:0;f|=w.history && history.pushState?16:0;f|=d.documentElement.webkitRequestFullScreen?32:0;f|='FileReader' in w?64:0;
48-
p.push('f='+f);p.push('r='+Math.random().toString(36).substring(7));p.push('w='+screen.width);p.push('h='+screen.height);var s=d.createElement('script');
49-
s.src='//yourserver/whichbrowser/detect.js?' + p.join('&');d.getElementsByTagName('head')[0].appendChild(s);})();
50-
</script>
51-
52-
Please make sure you change the URL of the detect.js file to point it to your own server.
53-
54-
To get the exact snippet you need to include visit the directory in which you installed WhichBrowser in your browser.
55-
56-
The second step is to create a new `WhichBrowser` object. This object will contain all the information the library could find about your browser.
57-
58-
For example:
59-
60-
result = new WhichBrowser();
61-
62-
63-
The variable `result` now contains an object which you can query for information. There are various ways to access the information.
64-
65-
66-
First of all, you can treat the object as a string to get a human readable identification:
67-
68-
"You are using " + result
69-
// You are using Chrome 27 on Mac OS X 10.8.4
70-
71-
If you need to, you can also explicitly typecast the object to a string
72-
73-
String(result)
74-
result.toString()
75-
76-
77-
Or you can turn the object into JSON:
78-
79-
JSON.stringify(result)
80-
// { "browser": {"name":"Chrome","version":{"value":"27"...
81-
82-
83-
Another possiblity is to query the object:
84-
85-
result.isType('desktop')
86-
// true
87-
88-
result.isType('mobile', 'tablet', 'media')
89-
// false
90-
91-
result.isBrowser('Maxthon', '<', '4.0.5')
92-
// false
93-
94-
result.isOs('iOS', '>=', '5')
95-
// false
96-
97-
result.isEngine('Blink')
98-
// true
99-
100-
101-
You can also access these properties directly:
102-
103-
result.browser
104-
// Chrome 27
105-
106-
result.engine
107-
// Blink
108-
109-
result.os
110-
// Mac OS X 10.8.4
111-
112-
113-
Or access parts of these properties directly:
114-
115-
result.browser.name
116-
// Chrome
117-
118-
result.browser.name + ' ' + String(result.browser.version)
119-
// Chrome 27
120-
121-
result.browser.version.major
122-
// 27
123-
124-
result.browser.version.minor
125-
// 0
126-
127-
result.browser.version.original
128-
// 27.0.1453.110
129-
130-
result.engine.name
131-
// Blink
132-
133-
134-
Finally you can also query versions directly:
135-
136-
result.browser.version.is('>', 26)
137-
// true
138-
139-
result.os.version.is('<', '10.7.4')
140-
// false
141-
142-
143-
API reference
144-
-------------
145-
146-
### The WhichBrowser object
147-
148-
After a new `WhichBrowser` object is created, it contains a number of properties and functions. All of these properties are guaranteed to be present.
149-
150-
**Properties:**
151-
152-
* `browser`
153-
an object that contains information about the browser itself
154-
* `engine`
155-
an object that contains information about the rendering engine
156-
* `os`
157-
an object that contains information about the operating system
158-
* `device`
159-
an object that contains information about the device
160-
161-
**Functions:**
162-
163-
`isType(type [,type [,type [,type]]])`
164-
If a single argument is used, the function returns `true` if the argument matches the `type` propery of `device` obejct. It can use multiple arguments in which case the function returns `true` if one of the arguments matches. If none of the arguments matches, it returns `false`
165-
166-
`isBrowser(name [, comparison, version])`
167-
Is used to query the `name` and `version` property of the `browser` object. The funcion can contain a single argument to a simple comparison based on `name`, or three arguments to compare both `name` and `version`. The first argument always contains the name of the browser. The second arguments is a string that can container either `<`, `<=`, `=`, `=>` or `>`. The third is an integer, float or string that contains the version. You can use versions like `10`, `10.7` or `'10.7.4'`. For more information about how version comparisons are performed, please see the `is()` function of the `Version` object.
168-
169-
`isEngine(name [, comparison, version])`
170-
Is used to query the `name` and `version` property of the `engine` object. This function works in exactly the same way as `isBrowser`.
171-
172-
`isOs(name [, comparison, version])`
173-
Is used to query the `name` and `version` property of the `os` object. This function works in exactly the same way as `isBrowser`.
174-
175-
176-
### The browser object
177-
178-
The `Browser` object is used for the `browser` property of the main `WhichBrowser` object and contains a number of properties. If a property is not applicable in this situation it will be null.
179-
180-
**Properties:**
181-
182-
* `name`
183-
a string containing the name of the browser
184-
* `version`
185-
a version object containing information about the version of the browser
186-
* `stock`
187-
a boolean, true if the browser is the default browser of the operating system, false otherwise
188-
* `channel`
189-
a string containing the distribution channel, ie. 'Nightly' or 'Next'.
190-
* `mode`
191-
a string that can contain the operating mode of the browser, ie. 'proxy'.
192-
* `hidden`
193-
a boolean that is true if the browser does not have a name and is the default of the operating system.
194-
195-
196-
### The engine object
197-
198-
The `Engine` object is used for the `engine` property of the main `WhichBrowser` object and contains a number of properties. If a property is not applicable in this situation it will be null.
199-
200-
**Properties:**
201-
202-
* `name`
203-
a string containing the name of the rendering engine
204-
* `version`
205-
a version object containing information about the version of the rendering engine
206-
207-
208-
### The os object
209-
210-
The `Os` object is used for the `os` property of the main `WhichBrowser` object and contains a number of properties. If a property is not applicable in this situation it will be null.
211-
212-
**Properties:**
213-
214-
* `name`
215-
a string containing the name of the operating system
216-
* `version`
217-
a version object containing information about the version of the operating system
218-
219-
220-
### The device object
221-
222-
The `Device` object is used for the `device` property of the main `WhichBrowser` object and contains a number of properties. If a property is not applicable in this situation it will be null.
223-
224-
**Properties:**
225-
226-
* `type`
227-
a string containing the type of the browser.
228-
* `identified`
229-
a boolean that is true if the device has been positively identified.
230-
* `manufacturer`
231-
a string containing the manufacturer of the device, ie. 'Apple' or 'Samsung'.
232-
* `model`
233-
as string containing the model of the device, ie. 'iPhone' or 'Galaxy S4'.
234-
235-
The `type` property can contain any value from the following list:
236-
237-
* desktop
238-
* mobile
239-
* tablet
240-
* gaming
241-
* headset
242-
* ereader
243-
* media
244-
* emulator
245-
* television
246-
* monitor
247-
* camera
248-
* signage
249-
* whiteboard
250-
* car
251-
* pos
252-
* bot
253-
254-
255-
### The version object
256-
257-
The `Version` object is used for the `version` property of the `browser`, `engine` and `os` object and contains a number of properties and functions. If a property is not applicable in this situation it will be null.
258-
259-
**Properties:**
260-
261-
* `original`
262-
a string containing the original version number.
263-
* `alias`
264-
a string containing an alias for the version number, ie. 'XP' for Windows '5.1'.
265-
* `details`
266-
an integer containing the number of digits of the version number that should be printed.
267-
* `major`
268-
an integer containing the major version number.
269-
* `minor`
270-
an integer containing the minor version number.
271-
* `type`
272-
a string containing a type indicator, ie. 'beta' or 'alpha'.
273-
274-
**Functions:**
275-
276-
`is(version)` or `is(comparison, version)`
277-
Using this function it is easy to compare a version to another version. If you specify only one argument, this function will return if the versions are the same. You can also specify two arguments, in that case the first argument contains the comparison operator, such as `<`, `<=`, `=`, `=>` or `>`. The second argument is the version you want to compare it to. You can use versions like `10`, `10.7` or `'10.7.4'`, but be aware that `10` is not the same as `10.0`. For example if our OS version is `10.7.4`:
278-
279-
result.os.version.is('10.7.4')
280-
// true
281-
282-
result.os.version.is('10.7')
283-
// true
284-
285-
result.os.version.is('10')
286-
// true
287-
288-
result.os.version.is('10.0')
289-
// false
290-
291-
result.os.version.is('>', '10')
292-
// false
293-
294-
result.os.version.is('>', '10.7')
295-
// false
296-
297-
result.os.version.is('>', '10.7.3')
298-
// true
299-
300-
301-
302-
License
303-
-------
304-
305-
Copyright (c) 2015 Niels Leenheer
306-
307-
Permission is hereby granted, free of charge, to any person obtaining
308-
a copy of this software and associated documentation files (the
309-
"Software"), to deal in the Software without restriction, including
310-
without limitation the rights to use, copy, modify, merge, publish,
311-
distribute, sublicense, and/or sell copies of the Software, and to
312-
permit persons to whom the Software is furnished to do so, subject to
313-
the following conditions:
314-
315-
The above copyright notice and this permission notice shall be
316-
included in all copies or substantial portions of the Software.
317-
318-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
319-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
320-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
321-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
322-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
323-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
324-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8+
For more information about installing the current version of WhichBrowser, please see the main [WhichBrowser](https://github.com/WhichBrowser/WhichBrowser) project.

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "whichbrowser/whichbrowser",
3-
"description": "User agent sniffing gone too far",
3+
"description": "Project containing the legacy version of WhichBrowser",
44
"keywords": ["useragent","browser"],
55
"homepage": "http://whichbrowser.net",
66
"license": "MIT",

0 commit comments

Comments
 (0)