TokiCLI 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. checksums.yaml +4 -4
  2. data/.coveralls.yml +1 -0
  3. data/.gitignore +9 -17
  4. data/.rspec +3 -0
  5. data/.travis.yml +3 -0
  6. data/CHANGELOG.md +4 -0
  7. data/README.md +99 -163
  8. data/Rakefile +5 -0
  9. data/TokiCLI.gemspec +5 -4
  10. data/bin/toki +2 -2
  11. data/lib/API/helpers.rb +27 -170
  12. data/lib/API/toki_api.rb +227 -0
  13. data/lib/API/toki_db.rb +67 -0
  14. data/lib/TokiCLI.rb +270 -5
  15. data/lib/TokiCLI/adnimport.rb +202 -0
  16. data/lib/TokiCLI/fileops.rb +187 -0
  17. data/lib/TokiCLI/status.rb +49 -37
  18. data/lib/TokiCLI/version.rb +1 -1
  19. data/lib/TokiCLI/view.rb +133 -86
  20. data/lib/TokiServer/.bowerrc +3 -0
  21. data/lib/TokiServer/.gitignore +2 -0
  22. data/lib/TokiServer/Gemfile +1 -0
  23. data/lib/TokiServer/bower.json +0 -0
  24. data/lib/TokiServer/bower_components/fastclick/.bower.json +4 -4
  25. data/lib/TokiServer/bower_components/fastclick/bower.json +1 -1
  26. data/lib/TokiServer/bower_components/fastclick/lib/fastclick.js +33 -2
  27. data/lib/TokiServer/bower_components/foundation/.bower.json +5 -4
  28. data/lib/TokiServer/bower_components/foundation/bower.json +2 -1
  29. data/lib/TokiServer/bower_components/foundation/css/foundation.css +2173 -922
  30. data/lib/TokiServer/bower_components/foundation/css/foundation.css.map +7 -0
  31. data/lib/TokiServer/bower_components/foundation/css/normalize.css +53 -16
  32. data/lib/TokiServer/bower_components/foundation/css/normalize.css.map +7 -0
  33. data/lib/TokiServer/bower_components/foundation/js/foundation.js +782 -542
  34. data/lib/TokiServer/bower_components/foundation/js/foundation.min.js +4 -3
  35. data/lib/TokiServer/bower_components/foundation/js/foundation/foundation.abide.js +45 -31
  36. data/lib/TokiServer/bower_components/foundation/js/foundation/foundation.accordion.js +12 -6
  37. data/lib/TokiServer/bower_components/foundation/js/foundation/foundation.alert.js +5 -5
  38. data/lib/TokiServer/bower_components/foundation/js/foundation/foundation.clearing.js +34 -10
  39. data/lib/TokiServer/bower_components/foundation/js/foundation/foundation.dropdown.js +83 -29
  40. data/lib/TokiServer/bower_components/foundation/js/foundation/foundation.equalizer.js +3 -3
  41. data/lib/TokiServer/bower_components/foundation/js/foundation/foundation.interchange.js +25 -12
  42. data/lib/TokiServer/bower_components/foundation/js/foundation/foundation.joyride.js +112 -40
  43. data/lib/TokiServer/bower_components/foundation/js/foundation/foundation.js +19 -5
  44. data/lib/TokiServer/bower_components/foundation/js/foundation/foundation.magellan.js +22 -11
  45. data/lib/TokiServer/bower_components/foundation/js/foundation/foundation.offcanvas.js +52 -8
  46. data/lib/TokiServer/bower_components/foundation/js/foundation/foundation.orbit.js +133 -271
  47. data/lib/TokiServer/bower_components/foundation/js/foundation/foundation.reveal.js +27 -20
  48. data/lib/TokiServer/bower_components/foundation/js/foundation/foundation.slider.js +73 -33
  49. data/lib/TokiServer/bower_components/foundation/js/foundation/foundation.tab.js +88 -31
  50. data/lib/TokiServer/bower_components/foundation/js/foundation/foundation.tooltip.js +7 -5
  51. data/lib/TokiServer/bower_components/foundation/js/foundation/foundation.topbar.js +44 -24
  52. data/lib/TokiServer/bower_components/foundation/js/vendor/fastclick.js +2 -2
  53. data/lib/TokiServer/bower_components/foundation/js/vendor/modernizr.js +2 -2
  54. data/lib/TokiServer/bower_components/foundation/scss/foundation.scss +38 -38
  55. data/lib/TokiServer/bower_components/foundation/scss/foundation/_functions.scss +3 -3
  56. data/lib/TokiServer/bower_components/foundation/scss/foundation/_settings.scss +417 -271
  57. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_accordion.scss +110 -6
  58. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_alert-boxes.scss +2 -2
  59. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_block-grid.scss +2 -2
  60. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_breadcrumbs.scss +8 -3
  61. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_button-groups.scss +99 -9
  62. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_buttons.scss +66 -28
  63. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_clearing.scss +5 -5
  64. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_dropdown-buttons.scss +4 -4
  65. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_dropdown.scss +48 -35
  66. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_forms.scss +104 -32
  67. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_global.scss +48 -30
  68. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_grid.scss +19 -4
  69. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_icon-bar.scss +293 -0
  70. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_joyride.scss +11 -9
  71. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_keystrokes.scss +4 -4
  72. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_labels.scss +4 -2
  73. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_magellan.scss +1 -1
  74. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_offcanvas.scss +193 -35
  75. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_orbit.scss +92 -147
  76. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_pagination.scss +22 -10
  77. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_panels.scss +10 -7
  78. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_pricing-tables.scss +11 -11
  79. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_progress-bars.scss +2 -2
  80. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_range-slider.scss +29 -9
  81. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_reveal.scss +60 -56
  82. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_side-nav.scss +3 -2
  83. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_split-buttons.scss +2 -2
  84. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_sub-nav.scss +2 -2
  85. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_switches.scss +226 -0
  86. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_tables.scss +13 -7
  87. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_tabs.scss +22 -8
  88. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_thumbs.scss +2 -4
  89. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_toolbar.scss +70 -0
  90. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_tooltips.scss +9 -7
  91. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_top-bar.scss +77 -44
  92. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_type.scss +21 -9
  93. data/lib/TokiServer/bower_components/modernizr/.bower.json +4 -4
  94. data/lib/TokiServer/bower_components/modernizr/feature-detects/workers-blobworkers.js +2 -2
  95. data/lib/TokiServer/bower_components/modernizr/grunt.js +1 -1
  96. data/lib/TokiServer/bower_components/modernizr/modernizr.js +2 -2
  97. data/lib/TokiServer/config.rb +0 -0
  98. data/lib/TokiServer/humans.txt +0 -0
  99. data/lib/TokiServer/{itunesicon.rb → itunesicons.rb} +25 -23
  100. data/lib/TokiServer/js/app.js +0 -0
  101. data/lib/TokiServer/public/stylesheets/app.css +2636 -1610
  102. data/lib/TokiServer/robots.txt +0 -0
  103. data/lib/TokiServer/scss/_settings.scss +0 -0
  104. data/lib/TokiServer/scss/app.scss +7 -1
  105. data/lib/TokiServer/tokiserver.rb +239 -244
  106. data/lib/TokiServer/views/activity.erb +42 -0
  107. data/lib/TokiServer/views/apps_total.erb +8 -2
  108. data/lib/TokiServer/views/error.erb +13 -4
  109. data/lib/TokiServer/views/index.erb +36 -27
  110. data/lib/TokiServer/views/logs_total.erb +34 -0
  111. data/spec/TokiCLI_spec.rb +354 -0
  112. data/spec/mock/mock.sqlite3 +0 -0
  113. data/spec/spec_helper.rb +26 -0
  114. metadata +78 -23
  115. data/lib/API/dbapi.rb +0 -488
  116. data/lib/TokiCLI/app.rb +0 -389
  117. data/lib/TokiCLI/authorize.rb +0 -77
  118. data/lib/TokiCLI/export.rb +0 -81
  119. data/lib/TokiCLI/get_channels.rb +0 -22
  120. data/lib/TokiCLI/get_messages.rb +0 -32
  121. data/lib/TokiCLI/import.rb +0 -122
  122. data/lib/TokiCLI/scan.rb +0 -19
  123. data/lib/TokiCLI/search_messages.rb +0 -23
  124. data/lib/TokiServer/README.md +0 -37
  125. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_reveal-new.scss +0 -0
  126. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_switch.scss +0 -294
  127. data/lib/TokiServer/views/name_log.erb +0 -50
  128. data/lib/TokiServer/views/name_split.erb +0 -37
  129. data/lib/TokiServer/views/name_total.erb +0 -34
@@ -1,81 +0,0 @@
1
- # encoding: utf-8
2
- module TokiCLI
3
- class Export
4
-
5
- def initialize toki, view
6
- @toki = toki
7
- @view = view
8
- end
9
-
10
- def apps_total options, apps, type
11
- arr = []
12
- apps['data']['apps'].each do |obj|
13
- arr << {
14
- bundle: obj['bundle'],
15
- name: obj['name'],
16
- total: {
17
- seconds: obj['total']['seconds'],
18
- time: @view.readable_time(obj['total']['time'])
19
- }
20
- }
21
- end
22
- save options, arr, "toki-#{type}__#{Time.now.to_s[0..9]}"
23
- end
24
-
25
- def log options, log, type
26
- arr = []
27
- temp = log['data']['log'].map do |obj|
28
- [obj[1]['start'], obj[1]['duration']['seconds'], @view.readable_time(obj[1]['duration']['time']), obj[0]]
29
- end
30
- temp.sort_by! {|obj| obj[0]}
31
- temp.each do |obj|
32
- arr << {
33
- start: obj[0],
34
- duration: {
35
- seconds: obj[1],
36
- time: obj[2]
37
- },
38
- sync_id: obj[3]
39
- }
40
- end
41
- save_log options, arr, "toki-#{type}__#{Time.now.to_s[0..9]}"
42
- end
43
-
44
- private
45
-
46
- def save options, data, filename
47
- case
48
- when options[:json]
49
- name = @toki.helpers.toki_path + "/#{filename}.json"
50
- File.write(name, data.to_json)
51
- when options[:csv]
52
- name = @toki.helpers.toki_path + "/#{filename}.csv"
53
- CSV.open(name, "wb") do |csv|
54
- csv << ['Bundle Identifier', 'Name', 'Total seconds', 'Total time']
55
- data.each {|line| csv << [line[:bundle], line[:name], line[:total][:seconds], line[:total][:time]]}
56
- end
57
- else
58
- exit
59
- end
60
- puts "File converted and exported to #{name}\n\n"
61
- end
62
-
63
- def save_log options, data, filename
64
- case
65
- when options[:json]
66
- name = @toki.helpers.toki_path + "/#{filename}.json"
67
- File.write(name, data.to_json)
68
- when options[:csv]
69
- name = @toki.helpers.toki_path + "/#{filename}.csv"
70
- CSV.open(name, "wb") do |csv|
71
- csv << ['Start', 'Duration (seconds)', 'Duration (time)', 'Sync ID']
72
- data.each {|line| csv << [line[:start], line[:duration][:seconds], line[:duration][:time], line[:sync_id]]}
73
- end
74
- else
75
- exit
76
- end
77
- puts "File converted and exported to #{name}\n\n"
78
- end
79
-
80
- end
81
- end
@@ -1,22 +0,0 @@
1
- require 'json'
2
- require 'rest_client'
3
- module ADNChannels
4
- class GetChannels
5
- def initialize(token)
6
- @base_url = 'http://api.app.net'
7
- @token = token
8
- end
9
- def get_channels
10
- args = {:count => 200, :before_id => nil}
11
- channels = []
12
- loop do
13
- @url = "#{@base_url}/users/me/channels?access_token=#{@token}&include_machine=1&include_message_annotations=1&include_deleted=0&include_html=0&count=#{args[:count]}&before_id=#{args[:before_id]}"
14
- resp = JSON.parse(RestClient.get(@url))
15
- resp['data'].each { |m| channels << m }
16
- break unless resp['meta']['more']
17
- args = {:count => 200, :before_id => resp['meta']['min_id']}
18
- end
19
- channels
20
- end
21
- end
22
- end
@@ -1,32 +0,0 @@
1
- require 'json'
2
- require 'rest_client'
3
- module ADNChannels
4
- class GetMessages
5
- def initialize(token)
6
- @base_url = 'http://api.app.net'
7
- @token = token
8
- end
9
- def get_messages(channel_id)
10
- args = {:count => 200, :before_id => nil}
11
- messages = []
12
- @index = 1
13
- puts "Downloading synced objects (200/page):\n\n"
14
- loop do
15
- puts "--Downloading from page #{@index}...\n"
16
- @url = "#{@base_url}/channels/#{channel_id}/messages?access_token=#{@token}&include_machine=1&include_message_annotations=1&include_deleted=0&include_html=0&count=#{args[:count]}&before_id=#{args[:before_id]}"
17
- begin
18
- data = RestClient.get(@url)
19
- rescue Interrupt
20
- puts TokiCLI::Status.canceled
21
- exit
22
- end
23
- resp = JSON.parse(data)
24
- resp['data'].each { |m| messages << m }
25
- break unless resp['meta']['more']
26
- @index += 1
27
- args = {:count => 200, :before_id => resp['meta']['min_id']}
28
- end
29
- messages
30
- end
31
- end
32
- end
@@ -1,122 +0,0 @@
1
- # encoding: utf-8
2
- module TokiCLI
3
- class Import
4
-
5
- def initialize toki, view
6
- @toki_api = toki
7
- @view = view
8
- end
9
-
10
- def restore token, channel_id
11
- please_quit
12
- backup_db
13
- adn_data = get_adn_data token, channel_id
14
- db = create_db
15
- create_table db
16
- lines = decode adn_data
17
- populate db, lines
18
- replace
19
- end
20
-
21
-
22
- def replace
23
- if File.exist? @toki_api.helpers.db_path
24
- puts "\nAre you sure you want to replace the current Toki.app database?\n\nHit SPACE to continue (any other key to cancel).\n\n"
25
- abort("Canceled.\n\n") unless STDIN.getch == ' '
26
- FileUtils.mv @toki_api.helpers.db_path, "#{Dir.home}/.Trash/"
27
- end
28
- FileUtils.mv @new_db_path, @toki_api.helpers.db_path
29
- puts "\n\nDone. You may relaunch Toki.app now.\n\n"
30
- end
31
-
32
- def populate db, lines
33
- puts "Populating new database with App.net data...\n\n"
34
- before = Time.now
35
- idx = 0
36
- db.transaction do |db_in_transaction|
37
- lines.each do |obj|
38
- insert_data = {}
39
- insert_data[':id'] = obj[:id]
40
- insert_data[':bundleIdentifier'] = obj[:bundleIdentifier]
41
- insert_data[':activeTo'] = obj[:activeTo]
42
- insert_data[':activeFrom'] = obj[:activeFrom]
43
- insert_data[':totalSeconds'] = obj[:totalSeconds]
44
- insert_data[':UUID'] = obj[:uuid]
45
- insert_data[':synced'] = 1
46
- insert_data[':availableToSync'] = 1
47
-
48
- db_in_transaction.prepare("INSERT INTO plain(id, bundleIdentifier, activeTo, activeFrom, totalSeconds, UUID, synced, availableToSync) VALUES(:id, :bundleIdentifier, :activeTo, :activeFrom, :totalSeconds, :UUID, :synced, :availableToSync);") do |insert|
49
- insert.execute insert_data
50
- end
51
-
52
- idx += 1
53
- print "Processed #{idx} of #{lines.size}\r"
54
- $stdout.flush
55
- end
56
- end
57
- puts "\n\n\nFinished inserting #{idx} lines in #{Time.now - before}.\n\n"
58
- end
59
-
60
- def decode adn_data
61
- puts "Decoding App.net data...\n\n"
62
- lines = []
63
- adn_data.each do |obj|
64
- adn = obj['annotations'][0]
65
- lines <<
66
- {
67
- type: adn['type'],
68
- table: adn['value']['c'],
69
- uuid: adn['value']['d']['UUID'],
70
- bundleIdentifier: adn['value']['d']['bundleIdentifier'],
71
- activeTo: adn['value']['d']['activeTo'],
72
- activeFrom: adn['value']['d']['activeFrom'],
73
- totalSeconds: adn['value']['d']['totalSeconds'],
74
- id: adn['value']['d']['id']
75
- }
76
- end
77
- lines
78
- end
79
-
80
- def create_table db
81
- puts "Creating table...\n\n"
82
- db.execute_batch <<-SQL
83
- CREATE TABLE KKAppActivity (
84
- id INTEGER,
85
- bundleIdentifier VARCHAR(256),
86
- activeTo INTEGER,
87
- activeFrom INTEGER,
88
- totalSeconds INTEGER,
89
- UUID VARCHAR(256),
90
- synced INTEGER,
91
- availableToSync INTEGER
92
- );
93
- SQL
94
- db.reload_schema!
95
- end
96
-
97
- def create_db
98
- puts "\n\nCreating a new SQLite3 database...\n\n"
99
- @new_db_path = "#{@toki_api.helpers.toki_path}/db_from_adn.sqlite3"
100
- Amalgalite::Database.new @new_db_path
101
- end
102
-
103
- def get_adn_data token, channel_id
104
- puts "Connecting to App.net...\n\n"
105
- channels = ADNChannels::GetMessages.new(token)
106
- channels.get_messages(channel_id)
107
- end
108
-
109
- def backup_db
110
- if File.exist? @toki_api.helpers.db_path
111
- FileUtils.copy(@toki_api.helpers.db_path, "#{@toki_api.helpers.toki_path}/toki_data.sqlite3.bak")
112
- puts "Current database has been backed up in #{@toki_api.helpers.toki_path}\n\n"
113
- end
114
- end
115
-
116
- def please_quit
117
- puts "\n\nYou need to quit Toki.app before restoring data from App.net.\n\nPlease quit Toki.app then hit SPACE to continue (any other key to cancel).\n\n"
118
- abort("Canceled.\n\n") unless STDIN.getch == ' '
119
- end
120
-
121
- end
122
- end
@@ -1,19 +0,0 @@
1
- # encoding: utf-8
2
- module TokiCLI
3
- class Scan
4
-
5
- def initialize toki
6
- @toki_api = toki
7
- end
8
-
9
- def scan params
10
- bundles = @toki_api.helpers.scan params
11
- if bundles.empty? || bundles.nil?
12
- puts "\nError.\n\n"
13
- else
14
- puts "\nDone.\n\n"
15
- end
16
- end
17
-
18
- end
19
- end
@@ -1,23 +0,0 @@
1
- require 'json'
2
- require 'rest_client'
3
- module ADNChannels
4
- class SearchMessages
5
- def initialize(token)
6
- @base_url = 'http://api.app.net'
7
- @token = token
8
- end
9
- def search_annotation(channel_id, query)
10
- args = {:count => 200, :before_id => nil}
11
- messages = []
12
- loop do
13
- @url = "#{@base_url}/channels/messages/search?query=#{query}&channel_ids=#{channel_id}&access_token=#{@token}&include_machine=1&include_message_annotations=1&include_deleted=0&count=#{args[:count]}&before_id=#{args[:before_id]}"
14
- resp = JSON.parse(RestClient.get(@url))
15
- resp['data'].each { |m| messages << m }
16
- break unless resp['meta']['more']
17
- args = {:count => 200, :before_id => resp['meta']['min_id']}
18
- end
19
- messages
20
- end
21
- end
22
- end
23
-
@@ -1,37 +0,0 @@
1
- # Foundation Compass Template
2
-
3
- The easiest way to get started with Foundation + Compass.
4
-
5
- ## Requirements
6
-
7
- * Ruby 1.9+
8
- * [Node.js](http://nodejs.org)
9
- * [compass](http://compass-style.org/): `gem install compass`
10
- * [bower](http://bower.io): `npm install bower -g`
11
-
12
- ## Quickstart
13
-
14
- * [Download this starter compass project and unzip it](https://github.com/zurb/foundation-compass-template/archive/master.zip)
15
- * Run `bower install` to install the latest version of Foundation
16
-
17
- Then when you're working on your project, just run the following command:
18
-
19
- ```bash
20
- compass watch
21
- ```
22
-
23
- ## Upgrading
24
-
25
- If you'd like to upgrade to a newer version of Foundation down the road just run:
26
-
27
- ```bash
28
- bower update
29
- ```
30
-
31
-
32
- ## Starting the app
33
-
34
- Run `bundle install`
35
- Run `ruby app.rb`
36
-
37
- Visit `http://localhost:4567/`
@@ -1,294 +0,0 @@
1
- // Foundation by ZURB
2
- // foundation.zurb.com
3
- // Licensed under MIT Open Source
4
-
5
- @import "global";
6
-
7
- //
8
- // @name
9
- // @dependencies _global.scss
10
- //
11
-
12
- //
13
- // @variables
14
- //
15
-
16
- // NOTE: Switches have been deprecated in Foundation 5 and will be removed in the future.
17
-
18
- $include-html-form-classes: $include-html-classes !default;
19
-
20
- // Controlling border styles and background colors for the switch container
21
- $switch-border-color: scale-color(#fff, $lightness: -20%) !default;
22
- $switch-border-style: solid !default;
23
- $switch-border-width: 1px !default;
24
- $switch-bg: #fff !default;
25
-
26
- // We use these to control the switch heights for our default classes
27
- $switch-height-tny: 22px !default;
28
- $switch-height-sml: 28px !default;
29
- $switch-height-med: 36px !default;
30
- $switch-height-lrg: 44px !default;
31
- $switch-bottom-margin: rem-calc(20) !default;
32
-
33
- // We use these to control default font sizes for our classes.
34
- $switch-font-size-tny: 11px !default;
35
- $switch-font-size-sml: 12px !default;
36
- $switch-font-size-med: 14px !default;
37
- $switch-font-size-lrg: 17px !default;
38
- $switch-label-side-padding: 6px !default;
39
-
40
- // We use these to style the switch-paddle
41
- $switch-paddle-bg: #fff !default;
42
- $switch-paddle-fade-to-color: scale-color($switch-paddle-bg, $lightness: -10%) !default;
43
- $switch-paddle-border-color: scale-color($switch-paddle-bg, $lightness: -35%) !default;
44
- $switch-paddle-border-width: 1px !default;
45
- $switch-paddle-border-style: solid !default;
46
- $switch-paddle-transition-speed: .1s !default;
47
- $switch-paddle-transition-ease: ease-out !default;
48
- $switch-positive-color: scale-color($success-color, $lightness: 94%) !default;
49
- $switch-negative-color: #f5f5f5 !default;
50
-
51
- // Outline Style for tabbing through switches
52
- $switch-label-outline: 1px dotted #888 !default;
53
-
54
-
55
- //
56
- // @mixins
57
- //
58
-
59
- // We use this mixin to create the base styles for our switch element.
60
- //
61
- // $transition-speed - Time in ms for switch to toggle. Default: $switch-paddle-transition-speed.
62
- // $transition-ease - Easing function to use for animation (i.e. ease-out). Default: $switch-paddle-transition-ease.
63
- @mixin switch-base(
64
- $transition-speed:$switch-paddle-transition-speed,
65
- $transition-ease:$switch-paddle-transition-ease) {
66
-
67
- // Default position and structure for switch container.
68
- position: relative;
69
- padding: 0;
70
- display: block;
71
- overflow: hidden;
72
- border-style: $switch-border-style;
73
- border-width: $switch-border-width;
74
- margin-bottom: $switch-bottom-margin;
75
-
76
- // Default label styles for type and transition
77
- label {
78
- position: relative;
79
- #{$default-float}: 0;
80
- z-index: 2;
81
- float: $default-float;
82
- width: 50%;
83
- height: 100%;
84
- margin: 0;
85
- font-weight: $font-weight-bold;
86
- text-align: $default-float;
87
-
88
- // Transition for the switch label to follow paddle
89
- @include single-transition(all, $transition-speed, $transition-ease);
90
- }
91
-
92
- // So that we don't need to recreate the form with any JS, we use the
93
- // existing radio button, but we cleverly position and hide it.
94
- input {
95
- position: absolute;
96
- z-index: 3;
97
- opacity: 0;
98
- width: 100%;
99
- height: 100%;
100
- -moz-appearance: none;
101
-
102
- // Hover and focus styles for the paddle
103
- &:hover,
104
- &:focus {
105
- cursor: $cursor-pointer-value;
106
- }
107
- }
108
-
109
- // The toggle area for radio switches. We call is a paddle.
110
- span:last-child {
111
- position: absolute;
112
- top: -1px;
113
- #{$default-float}: -1px;
114
- z-index: 1;
115
- display: block;
116
- padding: 0;
117
- border-width: $switch-paddle-border-width;
118
- border-style: $switch-paddle-border-style;
119
-
120
- // Transition for the switch paddle
121
- @include single-transition(all, $transition-speed, $transition-ease);
122
- }
123
-
124
- // When a label isn't :checked, we hide it as it slides away.
125
- input:not(:checked) + label { opacity: 0; }
126
-
127
- // Controlling the position of the labels as they are toggled.
128
- input:checked { display: none !important; }
129
- input { #{$default-float}: 0; display: block !important; }
130
-
131
- // Left Label alignment and position changes, including fixes for while inside a custom form
132
- input:first-of-type + label,
133
- input:first-of-type + span + label { #{$default-float}: -50%; }
134
- input:first-of-type:checked + label,
135
- input:first-of-type:checked + span + label { #{$default-float}: 0%; }
136
-
137
- // Right Label alignment and position changes, including fixes for while inside a custom form
138
- input:last-of-type + label,
139
- input:last-of-type + span + label {#{$opposite-direction}: -50%; #{$default-float}: auto; text-align: $opposite-direction; }
140
- input:last-of-type:checked + label,
141
- input:last-of-type:checked + span + label { #{$opposite-direction}: 0%; #{$default-float}: auto; }
142
-
143
- // Hiding custom form spans since we auto-create them
144
- span.custom { display: none !important; }
145
-
146
- form.custom & .hidden-field {
147
- margin-left: auto;
148
- position: absolute;
149
- visibility: visible;
150
- }
151
- }
152
-
153
- // We use this mixin to create the size styles for switches.
154
- //
155
- // $height - Height (in px) of the switch. Default: $switch-height-med.
156
- // $font-size - Font size of text in switch. Default: $switch-font-size-med.
157
- // $line-height - Line height of switch. Default: 2.3rem.
158
- @mixin switch-size(
159
- $height: $switch-height-med,
160
- $font-size: $switch-font-size-med,
161
- $line-height: 2.3rem) {
162
-
163
- height: rem-calc($height);
164
-
165
- label {
166
- padding: rem-calc(0, $switch-label-side-padding);
167
- line-height: $line-height;
168
- font-size: rem-calc($font-size);
169
- }
170
-
171
- input {
172
- // Move the paddle to the right position
173
- &:first-of-type:checked ~ span:last-child {
174
- #{$default-float}: 100%;
175
- margin-#{$default-float}: rem-calc(-$height + 1px);
176
- }
177
- }
178
-
179
- span:last-child {
180
- width: rem-calc($height);
181
- height: rem-calc($height);
182
- }
183
-
184
- }
185
-
186
- // We use this mixin to add color and other fanciness to the switches.
187
- //
188
- // $paddle-bg - Background of switch paddle. Default: $switch-paddle-bg.
189
- // $positive-color - Background color of positive side of switch. Default: $switch-positive-color.
190
- // $negative-color - Background color of negative side of switch. Default: $switch-negative-color.
191
- // $radius - Radius to apply to switch. Default: false.
192
- // $base-style - Apply base styles? Default: true.
193
- @mixin switch-style(
194
- $paddle-bg:$switch-paddle-bg,
195
- $positive-color:$switch-positive-color,
196
- $negative-color:$switch-negative-color,
197
- $radius:false,
198
- $base-style:true) {
199
-
200
- @if $base-style {
201
- background: $switch-bg;
202
- border-color: $switch-border-color;
203
-
204
- span:last-child {
205
- border-color: scale-color($paddle-bg, $lightness: -30%);
206
- background: $paddle-bg;
207
- background: linear-gradient(to bottom, $paddle-bg 0%, scale-color($paddle-bg, $lightness: -5%) 100%);
208
-
209
- // Building the alternating colored sides of the switch
210
- box-shadow: 2px 0 10px 0 rgba(0,0,0,0.07),
211
- 1000px 0 0 980px $positive-color,
212
- -2px 0 10px 0 rgba(0,0,0,0.07),
213
- -1000px 0 0 1000px $negative-color;
214
- }
215
-
216
- &:hover,
217
- &:focus {
218
- span:last-child {
219
- background: $paddle-bg;
220
- background: linear-gradient(to bottom, $paddle-bg 0%, scale-color($paddle-bg, $lightness: -10%) 100%);
221
- }
222
- }
223
-
224
- &:active { background: transparent; }
225
- }
226
-
227
- // Setting up the radius for switches
228
- @if $radius == true {
229
- @include radius(4px);
230
- span:last-child { @include radius(3px); }
231
- }
232
- @else if $radius {
233
- @include radius($radius);
234
- span:last-child { @include radius($radius - 1px); }
235
- }
236
-
237
- }
238
-
239
- // We use this to quickly create switches with a single mixin
240
- //
241
- // $transition-speed - Time in ms for switch to toggle. Default: $switch-paddle-transition-speed.
242
- // $transition-ease - Easing function to use for animation (i.e. ease-out). Default: $switch-paddle-transition-ease.
243
- // $height - Height (in px) of the switch. Default: $switch-height-med.
244
- // $font-size - Font size of text in switch. Default: $switch-font-size-med.
245
- // $line-height - Line height of switch. Default: 2.3rem.
246
- // $paddle-bg - Background of switch paddle. Default: $switch-paddle-bg.
247
- // $positive-color - Background color of positive side of switch. Default: $switch-positive-color.
248
- // $negative-color - Background color of negative side of switch. Default: $switch-negative-color.
249
- // $radius - Radius to apply to switch. Default: false.
250
- // $base-style - Apply base styles? Default: true.
251
- @mixin switch(
252
- $transition-speed: $switch-paddle-transition-speed,
253
- $transition-ease: $switch-paddle-transition-ease,
254
- $height: $switch-height-med,
255
- $font-size: $switch-font-size-med,
256
- $line-height: 2.3rem,
257
- $paddle-bg: $switch-paddle-bg,
258
- $positive-color: $switch-positive-color,
259
- $negative-color: $switch-negative-color,
260
- $radius:false,
261
- $base-style:true) {
262
- @include switch-base($transition-speed, $transition-ease);
263
- @include switch-size($height, $font-size, $line-height);
264
- @include switch-style($paddle-bg, $positive-color, $negative-color, $radius, $base-style);
265
- }
266
-
267
- @include exports("switch") {
268
- @if $include-html-form-classes {
269
- div.switch {
270
- @include switch;
271
-
272
- // Large radio switches
273
- &.large { @include switch-size($switch-height-lrg, $switch-font-size-lrg); }
274
-
275
- // Small radio switches
276
- &.small { @include switch-size($switch-height-sml, $switch-font-size-sml, 2.1rem); }
277
-
278
- // Tiny radio switches
279
- &.tiny { @include switch-size($switch-height-tny, $switch-font-size-tny, 1.9rem); }
280
-
281
- // Add a radius to the switch
282
- &.radius { @include radius(4px);
283
- span:last-child{ @include radius(3px); }
284
- }
285
-
286
- // Make the switch completely round, like a pill
287
- &.round { @include radius(1000px);
288
- span:last-child { @include radius(999px); }
289
- label { padding: rem-calc(0 $switch-label-side-padding + 3); }
290
- }
291
-
292
- }
293
- }
294
- }