cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

Quick-add: + add another resource

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <div ng-app="app">
  
  <script type="text/ng-template" id="views/templates/switch.html">
  <div class="ly-switch ly-device">
    <input type="checkbox" id="ly-checkbox" />
    <label class="ly-slider" for="ly-checkbox" ng-click="execute(status.function)"></label>
    <div class="ly-spinner ly-animation" ng-if="device.pending">
      <div class="ly-bounce-1"></div>
      <div class="ly-bounce-2"></div>
      <div class="ly-bounce-3"></div>
    </div>
  </div>
  </script>

  <device device-id="1" device-template="views/templates/switch.html"></device>

</div>
            
          
!
            
              /*
 * Device component reset
 */

.ly-switch * {
  font-size: 1em;
  font-family: "Lato", "Helvetica Neue", sans-serif;
  background: none repeat scroll 0 0 transparent;
  border: medium none;
  border-spacing: 0;
  font-size: 1em;
  font-weight: 100;
  list-style: none outside none;
  margin: 0;
  padding: 0;
  text-align: left;
  text-decoration: none;
  text-indent: 0;
  line-height: 1.2em;
}

.ly-switch .fa {
  font-family: FontAwesome;
}


/*
 * Device generics
 */

.ly-switch {
  font-family: "Lato", "Helvetica Neue", sans-serif;
  background-color: #fff;
  color: #333;
  position: relative;
}

/*
 * Device spinner
 */

.ly-switch .ly-spinner > div {
  width: .5em;
  height: .5em;
  background-color: #bbb;
  border-radius: 100%;
  display: inline-block;

  -webkit-animation: bouncedelay 1.4s infinite ease-in-out;
  animation: bouncedelay 1.4s infinite ease-in-out;
  -webkit-animation-fill-mode: both;
  animation-fill-mode: both;
}

.ly-switch .ly-spinner .ly-bounce-1 {
  -webkit-animation-delay: -0.32s;
  animation-delay: -0.32s;
}

.ly-switch .ly-spinner .ly-bounce-2 {
  -webkit-animation-delay: -0.16s;
  animation-delay: -0.16s;
}

@-webkit-keyframes bouncedelay {
  0%, 80%, 100% { -webkit-transform: scale(0.0) }
  40% { -webkit-transform: scale(1.0) }
}

@keyframes bouncedelay {
  0%, 80%, 100% {
    transform: scale(0.0);
    -webkit-transform: scale(0.0);
  } 40% {
    transform: scale(1.0);
    -webkit-transform: scale(1.0);
  }
}

.ly-switch {
  height: 60px;
  margin-left: 120px;
  margin-top: 30px;
}

.ly-switch input {
position: absolute;
left: -9999px;
}

.ly-switch input:checked + .ly-slider::before {
box-shadow: 0 0.08em 0.15em -0.1em rgba(0, 0, 0, 0.5) inset, 0 0.05em 0.08em -0.01em rgba(255, 255, 255, 0.7), 3em 0 0 0 #239cbb inset;
}

.ly-switch input:checked + .ly-slider::after {
left: 3em;
}

.ly-switch .ly-slider {
position: relative;
display: block;
width: 5.5em;
height: 3em;
cursor: pointer;
border-radius: 1.5em;
transition: 350ms;
background: linear-gradient(rgba(0, 0, 0, 0.07), rgba(255, 255, 255, 0)), #dddddd;
box-shadow: 0 0.07em 0.1em -0.1em rgba(0, 0, 0, 0.4) inset, 0 0.05em 0.08em -0.01em rgba(255, 255, 255, 0.7);
}

.ly-switch .ly-slider::after {
position: absolute;
content: '';
width: 2em;
height: 2em;
top: 0.5em;
left: 0.5em;
border-radius: 50%;
transition: 250ms ease-in-out;
background: linear-gradient(#f5f5f5 10%, #eeeeee);
box-shadow: 0 0.1em 0.15em -0.05em rgba(255, 255, 255, 0.9) inset, 0 0.2em 0.2em -0.12em rgba(0, 0, 0, 0.5);
}

.ly-switch .ly-slider::before {
position: absolute;
content: '';
width: 4em;
height: 1.5em;
top: 0.75em;
left: 0.75em;
border-radius: 0.75em;
transition: 250ms ease-in-out;
background: linear-gradient(rgba(0, 0, 0, 0.07), rgba(255, 255, 255, 0.1)), #d0d0d0;
box-shadow: 0 0.08em 0.15em -0.1em rgba(0, 0, 0, 0.5) inset, 0 0.05em 0.08em -0.01em rgba(255, 255, 255, 0.7), 0 0 0 0 #239cbb inset;
}

.ly-switch .ly-spinner {
padding-left: 1.5em;
}

.ly-switch .ly-spinner > div {
background-color: #ccc;
}

            
          
!
            
              var app = angular.module('app', ['lelylan.directives.device', 'ngMockE2E']);

// mock all requests we need
app.run(function($httpBackend, $timeout, Profile) {
  Profile.set({id: '1'});

  device = {
  "id": "1",
  "uri": "http://www.example.com/devices/1",
  "name": "Closet dimmer",
  "categories": ["lights"],
  "pending": false,
  "activated": true,
  "type": {
    "id": "1",
    "uri": "https://type.lelylan.com/types/dimmer"
  },
  "properties": [{
    "id": "1",
    "uri": "https://type.lelylan.com/properties/status",
    "value": "off",
    "expected": "off",
    "pending": false,
    "accepted": null
  }, {
    "id": "2",
    "uri": "https://type.lelylan.com/properties/intensity",
    "expected": "0",
    "value": "0",
    "pending": false,
    "accepted": null
  }],
  "physical": {
    "uri": "https://node.lelylan.com/mqtt/devices/1"
  },
  "maker": {
    "id": "1",
    "uri": "http://api.lelylan.com/people/1"
  },
  "owner": {
    "id": "2",
    "uri": "http://api.lelylan.com/people/2"
  },
  "created_at": "2011-06-20T15:54:42Z",
  "updated_at": "2011-04-23T15:55:31Z",
  "updated_from": "you"
  }
  
  type = {
    "id": "1",
    "uri": "http://www.example.com/types/50042612d033a9b4ac0007fa",
    "name": "Dimmer",
    "description": "Dimmer description",
    "categories": ["lights"],
    "owner": {
      "id": "1",
      "uri": "http://api.lelylan.com/people/1"
    },
    "created_at": "2012-07-16T14:32:50Z",
    "updated_at": "2012-07-16T14:32:50Z",
    "properties": [{
      "id": "1",
      "uri": "http://www.example.com/properties/status",
      "name": "Status",
      "type": "text",
      "default": "0",
      "accepted": { "on": "On", "off": "Off" },
      "created_at": "2012-07-16T14:32:50Z",
      "updated_at": "2012-07-16T14:32:50Z"
    },
    {
      "uri": "http://www.example.com/properties/intensity",
      "id": "2",
      "name": "Intensity",
      "type": "range",
      "range": { "min": "0", "max": "100", "step": "1" },
      "default": "0",
      "created_at": "2012-07-16T14:32:50Z",
      "updated_at": "2012-07-16T14:32:50Z"
    }],
    "functions": [{
        "uri": "http://www.example.com/functions/50042612d033a9b4ac0007f0",
        "id": "1",
        "name": "Turn on",
        "created_at": "2012-07-16T14:32:50Z",
        "updated_at": "2012-07-16T14:32:50Z",
        "properties": [{
          "id": "1",
          "uri": "http://www.example.com/properties/status",
          "expected": "on"
        }]
    },
    {
        "uri": "http://www.example.com/functions/50042612d033a9b4ac0007f2",
        "id": "2",
        "name": "Turn off",
        "created_at": "2012-07-16T14:32:50Z",
        "updated_at": "2012-07-16T14:32:50Z",
        "properties": [{
          "id": "1",
          "uri": "http://www.example.com/properties/status",
          "expected": "off"
        }]
    },
    {
        "uri": "http://www.example.com/functions/50042612d033a9b4ac0007f5",
        "id": "3",
        "name": "Set intensity",
        "created_at": "2012-07-16T14:32:50Z",
        "updated_at": "2012-07-16T14:32:50Z",
        "properties": [{
          "id": "1",
          "uri": "http://www.example.com/properties/status",
          "expected": "on"
        },
        {
          "id": "2",
          "uri": "http://www.example.com/properties/intensity",
          "expected": null
        }]
    }],
    "statuses": [{
        "uri": "http://www.example.com/statuses/50042612d033a9b4ac0007f8",
        "id": "50042612d033a9b4ac0007f8",
        "name": "On",
        "created_at": "2012-07-16T14:32:50Z",
        "updated_at": "2012-07-16T14:32:50Z",
        "function": {
          "id": "2",
          "uri": "http://www.example.com/functions/turn-off"
        },
        "properties": [{
          "id": "1",
          "uri": "http://www.example.com/properties/status",
          "pending": false,
          "values": ["on"],
          "ranges": []
        }]
      }, {
        "uri": "http://www.example.com/statuses/50042612d033a9b4ac0007f8",
        "id": "50042612d033a9b4ac0007f8",
        "name": "Off",
        "created_at": "2012-07-16T14:32:50Z",
        "updated_at": "2012-07-16T14:32:50Z",
        "function": {
          "id": "1",
          "uri": "http://www.example.com/functions/turn-on"
        },
        "properties": [{
          "id": "1",
          "uri": "http://www.example.com/properties/status",
          "pending": false,
          "values": ["off"],
          "ranges": []
        }]
    }]
  };
  
  privates = {
    "uri": "http://api.lelylan.com/devices/5042344b95fc441000000001",
    "id": "1",
    "name": "Closet dimmer",
    "secret": "secret",
    "activation_code": "activation_code"
  }

  $httpBackend.when('GET', /\/templates\//).passThrough();

  $httpBackend.whenGET('http://api.lelylan.com/devices/1').respond(device);
  $httpBackend.whenPUT('http://api.lelylan.com/devices/1')
    .respond(function(method, url, data, headers) { return [200, updateDevice(data), {}]; });
  $httpBackend.whenPUT('http://api.lelylan.com/devices/1/properties')
    .respond(function(method, url, data, headers) { return [200,  updateDeviceProperties(data), {}]; });
  $httpBackend.whenDELETE('http://api.lelylan.com/devices/1').respond(device);
  $httpBackend.whenGET('http://api.lelylan.com/types/1').respond(type);
  $httpBackend.whenGET('http://api.lelylan.com/devices/1/privates').respond(privates);

  var updateDevice = function(data) {
    data = angular.fromJson(data);
    device.updated_at   = new Date();
    device.name         = data.name;
    device.physical.uri = data.physical.uri;
    return device;
  }

  var updateDeviceProperties = function(data) {
    data = angular.fromJson(data);
    device.updated_at = new Date();
    _.each(data.properties, function(property) {
      var result = _.find(device.properties, function(_property) { return _property.id == property.id; } );
      result.expected = result.value = property.expected; });
    return device;
  }
});

// hack to make the anchor links work
app.run(function($rootScope, $location, $anchorScroll) {
  $rootScope.$on('$routeChangeSuccess', function(newRoute, oldRoute) { });
});

app.config(['$locationProvider', function ($locationProvider) {
  $locationProvider.html5Mode(true);
  $locationProvider.hashPrefix('!');
}]);

            
          
!
999px
Loading ..................

Console