Skip to content

Commit

Permalink
Adding example usage of device.noConflict()
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Hudson committed Oct 30, 2013
1 parent df1fd40 commit 7f3fc72
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
14 changes: 12 additions & 2 deletions examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,13 @@ <h2>Device OS</h2>
</div>
</div>

<script src="../lib/device.min.js"></script>

<script type="text/javascript">
// Dummy value for demonstrating device.noConflict()
window.device = "Hello World!";
</script>

<script src="../lib/device.js"></script>

<script type="text/javascript">
console.log("device.portrait() === %s", device.portrait());
console.log("device.landscape() === %s", device.landscape());
Expand All @@ -184,6 +189,11 @@ <h2>Device OS</h2>
console.log("device.fxos() === %s", device.fxos());
console.log("device.fxosPhone() === %s", device.fxosPhone());
console.log("device.fxosTablet() === %s", device.fxosTablet());

var devicejs = device.noConflict();

console.log ("device.noConflict() [previous]", window.device);
console.log ("device.noConflict() [device.js]", devicejs.iphone());
</script>

</body>
Expand Down
9 changes: 8 additions & 1 deletion lib/device.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
(function() {
var _addClass, _doc_element, _find, _handleOrientation, _hasClass, _orientation_event, _removeClass, _supports_orientation, _user_agent;
var previousDevice, _addClass, _doc_element, _find, _handleOrientation, _hasClass, _orientation_event, _removeClass, _supports_orientation, _user_agent;

previousDevice = window.device;

window.device = {};

Expand Down Expand Up @@ -87,6 +89,11 @@
return Math.abs(window.orientation) === 90;
};

device.noConflict = function() {
window.device = previousDevice;
return this;
};

_find = function(needle) {
return _user_agent.indexOf(needle) !== -1;
};
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "device.js",
"version": "0.1.56",
"version": "0.1.58",
"homepage": "https://github.com/matthewhudson/device.js",
"description": "Device.js makes it easy to write conditional CSS and/or JavaScript based on device operating system (iOS, Android, Blackberry, Windows), orientation (Portrait vs. Landscape), and type (Tablet vs. Mobile).",
"author": {
Expand Down

0 comments on commit 7f3fc72

Please sign in to comment.