backboneAXSwitch 0.0.1

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.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'rails', '~> 3.2.1'
4
+
5
+ # Specify your gem's dependencies in backboneAXSwitch.gemspec
6
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "backboneAXSwitch/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "backboneAXSwitch"
7
+ s.version = Backboneaxswitch::VERSION
8
+ s.authors = ["Chris Douglas"]
9
+ s.email = ["dougo.chris@gmail.com"]
10
+ s.homepage = "https://github.com/dougochris/backboneAXSwitch"
11
+ s.summary = %q{backboneAX Switch Control}
12
+ s.description = %q{backbone Application Extensions Switch Control}
13
+
14
+ s.rubyforge_project = "backboneAXSwitch"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ # s.add_development_dependency "rspec"
23
+ s.add_runtime_dependency "backboneAX"
24
+ end
@@ -0,0 +1,12 @@
1
+ require "backboneAXSwitch/version"
2
+
3
+ if defined? Rails
4
+ if Rails.version.to_f >= 3.1
5
+ require "backboneAXSwitch/engine"
6
+ end
7
+ end
8
+
9
+ require "backboneAXSwitch/bootstrap_view"
10
+ module Sprockets::Helpers::RailsHelper
11
+ include BackboneAXSwitch::BootstrapView
12
+ end
@@ -0,0 +1,34 @@
1
+ module BackboneAXSwitch
2
+ module BootstrapView
3
+
4
+ def bx_field_switch(label, field_id, options = {})
5
+ capture_haml do
6
+ haml_tag(:div, options.merge({class: 'switch', id: field_id})) do
7
+ haml_tag(:div, {class: 'cb-enable'}) do
8
+ haml_tag(:span, 'On')
9
+ end
10
+ haml_tag(:div, {class: 'cb-disable'}) do
11
+ haml_tag(:span, 'Off')
12
+ end
13
+ haml_tag(:input, options.merge({class: 'hide', type: 'checkbox', id: field_id}))
14
+ end
15
+ end
16
+ end
17
+
18
+
19
+ def bx_cg_switch(label, field_id, options = {})
20
+ bx_cg_group(label, field_id, options) do
21
+ haml_tag(:div, options.merge({class: 'switch', id: field_id})) do
22
+ haml_tag(:div, {class: 'cb-enable'}) do
23
+ haml_tag(:span, 'On')
24
+ end
25
+ haml_tag(:div, {class: 'cb-disable'}) do
26
+ haml_tag(:span, 'Off')
27
+ end
28
+ haml_tag(:input, options.merge({class: 'hide', type: 'checkbox', id: field_id}))
29
+ end
30
+ end
31
+ end
32
+
33
+ end
34
+ end
@@ -0,0 +1,4 @@
1
+ module BackboneAXSwitch
2
+ class Engine < Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module Backboneaxswitch
2
+ VERSION = "0.0.1"
3
+ end
Binary file
@@ -0,0 +1,39 @@
1
+ $.fn.initSwitch = () ->
2
+ $this = if $(this).hasClass('switch') then $(this) else $(this).closest('.switch')
3
+
4
+ $this.find('.cb-enable').click () ->
5
+ $(this).closest('.switch').switch(true)
6
+
7
+ $this.find('.cb-disable').click () ->
8
+ $(this).closest('.switch').switch(false)
9
+
10
+ $.fn.switch = (trueFalse) ->
11
+ $this = if $(this).hasClass('switch') then $(this) else $(this).closest('.switch')
12
+
13
+ if trueFalse == true
14
+ $this.find('.cb-enable').addClass('selected')
15
+ $this.find('.cb-disable').removeClass('selected')
16
+ $this.find('input[type=checkbox]').attr('checked', true)
17
+ else
18
+ $this.find('.cb-enable').removeClass('selected')
19
+ $this.find('.cb-disable').addClass('selected')
20
+ $this.find('input[type=checkbox]').attr('checked', false)
21
+ $this.find('input[type=checkbox]').removeAttr('checked')
22
+
23
+ _.extend Backbone.View.prototype,
24
+ formSetSwitch: (fieldName, model) ->
25
+ value = if @_isModel(model) then model.get(fieldName) else model
26
+ field = @$("##{fieldName}")
27
+
28
+ field.closest('.switch').switch(value == true)
29
+
30
+ formGetSwitch: (fieldName, model) ->
31
+ field = @$("##{fieldName}")
32
+ value = field.is(':checked')
33
+
34
+ if model?
35
+ options = {}
36
+ options[fieldName] = value
37
+ model.set(options, {silent: true})
38
+ return value
39
+
@@ -0,0 +1,10 @@
1
+ .cb-enable, .cb-disable, .cb-enable span, .cb-disable span { background: image-url('bx_switch.gif') repeat-x; display: block; float: left; }
2
+ .cb-enable span, .cb-disable span { line-height: 30px; display: block; background-repeat: no-repeat; font-weight: bold; }
3
+ .cb-enable span { background-position: left -90px; padding: 0 10px; }
4
+ .cb-disable span { background-position: right -180px;padding: 0 10px; }
5
+ .cb-disable.selected { background-position: 0 -30px; }
6
+ .cb-disable.selected span { background-position: right -210px; color: #fff; }
7
+ .cb-enable.selected { background-position: 0 -60px; }
8
+ .cb-enable.selected span { background-position: left -150px; color: #fff; }
9
+ .switch { cursor: pointer; }
10
+ .switch input { display: none; }
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: backboneAXSwitch
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Chris Douglas
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-09 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: backboneAX
16
+ requirement: &70241780874220 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70241780874220
25
+ description: backbone Application Extensions Switch Control
26
+ email:
27
+ - dougo.chris@gmail.com
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - .gitignore
33
+ - Gemfile
34
+ - Rakefile
35
+ - backboneAXSwitch.gemspec
36
+ - lib/backboneAXSwitch.rb
37
+ - lib/backboneAXSwitch/bootstrap_view.rb
38
+ - lib/backboneAXSwitch/engine.rb
39
+ - lib/backboneAXSwitch/version.rb
40
+ - vendor/assets/images/bx_switch.gif
41
+ - vendor/assets/javascripts/bx_switch.js.coffee
42
+ - vendor/assets/stylesheets/bx_switch.css.scss
43
+ homepage: https://github.com/dougochris/backboneAXSwitch
44
+ licenses: []
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ segments:
56
+ - 0
57
+ hash: -4049989469784335242
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ segments:
65
+ - 0
66
+ hash: -4049989469784335242
67
+ requirements: []
68
+ rubyforge_project: backboneAXSwitch
69
+ rubygems_version: 1.8.10
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: backboneAX Switch Control
73
+ test_files: []