Skip to content

Commit

Permalink
Fixes to orientation changing, cleanup in syiro.device.FetchOperating…
Browse files Browse the repository at this point in the history
…System().
  • Loading branch information
JoshStrobl committed Aug 21, 2015
1 parent 7946bbe commit 8bcb735
Show file tree
Hide file tree
Showing 9 changed files with 286 additions and 267 deletions.
3 changes: 3 additions & 0 deletions build/syiro.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ interface Element {
interface Navigator {
doNotTrack: string;
}
interface Console {
profileEnd(profile?: string): any;
}
interface Screen {
orientation: any;
mozOrientation: any;
Expand Down
23 changes: 13 additions & 10 deletions build/syiro.js
Original file line number Diff line number Diff line change
Expand Up @@ -1286,8 +1286,10 @@ var syiro;
}
}
};
var orientationListener = screen;
if ((typeof screen.orientation !== "undefined") && (typeof screen.orientation.onchange !== "undefined")) {
syiro.device.OrientationObject = screen.orientation;
orientationListener = screen.orientation;
syiro.device.OrientationObject = screen.orientation.type;
syiro.events.eventStrings["orientationchange"] = ["change"];
}
else if (typeof screen.onmsorientationchange !== "undefined") {
Expand All @@ -1302,7 +1304,7 @@ var syiro;
syiro.events.eventStrings["orientationchange"] = ["orientationchange-viainterval"];
}
if (syiro.events.eventStrings["orientationchange"][0] !== "orientationchange-viainterval") {
syiro.events.Add(syiro.events.eventStrings["orientationchange"], syiro.device.OrientationObject, orientationChangeHandler);
syiro.events.Add(syiro.events.eventStrings["orientationchange"], orientationListener, orientationChangeHandler);
}
else {
window.setInterval(orientationChangeHandler.bind(this, "interval"), 2000);
Expand All @@ -1312,28 +1314,29 @@ var syiro;
}
device.Detect = Detect;
function FetchOperatingSystem() {
if (navigator.userAgent.indexOf("Android") !== -1) {
var userAgent = navigator.userAgent;
if (userAgent.indexOf("Android") !== -1) {
syiro.device.OperatingSystem = "Android";
}
else if ((navigator.userAgent.indexOf("iPhone") !== -1) || (navigator.userAgent.indexOf("iPad") !== -1)) {
else if ((userAgent.indexOf("iPhone") !== -1) || (userAgent.indexOf("iPad") !== -1)) {
syiro.device.OperatingSystem = "iOS";
}
else if ((navigator.userAgent.indexOf("Linux") !== -1) && (navigator.userAgent.indexOf("Android") == -1)) {
else if ((userAgent.indexOf("Linux") !== -1) && (userAgent.indexOf("Android") == -1)) {
syiro.device.OperatingSystem = "Linux";
if (navigator.userAgent.indexOf("Sailfish") !== -1) {
if (userAgent.indexOf("Sailfish") !== -1) {
syiro.device.OperatingSystem = "Sailfish";
}
else if ((navigator.userAgent.indexOf("Ubuntu") !== -1) && ((navigator.userAgent.indexOf("Mobile") !== -1) || (navigator.userAgent.indexOf("Tablet") !== -1))) {
else if ((userAgent.indexOf("Ubuntu") !== -1) && ((userAgent.indexOf("Mobile") !== -1) || (userAgent.indexOf("Tablet") !== -1))) {
syiro.device.OperatingSystem = "Ubuntu Touch";
}
}
else if (navigator.userAgent.indexOf("Macintosh") !== -1) {
else if (userAgent.indexOf("Macintosh") !== -1) {
syiro.device.OperatingSystem = "OS X";
}
else if (navigator.userAgent.indexOf("Windows Phone") !== -1) {
else if (userAgent.indexOf("Windows Phone") !== -1) {
syiro.device.OperatingSystem = "Windows Phone";
}
else if (navigator.userAgent.indexOf("Windows NT") !== -1) {
else if (userAgent.indexOf("Windows NT") !== -1) {
syiro.device.OperatingSystem = "Windows";
}
else {
Expand Down
236 changes: 118 additions & 118 deletions build/syiro.min.js

Large diffs are not rendered by default.

Binary file modified build/syiro.min.js.gz
Binary file not shown.
26 changes: 15 additions & 11 deletions src/typescript/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ namespace syiro.device {
// #region Detection Function - Use to detect functionality, define variables, etc.

export function Detect(){

// #region Do Not Track

if (typeof navigator.doNotTrack !== "undefined"){ // If DoNotTrack is defined in the navigator Object
Expand Down Expand Up @@ -144,8 +143,11 @@ namespace syiro.device {
}
}

var orientationListener : any = screen;

if ((typeof screen.orientation !== "undefined") && (typeof screen.orientation.onchange !== "undefined")){ // If Screen Orientation API is properly supported
syiro.device.OrientationObject = screen.orientation; // Point syiro.device.OrientationObject to screen.orientation rather than screen
orientationListener = screen.orientation; // Set orientationListener as the screen.orientation Object
syiro.device.OrientationObject = screen.orientation.type; // Point syiro.device.OrientationObject to screen.orientation type
syiro.events.eventStrings["orientationchange"] = ["change"]; // Set our eventStrings orientationchange to only change
}
else if (typeof screen.onmsorientationchange !== "undefined"){ // If this is the Internet Explorer vendor-prefixed orientation change
Expand All @@ -161,7 +163,7 @@ namespace syiro.device {
}

if (syiro.events.eventStrings["orientationchange"][0] !== "orientationchange-viainterval"){ // If orientation change is supported on the device
syiro.events.Add(syiro.events.eventStrings["orientationchange"], syiro.device.OrientationObject, orientationChangeHandler); // Add an orientation change event for the screen with our orientationChangeHandler
syiro.events.Add(syiro.events.eventStrings["orientationchange"], orientationListener, orientationChangeHandler); // Add an orientation change event for the screen with our orientationChangeHandler
}
else{ // If the device does not support orientation change
window.setInterval(orientationChangeHandler.bind(this, "interval"), 2000); // Set a timer for every two seconds to check for change in device orientation. We are using this due to the lack of full orientationchange event support in major browsers.
Expand All @@ -179,29 +181,31 @@ namespace syiro.device {
// #region Fetch Operating System

export function FetchOperatingSystem(){
if (navigator.userAgent.indexOf("Android") !== -1){ // If the userAgent is set to claim the device is Android
var userAgent : string = navigator.userAgent; // Get the userAgent

if (userAgent.indexOf("Android") !== -1){ // If the userAgent is set to claim the device is Android
syiro.device.OperatingSystem = "Android"; // Set device to Android
}
else if ((navigator.userAgent.indexOf("iPhone") !== -1) || (navigator.userAgent.indexOf("iPad") !== -1)){ // If the userAgent is set to claim the device is an iPhone or iPad
else if ((userAgent.indexOf("iPhone") !== -1) || (userAgent.indexOf("iPad") !== -1)){ // If the userAgent is set to claim the device is an iPhone or iPad
syiro.device.OperatingSystem = "iOS"; // Set device to iOS
}
else if ((navigator.userAgent.indexOf("Linux") !== -1) && (navigator.userAgent.indexOf("Android") == -1)){ // If the userAgent is set to claim the device is Linux (but not Android)
else if ((userAgent.indexOf("Linux") !== -1) && (userAgent.indexOf("Android") == -1)){ // If the userAgent is set to claim the device is Linux (but not Android)
syiro.device.OperatingSystem = "Linux"; // Set device to Linux

if (navigator.userAgent.indexOf("Sailfish") !== -1){ // If the userAgent is set to claim the device is a Sailfish OS device
if (userAgent.indexOf("Sailfish") !== -1){ // If the userAgent is set to claim the device is a Sailfish OS device
syiro.device.OperatingSystem = "Sailfish"; // Set device to Sailfish OS
}
else if ((navigator.userAgent.indexOf("Ubuntu") !== -1) && ((navigator.userAgent.indexOf("Mobile") !== -1) || (navigator.userAgent.indexOf("Tablet") !== -1))){ // IF the userAgent is claiming the device is running Ubuntu Touch
else if ((userAgent.indexOf("Ubuntu") !== -1) && ((userAgent.indexOf("Mobile") !== -1) || (userAgent.indexOf("Tablet") !== -1))){ // IF the userAgent is claiming the device is running Ubuntu Touch
syiro.device.OperatingSystem = "Ubuntu Touch"; // Set device to Ubuntu Touch
}
}
else if (navigator.userAgent.indexOf("Macintosh") !== -1){ // If the userAgent is set to claim the device is a Macintosh
else if (userAgent.indexOf("Macintosh") !== -1){ // If the userAgent is set to claim the device is a Macintosh
syiro.device.OperatingSystem = "OS X"; // Set device to OS X
}
else if (navigator.userAgent.indexOf("Windows Phone") !== -1){ // If the userAgent is set to claim the device is a Windows Phone
else if (userAgent.indexOf("Windows Phone") !== -1){ // If the userAgent is set to claim the device is a Windows Phone
syiro.device.OperatingSystem = "Windows Phone"; // Set device to Windows Phone
}
else if (navigator.userAgent.indexOf("Windows NT") !== -1){ // If the userAgent is set to claim the device is Windows
else if (userAgent.indexOf("Windows NT") !== -1){ // If the userAgent is set to claim the device is Windows
syiro.device.OperatingSystem = "Windows"; // Set device to Windows
}
else{ // If something else
Expand Down
4 changes: 4 additions & 0 deletions src/typescript/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ interface Navigator { // Implementation of valid spec not found in lib.d.ts
doNotTrack : string; // Define doNotTrack as a string
}

interface Console { // Implement Mozilla Console Profile spec.
profileEnd(profile ?: string);
}

// #region Extended Screen Interface

interface Screen {
Expand Down
2 changes: 2 additions & 0 deletions src/typescript/syiro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ namespace syiro {
syiro.secondaryColor = window.getComputedStyle(syiroInternalColorContainer).borderColor; // Get the secondaryColor defined in CSS as border-color key/val and set it to syiro.secondaryColor
document.body.removeChild(syiroInternalColorContainer); // Remove the no longer necessary Internal Color Container

// #endregion

// #region Watch DOM For Components

if (syiro.device.SupportsMutationObserver){ // If MutationObserver is supported by the browser
Expand Down
23 changes: 13 additions & 10 deletions tests/design/js/syiro.js
Original file line number Diff line number Diff line change
Expand Up @@ -1286,8 +1286,10 @@ var syiro;
}
}
};
var orientationListener = screen;
if ((typeof screen.orientation !== "undefined") && (typeof screen.orientation.onchange !== "undefined")) {
syiro.device.OrientationObject = screen.orientation;
orientationListener = screen.orientation;
syiro.device.OrientationObject = screen.orientation.type;
syiro.events.eventStrings["orientationchange"] = ["change"];
}
else if (typeof screen.onmsorientationchange !== "undefined") {
Expand All @@ -1302,7 +1304,7 @@ var syiro;
syiro.events.eventStrings["orientationchange"] = ["orientationchange-viainterval"];
}
if (syiro.events.eventStrings["orientationchange"][0] !== "orientationchange-viainterval") {
syiro.events.Add(syiro.events.eventStrings["orientationchange"], syiro.device.OrientationObject, orientationChangeHandler);
syiro.events.Add(syiro.events.eventStrings["orientationchange"], orientationListener, orientationChangeHandler);
}
else {
window.setInterval(orientationChangeHandler.bind(this, "interval"), 2000);
Expand All @@ -1312,28 +1314,29 @@ var syiro;
}
device.Detect = Detect;
function FetchOperatingSystem() {
if (navigator.userAgent.indexOf("Android") !== -1) {
var userAgent = navigator.userAgent;
if (userAgent.indexOf("Android") !== -1) {
syiro.device.OperatingSystem = "Android";
}
else if ((navigator.userAgent.indexOf("iPhone") !== -1) || (navigator.userAgent.indexOf("iPad") !== -1)) {
else if ((userAgent.indexOf("iPhone") !== -1) || (userAgent.indexOf("iPad") !== -1)) {
syiro.device.OperatingSystem = "iOS";
}
else if ((navigator.userAgent.indexOf("Linux") !== -1) && (navigator.userAgent.indexOf("Android") == -1)) {
else if ((userAgent.indexOf("Linux") !== -1) && (userAgent.indexOf("Android") == -1)) {
syiro.device.OperatingSystem = "Linux";
if (navigator.userAgent.indexOf("Sailfish") !== -1) {
if (userAgent.indexOf("Sailfish") !== -1) {
syiro.device.OperatingSystem = "Sailfish";
}
else if ((navigator.userAgent.indexOf("Ubuntu") !== -1) && ((navigator.userAgent.indexOf("Mobile") !== -1) || (navigator.userAgent.indexOf("Tablet") !== -1))) {
else if ((userAgent.indexOf("Ubuntu") !== -1) && ((userAgent.indexOf("Mobile") !== -1) || (userAgent.indexOf("Tablet") !== -1))) {
syiro.device.OperatingSystem = "Ubuntu Touch";
}
}
else if (navigator.userAgent.indexOf("Macintosh") !== -1) {
else if (userAgent.indexOf("Macintosh") !== -1) {
syiro.device.OperatingSystem = "OS X";
}
else if (navigator.userAgent.indexOf("Windows Phone") !== -1) {
else if (userAgent.indexOf("Windows Phone") !== -1) {
syiro.device.OperatingSystem = "Windows Phone";
}
else if (navigator.userAgent.indexOf("Windows NT") !== -1) {
else if (userAgent.indexOf("Windows NT") !== -1) {
syiro.device.OperatingSystem = "Windows";
}
else {
Expand Down
Loading

0 comments on commit 8bcb735

Please sign in to comment.