Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(81)

Unified Diff: pkg/polymer/lib/elements/polymer-ui-toggle-button/polymer-ui-toggle-button.html

Issue 175443005: [polymer] import all elements (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: updated from bower Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/polymer/lib/elements/polymer-ui-toggle-button/polymer-ui-toggle-button.html
diff --git a/pkg/polymer/lib/elements/polymer-ui-toggle-button/polymer-ui-toggle-button.html b/pkg/polymer/lib/elements/polymer-ui-toggle-button/polymer-ui-toggle-button.html
new file mode 100644
index 0000000000000000000000000000000000000000..80e5926b7dfd05db953a33c3290acc4a6550e1cc
--- /dev/null
+++ b/pkg/polymer/lib/elements/polymer-ui-toggle-button/polymer-ui-toggle-button.html
@@ -0,0 +1,96 @@
+<!--
+Copyright 2013 The Polymer Authors. All rights reserved.
+Use of this source code is governed by a BSD-style
+license that can be found in the LICENSE file.
+-->
+<!--
+/**
+ * @module Polymer UI Elements
+ */
+/**
+ * polymer-ui-toggle-button is a button that has one of two states (ON/OFF).
+ * You can tap or drag the button to switch state.
+ *
+ * Example:
+ *
+ * <polymer-ui-toggle-button></polymer-ui-toggle-button>
+ *
+ * @class polymer-ui-toggle-button
+ */
+-->
+<link rel="import" href="../polymer/polymer.html">
+
+<polymer-element name="polymer-ui-toggle-button" attributes="value noCaption onCaption offCaption"
+ on-tap="{{toggle}}" on-trackstart="{{trackStart}}" on-track="{{track}}" on-trackend="{{trackEnd}}" on-flick="{{flick}}">
+ <template>
+ <link rel="stylesheet" href="polymer-ui-toggle-button.css" />
+ <link rel="stylesheet" href="../polymer-flex-layout/polymer-flex-layout.css" />
+ <div id="toggle" class="toggle">
+ <span class="on-label flexbox align-center justify-center">{{noCaption ? '' : onCaption}}</span>
+ <span id="thumb" class="thumb"></span>
+ <span class="off-label flexbox align-center justify-center">{{noCaption ? '' : offCaption}}</span>
+ </div>
+ </template>
+ <script>
+ Polymer('polymer-ui-toggle-button', {
+ /**
+ * Gets or sets the state, true is ON and false is OFF.
+ *
+ * @attribute value
+ * @type boolean
+ * @default false
+ */
+ value: false,
+ /**
+ * If true, don't display caption.
+ *
+ * @attribute noCaption
+ * @type boolean
+ * @default false
+ */
+ noCaption: false,
+ /**
+ * Caption for on state.
+ *
+ * @attribute onCaption
+ * @type string
+ * @default 'ON'
+ */
+ onCaption: 'ON',
+ /**
+ * Caption for off state.
+ *
+ * @attribute offCaption
+ * @type string
+ * @default 'OFF'
+ */
+ offCaption: 'OFF',
+ toggle: function() {
+ this.value = !this.value;
+ },
+ valueChanged: function() {
+ this.classList.toggle('on', this.value);
+ this.$.toggle.classList.toggle('on', this.value);
+ },
+ trackStart: function(e) {
+ e.preventTap();
+ this.w = this.$.toggle.offsetWidth - this.clientWidth;
+ this.$.toggle.classList.add('dragging');
+ },
+ track: function(e) {
+ this.x = Math.max(-this.w, Math.min(0, this.value ? e.dx : e.dx - this.w));
+ this.$.toggle.style.left = this.x + 'px';
+ },
+ trackEnd: function() {
+ this.$.toggle.style.left = null;
+ this.$.toggle.classList.remove('dragging');
+ this.value = Math.abs(this.x) < this.w / 2;
+ Platform.flush();
+ },
+ flick: function(e) {
+ this.value = e.xVelocity > 0;
+ Platform.flush();
+ }
+ });
+ </script>
+</polymer-element>

Powered by Google App Engine
This is Rietveld 408576698