Skip to content
Permalink
Browse files

Added platform to DeviceComponent

  • Loading branch information
nvh committed Mar 22, 2017
1 parent 570aa20 commit 6ddff8f17979a16435e9f07152476fb7dbf1ed2a
Showing with 34 additions and 0 deletions.
  1. +13 −0 framer/Components/DeviceComponent.coffee
  2. +21 −0 test/tests/DeviceComponentTest.coffee
@@ -192,6 +192,19 @@ class exports.DeviceComponent extends BaseClass
# into the device screen
Framer.CurrentContext = @_context

platform: ->
if /google|nexus|htc|samsung/.test(@deviceType)
return "Android"
if /iphone|ipad/.test(@deviceType)
return "iOS"
if /apple-watch|applewatch/.test(@deviceType)
return "watchOS"
if /apple|safari/.test(@deviceType)
return "macOS"
if /microsoft|dell/.test(@deviceType)
return "Windows"
return null

###########################################################################
# FULLSCREEN

@@ -1,3 +1,5 @@
assert = require "assert"

describe "DeviceComponent", ->

it "should default to iphone 7 silver", ->
@@ -149,3 +151,22 @@ describe "DeviceComponent", ->
device.orientation.should.equal -90
device.isPortrait.should.equal false
device.screenSize.should.eql {width: 1920, height: 1080}

it "should return the correct platform per device", ->
device = new Framer.DeviceComponent()
for key, value of Framer.DeviceComponent.Devices
device.deviceType = key
switch device.platform()
when "iOS"
assert(_.startsWith(key, "iphone") or _.startsWith(key, "ipad") or _.startsWith(key, "apple-iphone") or _.startsWith(key, "apple-ipad"))
when "watchOS"
assert(_.startsWith(key, "apple-watch") or _.startsWith(key, "applewatch"))
when "Windows"
assert(_.startsWith(key, "dell") or _.startsWith(key, "microsoft"))
when "Android"
assert(_.startsWith(key, "google") or _.startsWith(key, "nexus") or _.startsWith(key, "htc") or _.startsWith(key, "samsung"))
when "macOS"
assert(_.startsWith(key, "apple-macbook") or _.startsWith(key, "apple-imac") or _.startsWith(key, "desktop-safari"))
else
# Exceptions
assert(key in ["fullscreen", "custom", "sony-w85Oc", "test"])

0 comments on commit 6ddff8f

Please sign in to comment.
You can’t perform that action at this time.