├── .gitignore ├── Gemfile ├── HISTORY.md ├── README.md ├── Rakefile ├── build ├── .gitignore ├── build.sh └── output │ └── assets │ └── ios-checkboxes │ ├── ios-checkboxes-5d38e09413b47993266b4343b181d2f9.css │ ├── ios-checkboxes-767fc292f6a04316d3a54b18f4637b57.js │ ├── off-32586c60c5c48b7002326fdff55cd42e.png │ ├── on-c1710e0553b5cb2ba6b41a59ace60662.png │ ├── slider-a8cd833485793750ee72350ac5adb4d4.png │ ├── slider_center-137b6fa2802dc0a9be192b66c5a76815.png │ ├── slider_left-e6930b387dd9c0a424e7c1aedd0b0aea.png │ └── slider_right-e8654b2a69377361211e57422446c703.png ├── ios-checkboxes.gemspec ├── lib ├── assets │ ├── images │ │ └── ios-checkboxes │ │ │ ├── off.png │ │ │ ├── on.png │ │ │ ├── slider.png │ │ │ ├── slider_center.png │ │ │ ├── slider_left.png │ │ │ └── slider_right.png │ ├── javascripts │ │ ├── ios-checkboxes.js.coffee │ │ └── ios-checkboxes │ │ │ └── ios-checkboxes.js.coffee │ └── stylesheets │ │ ├── ios-checkboxes.sass │ │ └── ios-checkboxes │ │ ├── _mixins.sass │ │ └── ios-checkboxes.sass ├── ios-checkboxes.rb ├── ios-checkboxes │ ├── engine.rb │ ├── railtie.rb │ └── version.rb ├── ios-style-checkboxes │ ├── off.png │ ├── on.png │ ├── slider.png │ ├── slider_center.png │ ├── slider_left.png │ └── slider_right.png ├── ios │ └── checkboxes.rb └── tasks │ └── ios-checkboxes_tasks.rake └── spec ├── dummy ├── Rakefile ├── app │ ├── assets │ │ ├── javascripts │ │ │ └── application.js │ │ └── stylesheets │ │ │ └── application.css │ ├── controllers │ │ └── application_controller.rb │ ├── helpers │ │ └── application_helper.rb │ ├── mailers │ │ └── .gitkeep │ ├── models │ │ └── .gitkeep │ └── views │ │ └── layouts │ │ └── application.html.erb ├── config.ru ├── config │ ├── application.rb │ ├── boot.rb │ ├── database.yml │ ├── environment.rb │ ├── environments │ │ ├── development.rb │ │ ├── production.rb │ │ └── test.rb │ ├── initializers │ │ ├── backtrace_silencers.rb │ │ ├── inflections.rb │ │ ├── mime_types.rb │ │ ├── secret_token.rb │ │ ├── session_store.rb │ │ └── wrap_parameters.rb │ ├── locales │ │ └── en.yml │ └── routes.rb ├── lib │ └── assets │ │ └── .gitkeep ├── log │ └── .gitkeep ├── public │ ├── 404.html │ ├── 422.html │ ├── 500.html │ └── favicon.ico └── script │ └── rails ├── ios-checkboxes_spec.rb ├── javascripts ├── ios-checkboxes_spec.js.coffee ├── spec.css ├── spec.js.coffee └── support │ └── custom-theme.css.sass ├── spec_helper.rb └── support └── asset_matchers.rb /.gitignore: -------------------------------------------------------------------------------- 1 | .bundle/ 2 | log/*.log 3 | pkg/ 4 | Gemfile.lock 5 | spec/dummy/db/*.sqlite3 6 | spec/dummy/log/*.log 7 | spec/dummy/tmp/ 8 | spec/dummy/public/assets 9 | db/*.sqlite3 10 | log/*.log 11 | tmp/ 12 | .sass-cache/ 13 | *.swp 14 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source "http://rubygems.org" 2 | 3 | # Declare your gem's dependencies in ios-checkboxes.gemspec. 4 | # Bundler will treat runtime dependencies like base dependencies, and 5 | # development dependencies will be added by default to the :development group. 6 | gemspec 7 | 8 | # jquery-rails is used by the dummy application 9 | gem "jquery-rails" 10 | gem 'jasminerice' 11 | gem 'coffee-script' 12 | gem 'pry' 13 | gem 'uglifier' 14 | 15 | # Declare any dependencies that are still in development here instead of in 16 | # your gemspec. These might include edge Rails or gems from your path or 17 | # Git. Remember to move these dependencies to your gemspec before releasing 18 | # your gem to rubygems.org. 19 | 20 | # To use debugger 21 | # gem 'ruby-debug19', :require => 'ruby-debug' 22 | -------------------------------------------------------------------------------- /HISTORY.md: -------------------------------------------------------------------------------- 1 | 0.2.1 - Fri 25 May 2012 2 | ======================================== 3 | - Updated to support Rails 3.2 4 | - No dependency on compass 5 | 6 | 7 | ... TODO: add missing ... 8 | 9 | 0.1.3 - Tue 22 Nov 2011 10 | ======================================== 11 | - Ability to customise using SASS mixins as hooks 12 | - Allow to remove the variable value altoether by giving it an empty string (`$iphone-style-images-path: ''`) 13 | 14 | 0.1.2 - Mon 21 Nov 2011 15 | ======================================== 16 | - Customise the images, sizes etc via SASS 17 | - Provide precompiled assets for standalone use 18 | 19 | 0.1.1 - Fri 18 Nov 2011 20 | ======================================== 21 | - Provides jQuery iphoneStyle function in JavaScript and the JavaScript file itself. 22 | - Provides default styling. 23 | - Compatible with Rails Assets Pipeline (include images referenced from the CSS). 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ios-checkboxes 2 | ======================================== 3 | 4 | This project allows you to easily use iPhone style checkboxes in a Rails 3.1 application. 5 | 6 | Install 7 | ======================================== 8 | 9 | Add `gem 'ios-checkboxes'` to your Gemfile and run `bundle install` 10 | 11 | 12 | Using with Rails 3.1 13 | ======================================== 14 | 15 | Add `//=require ios-checkboxes` to your `app/assets/javascripts/application.js`. 16 | This will require `jquery` automaticaly. 17 | 18 | Also make sure you add the stylesheets to your `application.css`. 19 | Just `require ios-checkboxes` to get the default styling. 20 | 21 | You may choose not to use it and write the styling from scratch. In that case just don't add the iox-checkboxes to the stylesheet manifest. 22 | 23 | 24 | After you have all the ingridients in place you can convert your checkboxes into "On/Off" buttons 25 | with this JavaScript snippet: 26 | 27 | ```javascript 28 | $(function(){ 29 | $("input:checkbox").iphoneStyle(); 30 | }); 31 | ``` 32 | 33 | Using as a standalone 34 | ======================================== 35 | 36 | Go to the `build/output` directory and download its content. 37 | Put it content under your server root. 38 | Make sure you reference the JavaScript and CSS files properly. 39 | 40 | Don't reference it as 'assets/ios-checkboxes.js', instead use the full file name from the download 41 | (it will change with time): `assets/ios-checkboxes-d0bbaf0b834d61ddccf7510739596dd2.js` 42 | 43 | The same applies to CSS, but you don't need to do anything for images. 44 | 45 | The use of the "digest" appended to the end of file ensures that your users will have the most recent version of the files (cashe buster). 46 | 47 | 48 | Customisation 49 | ======================================== 50 | 51 | Basic 52 | ---------------------------------------- 53 | 54 | If the defaut stylesheet doesn't fit your design, you can customize it. 55 | 56 | Add a `.css.sass` file to your application and require it. 57 | The basic example may look like this: 58 | 59 | ```sass 60 | // app/assets/stylesheets/iphone.css.sass 61 | @import "ios-checkboxes/mixins" 62 | 63 | // This will change the defaults for everything 64 | $iphone-style-height: 33px // Default = 27px 65 | $iphone-style-font-size: 30px // Default = 17px 66 | $iphone-style-images-path: 'custom-path-to-images' // Default = ios-checkboxes 67 | 68 | +iphone-style // This includes the actual styles with customised values 69 | 70 | // You can also override the styles for sub-selectors 71 | .huge 72 | $iphone-style-height: 60px 73 | $iphone-style-font-size: 40px 74 | $iphone-style-images-path: 'hude-images' 75 | +iphone-style 76 | ``` 77 | 78 | 79 | If you modify the `$iphone-style-images-path` then you have to provide a (Sprockets) directory with the following files: 80 | 81 | ``` 82 | off.png 83 | on.png 84 | slider.png 85 | slider_center.png 86 | slider_left.png 87 | slider_right.png 88 | ``` 89 | 90 | Advanced 91 | ---------------------------------------- 92 | 93 | If overriding existing variables doesn't work for you and you don't want to write everything from scratch, 94 | then you can customise using the hooks provided. 95 | For example, this creates the iOS 5 On/Off buttons (round ones) and uses no images whatsoever. 96 | 97 | ```sass 98 | @import "compass/css3/images" 99 | @import "compass/css3/border-radius" 100 | @import "compass/css3/box-shadow" 101 | @import "ios-checkboxes/mixins" 102 | 103 | 104 | // Override the ios-checboxes defaults 105 | // Empty string disables the property (can't be applied to height) 106 | $iphone-style-font: '' 107 | $iphone-style-height: 1.8em 108 | $iphone-style-font-size: '' 109 | $iphone-style-images-path: '' 110 | 111 | // Define additional variables 112 | $onoff-active: #136785 113 | $onoff-active-alt: #1c94bf 114 | $onoff-back: #bfbfbf 115 | 116 | $onoff-radius: $iphone-style-height / 2 117 | 118 | =iphone-style-visual-container 119 | width: 6 * $onoff-radius 120 | // We add borders inside, so need to increse the padding 121 | padding: 1px 122 | 123 | 124 | =iphone-style-label 125 | +border-radius($onoff-radius) 126 | text-align: center 127 | text-transform: uppercase 128 | 129 | =iphone-style-label-on 130 | left: 0 131 | padding-right: $onoff-radius 132 | border: 1px solid $onoff-active 133 | color: white 134 | background: $onoff-active 135 | +background-image(linear-gradient(top, $onoff-active, $onoff-active-alt)) 136 | +box-shadow($onoff-back 0 0 2px inset) 137 | // Don't squeeze the On button too much to make sure the handle overlaps fully with it 138 | // this way it can interset with handler 139 | min-width: $onoff-radius*0.9 140 | 141 | 142 | =iphone-style-label-off 143 | left: $onoff-radius 144 | margin-left: -$onoff-radius 145 | text-align: right 146 | border: 1px solid $onoff-back 147 | color: #666666 148 | background: $onoff-back 149 | +background-image(linear-gradient(top, $onoff-back, white)) 150 | span 151 | padding-right: $onoff-radius 152 | 153 | 154 | =iphone-style-visual-handle 155 | width: $onoff-radius * 2 156 | height: $onoff-radius * 2 157 | +border-radius($onoff-radius) 158 | background: $onoff-back 159 | border: 1px solid $onoff-back 160 | +background-image(linear-gradient(top, $onoff-back, white)) 161 | 162 | // Additional hooks that you can override are: 163 | // =iphone-style-visual-handle-right 164 | // =iphone-style-visual-handle-center 165 | 166 | 167 | // And finally emit the stylesheet 168 | +iphone-style 169 | ``` 170 | 171 | 172 | 173 | Development 174 | ======================================== 175 | 176 | ```bash 177 | git clone git@github.com:dnagir/ios-checkboxes.git 178 | cd ios-checkboxes 179 | bundle install 180 | bundle rspec spec 181 | (cd spec/dummy/ && bundle exec rails s) 182 | # Now go to http://localhost:3000/jasmine to run the specs 183 | ``` 184 | 185 | To build the standalone assets: `sh build/build.sh`. 186 | 187 | Help 188 | ======================================== 189 | 190 | - Report issues on [Github](https://github.com/dnagir/ios-checkboxes/issues). 191 | - Shout at me in Twitter - [@dnagir](http://twitter.com/dnagir) 192 | 193 | 194 | Credits 195 | ======================================== 196 | 197 | [Thomas Reynolds](https://github.com/tdreyno) for the original [implementation](https://github.com/tdreyno/iphone-style-checkboxes). 198 | 199 | 200 | License (MIT) 201 | ======================================== 202 | 203 | Copyright 2011 Thomas Reynolds, Dmytrii Nagirniak 204 | 205 | Permission is hereby granted, free of charge, to any person obtaining 206 | a copy of this software and associated documentation files (the 207 | "Software"), to deal in the Software without restriction, including 208 | without limitation the rights to use, copy, modify, merge, publish, 209 | distribute, sublicense, and/or sell copies of the Software, and to 210 | permit persons to whom the Software is furnished to do so, subject to 211 | the following conditions: 212 | 213 | The above copyright notice and this permission notice shall be 214 | included in all copies or substantial portions of the Software. 215 | 216 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 217 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 218 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 219 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 220 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 221 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 222 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 223 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env rake 2 | begin 3 | require 'bundler/setup' 4 | rescue LoadError 5 | puts 'You must `gem install bundler` and `bundle install` to run rake tasks' 6 | end 7 | begin 8 | require 'rdoc/task' 9 | rescue LoadError 10 | require 'rdoc/rdoc' 11 | require 'rake/rdoctask' 12 | RDoc::Task = Rake::RDocTask 13 | end 14 | 15 | RDoc::Task.new(:rdoc) do |rdoc| 16 | rdoc.rdoc_dir = 'rdoc' 17 | rdoc.title = 'IosCheckboxes' 18 | rdoc.options << '--line-numbers' 19 | rdoc.rdoc_files.include('README.rdoc') 20 | rdoc.rdoc_files.include('lib/**/*.rb') 21 | end 22 | 23 | 24 | 25 | Bundler::GemHelper.install_tasks 26 | 27 | require 'rake/testtask' 28 | 29 | Rake::TestTask.new(:test) do |t| 30 | t.libs << 'lib' 31 | t.libs << 'test' 32 | t.pattern = 'test/**/*_test.rb' 33 | t.verbose = false 34 | end 35 | 36 | 37 | task :default => :test 38 | -------------------------------------------------------------------------------- /build/.gitignore: -------------------------------------------------------------------------------- 1 | *.yml 2 | *.gz 3 | -------------------------------------------------------------------------------- /build/build.sh: -------------------------------------------------------------------------------- 1 | 2 | pushd spec/dummy && 3 | bundle exec rake assets:clean RAILS_ENV=production && 4 | bundle exec rake assets:precompile:primary RAILS_ENV=production && 5 | popd && 6 | rm -rf build/output/* && 7 | cp -rf spec/dummy/public/assets build/output 8 | -------------------------------------------------------------------------------- /build/output/assets/ios-checkboxes/ios-checkboxes-5d38e09413b47993266b4343b181d2f9.css: -------------------------------------------------------------------------------- 1 | .iPhoneCheckContainer{position:relative;height:27px;cursor:pointer;overflow:hidden}.iPhoneCheckContainer input{position:absolute;top:5px;left:30px;filter:progid:DXImageTransform.Microsoft.Alpha(Opacity=0);opacity:0}.iPhoneCheckContainer label{white-space:nowrap;font-size:17x;line-height:17x;font-weight:bold;font-family:"Helvetica Neue",Arial,Helvetica,sans-serif;cursor:pointer;display:block;height:27px;position:absolute;width:auto;top:0;padding-top:5px;overflow:hidden}.iPhoneCheckContainer,.iPhoneCheckContainer label{user-select:none;-moz-user-select:none;-khtml-user-select:none}.iPhoneCheckDisabled{filter:progid:DXImageTransform.Microsoft.Alpha(Opacity=50);opacity:0.5}label.iPhoneCheckLabelOn{color:#fff;background:url(/assets/ios-checkboxes/on-c1710e0553b5cb2ba6b41a59ace60662.png) no-repeat;text-shadow:0px 0px 2px rgba(0,0,0,0.6);left:0;padding-top:5px}label.iPhoneCheckLabelOn span{padding-left:8px}label.iPhoneCheckLabelOff{color:#8b8b8b;background:url(/assets/ios-checkboxes/off-32586c60c5c48b7002326fdff55cd42e.png) no-repeat right 0;text-shadow:0px 0px 2px rgba(255,255,255,0.6);text-align:right;right:0}label.iPhoneCheckLabelOff span{padding-right:8px}.iPhoneCheckHandle{display:block;height:27px;cursor:pointer;position:absolute;top:0;left:0;width:0;background:url(/assets/ios-checkboxes/slider_left-e6930b387dd9c0a424e7c1aedd0b0aea.png) no-repeat;padding-left:3px}.iPhoneCheckHandleRight{height:100%;width:100%;padding-right:3px;background:url(/assets/ios-checkboxes/slider_right-e8654b2a69377361211e57422446c703.png) no-repeat right 0}.iPhoneCheckHandleCenter{height:100%;width:100%;background:url(/assets/ios-checkboxes/slider_center-137b6fa2802dc0a9be192b66c5a76815.png)} 2 | -------------------------------------------------------------------------------- /build/output/assets/ios-checkboxes/ios-checkboxes-767fc292f6a04316d3a54b18f4637b57.js: -------------------------------------------------------------------------------- 1 | ((function(){var a,b=Array.prototype.slice;a=function(){function a(b,c){var d,e,f;this.elem=$(b),e=$.extend({},a.defaults,c);for(d in e)f=e[d],this[d]=f;this.elem.data(this.dataName,this),this.wrapCheckboxWithDivs(),this.attachEvents(),this.disableTextSelection(),this.resizeHandle&&this.optionallyResize("handle"),this.resizeContainer&&this.optionallyResize("container"),this.initialPosition()}return a.prototype.isDisabled=function(){return this.elem.is(":disabled")},a.prototype.wrapCheckboxWithDivs=function(){return this.elem.wrap("
"),this.container=this.elem.parent(),this.offLabel=$("").appendTo(this.container),this.offSpan=this.offLabel.children("span"),this.onLabel=$("").appendTo(this.container),this.onSpan=this.onLabel.children("span"),this.handle=$("
\n
\n
\n
\n
").appendTo(this.container)},a.prototype.disableTextSelection=function(){if($.browser.msie)return $([this.handle,this.offLabel,this.onLabel,this.container]).attr("unselectable","on")},a.prototype._getDimension=function(a,b){return $.fn.actual!=null?a.actual(b):a[b]()},a.prototype.optionallyResize=function(a){var b,c,d;return d=this._getDimension(this.onLabel,"width"),c=this._getDimension(this.offLabel,"width"),a==="container"?(b=d>c?d:c,b+=this._getDimension(this.handle,"width")+this.handleMargin,this.container.css({width:b})):(b=d>c?d:c,this.handle.css({width:b}))},a.prototype.onMouseDown=function(b){var c;b.preventDefault();if(this.isDisabled())return;return c=b.pageX||b.originalEvent.changedTouches[0].pageX,a.currentlyClicking=this.handle,a.dragStartPosition=c,a.handleLeftOffset=parseInt(this.handle.css("left"),10)||0},a.prototype.onDragMove=function(b,c){var d,e;if(a.currentlyClicking!==this.handle)return;return e=(c+a.handleLeftOffset-a.dragStartPosition)/this.rightSide,e<0&&(e=0),e>1&&(e=1),d=e*this.rightSide,this.handle.css({left:d}),this.onLabel.css({width:d+this.handleRadius}),this.offSpan.css({marginRight:-d}),this.onSpan.css({marginLeft:-(1-e)*this.rightSide})},a.prototype.onDragEnd=function(b,c){var d;if(a.currentlyClicking!==this.handle)return;if(this.isDisabled())return;return a.dragging?(d=(c-a.dragStartPosition)/this.rightSide,this.elem.prop("checked",d>=.5)):this.elem.prop("checked",!this.elem.prop("checked")),a.currentlyClicking=null,a.dragging=null,this.didChange()},a.prototype.refresh=function(){return this.didChange()},a.prototype.didChange=function(){var a;return typeof this.onChange=="function"&&this.onChange(this.elem,this.elem.prop("checked")),this.isDisabled()?(this.container.addClass(this.disabledClass),!1):(this.container.removeClass(this.disabledClass),a=this.elem.prop("checked")?this.rightSide:0,this.handle.animate({left:a},this.duration),this.onLabel.animate({width:a+this.handleRadius},this.duration),this.offSpan.animate({marginRight:-a},this.duration),this.onSpan.animate({marginLeft:a-this.rightSide},this.duration))},a.prototype.attachEvents=function(){var a,b,c;return c=this,a=function(a){return c.onGlobalMove.apply(c,arguments)},b=function(d){return c.onGlobalUp.apply(c,arguments),$(document).unbind("mousemove touchmove",a),$(document).unbind("mouseup touchend",b)},this.elem.change(function(){return c.refresh()}),this.container.bind("mousedown touchstart",function(d){return c.onMouseDown.apply(c,arguments),$(document).bind("mousemove touchmove",a),$(document).bind("mouseup touchend",b)})},a.prototype.initialPosition=function(){var a,b;a=this._getDimension(this.container,"width"),this.offLabel.css({width:a-this.containerRadius}),b=this.containerRadius+1,$.browser.msie&&$.browser.version<7&&(b-=3),this.rightSide=a-this._getDimension(this.handle,"width")-b,this.elem.is(":checked")?(this.handle.css({left:this.rightSide}),this.onLabel.css({width:this.rightSide+this.handleRadius}),this.offSpan.css({marginRight:-this.rightSide})):(this.onLabel.css({width:0}),this.onSpan.css({marginLeft:-this.rightSide}));if(this.isDisabled())return this.container.addClass(this.disabledClass)},a.prototype.onGlobalMove=function(b){var c;if(!!this.isDisabled()||!a.currentlyClicking)return;return b.preventDefault(),c=b.pageX||b.originalEvent.changedTouches[0].pageX,!a.dragging&&Math.abs(a.dragStartPosition-c)>this.dragThreshold&&(a.dragging=!0),this.onDragMove(b,c)},a.prototype.onGlobalUp=function(b){var c;if(!a.currentlyClicking)return;return b.preventDefault(),c=b.pageX||b.originalEvent.changedTouches[0].pageX,this.onDragEnd(b,c),!1},a.defaults={duration:200,checkedLabel:"ON",uncheckedLabel:"OFF",resizeHandle:!0,resizeContainer:!0,disabledClass:"iPhoneCheckDisabled",containerClass:"iPhoneCheckContainer",labelOnClass:"iPhoneCheckLabelOn",labelOffClass:"iPhoneCheckLabelOff",handleClass:"iPhoneCheckHandle",handleCenterClass:"iPhoneCheckHandleCenter",handleRightClass:"iPhoneCheckHandleRight",dragThreshold:5,handleMargin:15,handleRadius:4,containerRadius:5,dataName:"iphoneStyle",onChange:function(){}},a}(),$.iphoneStyle=this.iOSCheckbox=a,$.fn.iphoneStyle=function(){var c,d,e,f,g,h,i,j,k,l,m,n;c=1<=arguments.length?b.call(arguments,0):[],e=(k=(l=c[0])!=null?l.dataName:void 0)!=null?k:a.defaults.dataName,m=this.filter(":checkbox");for(i=0,j=m.length;i= 3.1" 21 | s.add_dependency "sass-rails" 22 | 23 | s.add_development_dependency "rspec-rails" 24 | end 25 | -------------------------------------------------------------------------------- /lib/assets/images/ios-checkboxes/off.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dnagir/ios-checkboxes/b6fc021e323c0393567442fda085d028d9c09948/lib/assets/images/ios-checkboxes/off.png -------------------------------------------------------------------------------- /lib/assets/images/ios-checkboxes/on.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dnagir/ios-checkboxes/b6fc021e323c0393567442fda085d028d9c09948/lib/assets/images/ios-checkboxes/on.png -------------------------------------------------------------------------------- /lib/assets/images/ios-checkboxes/slider.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dnagir/ios-checkboxes/b6fc021e323c0393567442fda085d028d9c09948/lib/assets/images/ios-checkboxes/slider.png -------------------------------------------------------------------------------- /lib/assets/images/ios-checkboxes/slider_center.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dnagir/ios-checkboxes/b6fc021e323c0393567442fda085d028d9c09948/lib/assets/images/ios-checkboxes/slider_center.png -------------------------------------------------------------------------------- /lib/assets/images/ios-checkboxes/slider_left.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dnagir/ios-checkboxes/b6fc021e323c0393567442fda085d028d9c09948/lib/assets/images/ios-checkboxes/slider_left.png -------------------------------------------------------------------------------- /lib/assets/images/ios-checkboxes/slider_right.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dnagir/ios-checkboxes/b6fc021e323c0393567442fda085d028d9c09948/lib/assets/images/ios-checkboxes/slider_right.png -------------------------------------------------------------------------------- /lib/assets/javascripts/ios-checkboxes.js.coffee: -------------------------------------------------------------------------------- 1 | #= require jquery 2 | #= require ios-checkboxes/ios-checkboxes 3 | -------------------------------------------------------------------------------- /lib/assets/javascripts/ios-checkboxes/ios-checkboxes.js.coffee: -------------------------------------------------------------------------------- 1 | # iPhone-style Checkboxes Coffee plugin 2 | # Copyright Thomas Reynolds, licensed GPL & MIT 3 | 4 | class iOSCheckbox 5 | constructor: (elem, options) -> 6 | @elem = $(elem) 7 | 8 | opts = $.extend({}, iOSCheckbox.defaults, options) 9 | 10 | # Import options into instance variables 11 | for key, value of opts 12 | @[key] = value 13 | 14 | @elem.data(@dataName, this) 15 | 16 | # Initialize the control 17 | @wrapCheckboxWithDivs() 18 | @attachEvents() 19 | @disableTextSelection() 20 | 21 | @optionallyResize('handle') if @resizeHandle 22 | @optionallyResize('container') if @resizeContainer 23 | 24 | @initialPosition() 25 | 26 | isDisabled: -> @elem.is(':disabled') 27 | 28 | # Wrap the existing input[type=checkbox] with divs for styling and grab 29 | # DOM references to the created nodes 30 | wrapCheckboxWithDivs: -> 31 | @elem.wrap("
") 32 | 33 | @container = @elem.parent() 34 | 35 | @offLabel = $("""""").appendTo(@container) 38 | 39 | @offSpan = @offLabel.children('span') 40 | 41 | @onLabel = $("""""").appendTo(@container) 44 | 45 | @onSpan = @onLabel.children('span') 46 | 47 | @handle = $("""
48 |
49 |
50 |
51 |
""").appendTo(this.container) 52 | 53 | # Disable IE text selection, other browsers are handled in CSS 54 | disableTextSelection: -> 55 | # Elements containing text should be unselectable 56 | if $.browser.msie 57 | $([@handle, @offLabel, @onLabel, @container]).attr("unselectable", "on") 58 | 59 | _getDimension: (elem, dimension) -> 60 | if $.fn.actual? 61 | elem.actual(dimension) 62 | else 63 | elem[dimension]() 64 | 65 | # Automatically resize the handle or container 66 | optionallyResize: (mode) -> 67 | onLabelWidth = @_getDimension(@onLabel, "width") 68 | offLabelWidth = @_getDimension(@offLabel, "width") 69 | 70 | if mode == "container" 71 | newWidth = if (onLabelWidth > offLabelWidth) 72 | onLabelWidth 73 | else 74 | offLabelWidth 75 | 76 | newWidth += @_getDimension(@handle, "width") + @handleMargin 77 | @container.css(width: newWidth) 78 | else 79 | newWidth = if (onLabelWidth > offLabelWidth) 80 | onLabelWidth 81 | else 82 | offLabelWidth 83 | @handle.css(width: newWidth) 84 | 85 | onMouseDown: (event) -> 86 | event.preventDefault() 87 | 88 | return if @isDisabled() 89 | 90 | x = event.pageX || event.originalEvent.changedTouches[0].pageX 91 | iOSCheckbox.currentlyClicking = @handle 92 | iOSCheckbox.dragStartPosition = x 93 | iOSCheckbox.handleLeftOffset = parseInt(@handle.css('left'), 10) || 0 94 | 95 | onDragMove: (event, x) -> 96 | return unless iOSCheckbox.currentlyClicking == @handle 97 | 98 | p = (x + iOSCheckbox.handleLeftOffset - iOSCheckbox.dragStartPosition) / @rightSide 99 | p = 0 if p < 0 100 | p = 1 if p > 1 101 | 102 | newWidth = p * @rightSide 103 | @handle.css(left: newWidth) 104 | @onLabel.css(width: newWidth + @handleRadius) 105 | @offSpan.css(marginRight: -newWidth) 106 | @onSpan.css(marginLeft: -(1 - p) * @rightSide) 107 | 108 | onDragEnd: (event, x) -> 109 | return unless iOSCheckbox.currentlyClicking == @handle 110 | return if @isDisabled() 111 | 112 | if iOSCheckbox.dragging 113 | p = (x - iOSCheckbox.dragStartPosition) / @rightSide 114 | @elem.prop('checked', (p >= 0.5)) 115 | else 116 | @elem.prop('checked', !@elem.prop('checked')) 117 | 118 | iOSCheckbox.currentlyClicking = null 119 | iOSCheckbox.dragging = null 120 | @didChange() 121 | 122 | refresh: -> @didChange() #TODO: Verify - this might fire event unnecessarily 123 | 124 | didChange: -> 125 | @onChange?(@elem, @elem.prop('checked')) 126 | 127 | if @isDisabled() 128 | @container.addClass(@disabledClass) 129 | return false 130 | else 131 | @container.removeClass(@disabledClass) 132 | 133 | new_left = if @elem.prop('checked') then @rightSide else 0 134 | 135 | @handle.animate(left: new_left, @duration) 136 | @onLabel.animate(width: new_left + @handleRadius, @duration) 137 | @offSpan.animate(marginRight: -new_left, @duration) 138 | @onSpan.animate(marginLeft: new_left - @rightSide, @duration) 139 | 140 | attachEvents: -> 141 | self = this 142 | 143 | localMouseMove = (event) -> 144 | self.onGlobalMove.apply(self, arguments) 145 | 146 | localMouseUp = (event) -> 147 | self.onGlobalUp.apply(self, arguments) 148 | $(document).unbind 'mousemove touchmove', localMouseMove 149 | $(document).unbind 'mouseup touchend', localMouseUp 150 | 151 | # The original checkbox value might be changed by clickig on the associated label or other means 152 | # To make sure we are in sync: 153 | @elem.change -> self.refresh() 154 | 155 | # A mousedown anywhere in the control will start tracking for dragging 156 | @container.bind 'mousedown touchstart', (event) -> 157 | self.onMouseDown.apply(self, arguments) 158 | 159 | # As the mouse moves on the page, animate if we are in a drag state 160 | $(document).bind 'mousemove touchmove', localMouseMove 161 | 162 | # When the mouse comes up, leave drag state 163 | $(document).bind 'mouseup touchend', localMouseUp 164 | 165 | # Setup the control's inital position 166 | initialPosition: -> 167 | containerWidth = @_getDimension(@container, "width") 168 | @offLabel.css(width: containerWidth - @containerRadius) 169 | 170 | offset = @containerRadius + 1 171 | offset -= 3 if $.browser.msie and $.browser.version < 7 172 | @rightSide = containerWidth - @_getDimension(@handle, "width") - offset 173 | 174 | if @elem.is(':checked') 175 | @handle.css(left: @rightSide) 176 | @onLabel.css(width: @rightSide + @handleRadius) 177 | @offSpan.css(marginRight: -@rightSide) 178 | else 179 | @onLabel.css(width: 0) 180 | @onSpan.css(marginLeft: -@rightSide) 181 | 182 | @container.addClass(@disabledClass) if @isDisabled() 183 | 184 | onGlobalMove: (event) -> 185 | return unless !@isDisabled() && iOSCheckbox.currentlyClicking 186 | event.preventDefault() 187 | 188 | x = event.pageX || event.originalEvent.changedTouches[0].pageX 189 | 190 | if (!iOSCheckbox.dragging && 191 | (Math.abs(iOSCheckbox.dragStartPosition - x) > @dragThreshold)) 192 | iOSCheckbox.dragging = true 193 | 194 | @onDragMove(event, x) 195 | 196 | onGlobalUp: (event) -> 197 | return unless iOSCheckbox.currentlyClicking 198 | event.preventDefault() 199 | 200 | x = event.pageX || event.originalEvent.changedTouches[0].pageX 201 | 202 | @onDragEnd(event, x) 203 | false 204 | 205 | @defaults: 206 | # Time spent during slide animation 207 | duration: 200 208 | 209 | # Text content of "on" state 210 | checkedLabel: 'ON' 211 | 212 | # Text content of "off" state 213 | uncheckedLabel: 'OFF' 214 | 215 | # Automatically resize the handle to cover either label 216 | resizeHandle: true 217 | 218 | # Automatically resize the widget to contain the labels 219 | resizeContainer: true 220 | 221 | disabledClass: 'iPhoneCheckDisabled' 222 | containerClass: 'iPhoneCheckContainer' 223 | labelOnClass: 'iPhoneCheckLabelOn' 224 | labelOffClass: 'iPhoneCheckLabelOff' 225 | handleClass: 'iPhoneCheckHandle' 226 | handleCenterClass: 'iPhoneCheckHandleCenter' 227 | handleRightClass: 'iPhoneCheckHandleRight' 228 | 229 | # Pixels that must be dragged for a click to be ignored 230 | dragThreshold: 5 231 | 232 | handleMargin: 15 233 | handleRadius: 4 234 | containerRadius: 5 235 | 236 | dataName: "iphoneStyle" 237 | 238 | onChange: -> 239 | 240 | $.iphoneStyle = @iOSCheckbox = iOSCheckbox 241 | 242 | $.fn.iphoneStyle = (args...) -> 243 | dataName = args[0]?.dataName ? iOSCheckbox.defaults.dataName 244 | 245 | for checkbox in @filter(':checkbox') 246 | existingControl = $(checkbox).data(dataName) 247 | if existingControl? 248 | [method, params...] = args 249 | existingControl[method]?.apply(existingControl, params) 250 | else 251 | new iOSCheckbox(checkbox, args[0]) 252 | 253 | this 254 | 255 | $.fn.iOSCheckbox = (options={}) -> 256 | # iOS5 style only supports circular handle 257 | opts = $.extend({}, options, { 258 | resizeHandle: false 259 | disabledClass: 'iOSCheckDisabled' 260 | containerClass: 'iOSCheckContainer' 261 | labelOnClass: 'iOSCheckLabelOn' 262 | labelOffClass: 'iOSCheckLabelOff' 263 | handleClass: 'iOSCheckHandle' 264 | handleCenterClass: 'iOSCheckHandleCenter' 265 | handleRightClass: 'iOSCheckHandleRight' 266 | dataName: 'iOSCheckbox' 267 | }) 268 | 269 | this.iphoneStyle(opts) 270 | -------------------------------------------------------------------------------- /lib/assets/stylesheets/ios-checkboxes.sass: -------------------------------------------------------------------------------- 1 | @import "ios-checkboxes/ios-checkboxes" 2 | -------------------------------------------------------------------------------- /lib/assets/stylesheets/ios-checkboxes/_mixins.sass: -------------------------------------------------------------------------------- 1 | @mixin ios-opacity($opacity) 2 | opacity: $opacity 3 | // Borrowed from compass: https://github.com/chriseppstein/compass/blob/stable/frameworks/compass/stylesheets/compass/css3/_opacity.scss 4 | filter: unquote("progid:DXImageTransform.Microsoft.Alpha(Opacity=#{round($opacity * 100)})") 5 | 6 | 7 | $iphone-style-mode: "cross-browser" 8 | $iphone-style-font: "Helvetica Neue", Arial, Helvetica, sans-serif 9 | $iphone-style-height: 27px 10 | $iphone-style-font-size: 17px 11 | $iphone-style-images-path: 'ios-checkboxes' 12 | 13 | =iphone-style($selector-prefix: "iPhoneCheck") 14 | .#{$selector-prefix}Container 15 | +iphone-style-container 16 | &, label 17 | +iphone-style-disable-text-selection 18 | 19 | .#{$selector-prefix}Disabled 20 | +iphone-style-disabled 21 | 22 | label 23 | &.#{$selector-prefix}LabelOn 24 | +iphone-style-label-on 25 | &.#{$selector-prefix}LabelOff 26 | +iphone-style-label-off 27 | 28 | .#{$selector-prefix}Handle 29 | +iphone-style-handle 30 | 31 | .#{$selector-prefix}HandleRight 32 | +iphone-style-handle-right 33 | 34 | .#{$selector-prefix}HandleCenter 35 | +iphone-style-handle-center 36 | 37 | =iphone-style-disable-text-selection 38 | user-select: none 39 | -moz-user-select: none 40 | -khtml-user-select: none 41 | 42 | =iphone-style-disabled 43 | +ios-opacity(0.5) 44 | 45 | =iphone-style-label 46 | padding-top: 5px 47 | font-weight: bold 48 | 49 | =iphone-style-visual-container 50 | 51 | =iphone-style-container 52 | position: relative 53 | height: $iphone-style-height 54 | cursor: pointer 55 | overflow: hidden 56 | input 57 | position: absolute 58 | top: 5px 59 | left: 30px 60 | +ios-opacity(0) 61 | label 62 | white-space: nowrap 63 | @if $iphone-style-font-size != '' 64 | font-size: $iphone-style-font-size 65 | line-height: $iphone-style-font-size 66 | @if $iphone-style-font != '' 67 | font-family: $iphone-style-font 68 | cursor: pointer 69 | display: block 70 | height: $iphone-style-height 71 | position: absolute 72 | width: auto 73 | top: 0 74 | overflow: hidden 75 | +iphone-style-label 76 | +iphone-style-visual-container 77 | 78 | =iphone-style-label-on 79 | color: #fff 80 | @if $iphone-style-images-path != '' 81 | background: image-url("#{$iphone-style-images-path}/on.png") no-repeat 82 | text-shadow: 0px 0px 2px rgba(0, 0, 0, 0.6) 83 | left: 0 84 | padding-top: 5px 85 | span 86 | padding-left: 8px 87 | 88 | =iphone-style-label-off 89 | color: #8B8B8B 90 | @if $iphone-style-images-path != '' 91 | background: image-url("#{$iphone-style-images-path}/off.png") no-repeat right 0 92 | text-shadow: 0px 0px 2px rgba(255, 255, 255, 0.6) 93 | text-align: right 94 | right: 0 95 | span 96 | padding-right: 8px 97 | 98 | 99 | =iphone-style-visual-handle 100 | @if $iphone-style-images-path != '' 101 | background: image-url("#{$iphone-style-images-path}/slider_left.png") no-repeat 102 | padding-left: 3px 103 | =iphone-style-handle 104 | display: block 105 | height: $iphone-style-height 106 | cursor: pointer 107 | position: absolute 108 | top: 0 109 | left: 0 110 | width: 0 111 | +iphone-style-visual-handle 112 | 113 | 114 | =iphone-style-visual-handle-right 115 | padding-right: 3px 116 | @if $iphone-style-images-path != '' 117 | background: image-url("#{$iphone-style-images-path}/slider_right.png") no-repeat right 0 118 | =iphone-style-handle-right 119 | height: 100% 120 | width: 100% 121 | +iphone-style-visual-handle-right 122 | 123 | =iphone-style-visual-handle-center 124 | @if $iphone-style-images-path != '' 125 | background: image-url("#{$iphone-style-images-path}/slider_center.png") 126 | =iphone-style-handle-center 127 | height: 100% 128 | width: 100% 129 | +iphone-style-visual-handle-center 130 | -------------------------------------------------------------------------------- /lib/assets/stylesheets/ios-checkboxes/ios-checkboxes.sass: -------------------------------------------------------------------------------- 1 | @import "./ios-checkboxes/mixins" 2 | +iphone-style 3 | 4 | -------------------------------------------------------------------------------- /lib/ios-checkboxes.rb: -------------------------------------------------------------------------------- 1 | require 'ios-checkboxes/version' 2 | require 'ios-checkboxes/engine' 3 | require 'ios-checkboxes/railtie' 4 | 5 | module IosCheckboxes 6 | end 7 | -------------------------------------------------------------------------------- /lib/ios-checkboxes/engine.rb: -------------------------------------------------------------------------------- 1 | module IosCheckboxes 2 | class Engine < ::Rails::Engine 3 | end 4 | end 5 | -------------------------------------------------------------------------------- /lib/ios-checkboxes/railtie.rb: -------------------------------------------------------------------------------- 1 | require 'sass-rails' 2 | 3 | module IosCheckboxes 4 | class Railtie < ::Rails::Railtie 5 | initializer :ios_checkboxes, :after => :setup_sass do |app| 6 | config.sass.load_paths << File.join(::IosCheckboxes::Engine.root, 'lib', 'assets', 'stylesheets') 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /lib/ios-checkboxes/version.rb: -------------------------------------------------------------------------------- 1 | module IosCheckboxes 2 | VERSION = "0.2.2" 3 | end 4 | -------------------------------------------------------------------------------- /lib/ios-style-checkboxes/off.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dnagir/ios-checkboxes/b6fc021e323c0393567442fda085d028d9c09948/lib/ios-style-checkboxes/off.png -------------------------------------------------------------------------------- /lib/ios-style-checkboxes/on.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dnagir/ios-checkboxes/b6fc021e323c0393567442fda085d028d9c09948/lib/ios-style-checkboxes/on.png -------------------------------------------------------------------------------- /lib/ios-style-checkboxes/slider.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dnagir/ios-checkboxes/b6fc021e323c0393567442fda085d028d9c09948/lib/ios-style-checkboxes/slider.png -------------------------------------------------------------------------------- /lib/ios-style-checkboxes/slider_center.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dnagir/ios-checkboxes/b6fc021e323c0393567442fda085d028d9c09948/lib/ios-style-checkboxes/slider_center.png -------------------------------------------------------------------------------- /lib/ios-style-checkboxes/slider_left.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dnagir/ios-checkboxes/b6fc021e323c0393567442fda085d028d9c09948/lib/ios-style-checkboxes/slider_left.png -------------------------------------------------------------------------------- /lib/ios-style-checkboxes/slider_right.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dnagir/ios-checkboxes/b6fc021e323c0393567442fda085d028d9c09948/lib/ios-style-checkboxes/slider_right.png -------------------------------------------------------------------------------- /lib/ios/checkboxes.rb: -------------------------------------------------------------------------------- 1 | # Bundler infers the require statement as 'ios/checkboxes' 2 | # TODO: Avoid using the 'ios/checkboxes' directory 3 | require 'ios-checkboxes' 4 | -------------------------------------------------------------------------------- /lib/tasks/ios-checkboxes_tasks.rake: -------------------------------------------------------------------------------- 1 | # desc "Explaining what the task does" 2 | # task :ios-checkboxes do 3 | # # Task goes here 4 | # end 5 | -------------------------------------------------------------------------------- /spec/dummy/Rakefile: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env rake 2 | # Add your own tasks in files placed in lib/tasks ending in .rake, 3 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. 4 | 5 | require File.expand_path('../config/application', __FILE__) 6 | 7 | Dummy::Application.load_tasks 8 | -------------------------------------------------------------------------------- /spec/dummy/app/assets/javascripts/application.js: -------------------------------------------------------------------------------- 1 | // This is a manifest file that'll be compiled into including all the files listed below. 2 | // Add new JavaScript/Coffee code in separate files in this directory and they'll automatically 3 | // be included in the compiled file accessible from http://example.com/assets/application.js 4 | // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the 5 | // the compiled file. 6 | // 7 | //= require jquery 8 | //= require jquery_ujs 9 | //= require_tree . 10 | -------------------------------------------------------------------------------- /spec/dummy/app/assets/stylesheets/application.css: -------------------------------------------------------------------------------- 1 | /* 2 | * This is a manifest file that'll automatically include all the stylesheets available in this directory 3 | * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at 4 | * the top of the compiled file, but it's generally better to create a new file per style scope. 5 | *= require_self 6 | *= require_tree . 7 | */ -------------------------------------------------------------------------------- /spec/dummy/app/controllers/application_controller.rb: -------------------------------------------------------------------------------- 1 | class ApplicationController < ActionController::Base 2 | protect_from_forgery 3 | end 4 | -------------------------------------------------------------------------------- /spec/dummy/app/helpers/application_helper.rb: -------------------------------------------------------------------------------- 1 | module ApplicationHelper 2 | end 3 | -------------------------------------------------------------------------------- /spec/dummy/app/mailers/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dnagir/ios-checkboxes/b6fc021e323c0393567442fda085d028d9c09948/spec/dummy/app/mailers/.gitkeep -------------------------------------------------------------------------------- /spec/dummy/app/models/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dnagir/ios-checkboxes/b6fc021e323c0393567442fda085d028d9c09948/spec/dummy/app/models/.gitkeep -------------------------------------------------------------------------------- /spec/dummy/app/views/layouts/application.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Dummy 5 | <%= stylesheet_link_tag "application" %> 6 | <%= javascript_include_tag "application" %> 7 | <%= csrf_meta_tags %> 8 | 9 | 10 | 11 | <%= yield %> 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /spec/dummy/config.ru: -------------------------------------------------------------------------------- 1 | # This file is used by Rack-based servers to start the application. 2 | 3 | require ::File.expand_path('../config/environment', __FILE__) 4 | run Dummy::Application 5 | -------------------------------------------------------------------------------- /spec/dummy/config/application.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('../boot', __FILE__) 2 | 3 | #require 'rails/all' 4 | require "action_controller/railtie" 5 | require "action_mailer/railtie" 6 | require "active_resource/railtie" 7 | require "rails/test_unit/railtie" 8 | require 'sprockets/railtie' 9 | 10 | Bundler.require 11 | require "ios-checkboxes" 12 | 13 | require 'jasminerice' # This will plug-in Jasminerice engine automatically 14 | 15 | module Dummy 16 | class Application < Rails::Application 17 | # Settings in config/environments/* take precedence over those specified here. 18 | # Application configuration should go into files in config/initializers 19 | # -- all .rb files in that directory are automatically loaded. 20 | 21 | # Custom directories with classes and modules you want to be autoloadable. 22 | # config.autoload_paths += %W(#{config.root}/extras) 23 | 24 | # Only load the plugins named here, in the order given (default is alphabetical). 25 | # :all can be used as a placeholder for all plugins not explicitly named. 26 | # config.plugins = [ :exception_notification, :ssl_requirement, :all ] 27 | 28 | # Activate observers that should always be running. 29 | # config.active_record.observers = :cacher, :garbage_collector, :forum_observer 30 | 31 | # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. 32 | # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. 33 | # config.time_zone = 'Central Time (US & Canada)' 34 | 35 | # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. 36 | # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] 37 | # config.i18n.default_locale = :de 38 | 39 | # Configure the default encoding used in templates for Ruby 1.9. 40 | config.encoding = "utf-8" 41 | 42 | # Configure sensitive parameters which will be filtered from the log file. 43 | config.filter_parameters += [:password] 44 | 45 | # Enable the asset pipeline 46 | config.assets.enabled = true 47 | 48 | # Our specs are outside of the dummy app, so we need to tell Sprockets where those are 49 | config.assets.paths << File.join(Rails.root, "../", "javascripts") 50 | 51 | config.serve_static_assets = true 52 | 53 | # Version of your assets, change this if you want to expire all your assets 54 | config.assets.version = '1.0' 55 | end 56 | end 57 | 58 | -------------------------------------------------------------------------------- /spec/dummy/config/boot.rb: -------------------------------------------------------------------------------- 1 | require 'rubygems' 2 | gemfile = File.expand_path('../../../../Gemfile', __FILE__) 3 | 4 | if File.exist?(gemfile) 5 | ENV['BUNDLE_GEMFILE'] = gemfile 6 | require 'bundler' 7 | Bundler.setup 8 | end 9 | 10 | $:.unshift File.expand_path('../../../../lib', __FILE__) -------------------------------------------------------------------------------- /spec/dummy/config/database.yml: -------------------------------------------------------------------------------- 1 | # SQLite version 3.x 2 | # gem install sqlite3 3 | # 4 | # Ensure the SQLite 3 gem is defined in your Gemfile 5 | # gem 'sqlite3' 6 | development: 7 | adapter: sqlite3 8 | database: db/development.sqlite3 9 | pool: 5 10 | timeout: 5000 11 | 12 | # Warning: The database defined as "test" will be erased and 13 | # re-generated from your development database when you run "rake". 14 | # Do not set this db to the same as development or production. 15 | test: 16 | adapter: sqlite3 17 | database: db/test.sqlite3 18 | pool: 5 19 | timeout: 5000 20 | 21 | production: 22 | adapter: sqlite3 23 | database: db/production.sqlite3 24 | pool: 5 25 | timeout: 5000 26 | -------------------------------------------------------------------------------- /spec/dummy/config/environment.rb: -------------------------------------------------------------------------------- 1 | # Load the rails application 2 | require File.expand_path('../application', __FILE__) 3 | 4 | # Initialize the rails application 5 | Dummy::Application.initialize! 6 | -------------------------------------------------------------------------------- /spec/dummy/config/environments/development.rb: -------------------------------------------------------------------------------- 1 | Dummy::Application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb 3 | 4 | # In the development environment your application's code is reloaded on 5 | # every request. This slows down response time but is perfect for development 6 | # since you don't have to restart the web server when you make code changes. 7 | config.cache_classes = false 8 | 9 | # Log error messages when you accidentally call methods on nil. 10 | config.whiny_nils = true 11 | 12 | # Show full error reports and disable caching 13 | config.consider_all_requests_local = true 14 | config.action_controller.perform_caching = false 15 | 16 | # Don't care if the mailer can't send 17 | config.action_mailer.raise_delivery_errors = false 18 | 19 | # Print deprecation notices to the Rails logger 20 | config.active_support.deprecation = :log 21 | 22 | # Only use best-standards-support built into browsers 23 | config.action_dispatch.best_standards_support = :builtin 24 | 25 | # Do not compress assets 26 | config.assets.compress = false 27 | 28 | # Expands the lines which load the assets 29 | config.assets.debug = true 30 | end 31 | -------------------------------------------------------------------------------- /spec/dummy/config/environments/production.rb: -------------------------------------------------------------------------------- 1 | Dummy::Application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb 3 | 4 | # Code is not reloaded between requests 5 | config.cache_classes = true 6 | 7 | # Full error reports are disabled and caching is turned on 8 | config.consider_all_requests_local = false 9 | config.action_controller.perform_caching = true 10 | 11 | # Disable Rails's static asset server (Apache or nginx will already do this) 12 | config.serve_static_assets = false 13 | 14 | # Compress JavaScripts and CSS 15 | config.assets.compress = true 16 | 17 | # Don't fallback to assets pipeline if a precompiled asset is missed 18 | config.assets.compile = false 19 | 20 | # Generate digests for assets URLs 21 | config.assets.digest = true 22 | 23 | # Defaults to Rails.root.join("public/assets") 24 | # config.assets.manifest = YOUR_PATH 25 | 26 | # Specifies the header that your server uses for sending files 27 | # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache 28 | # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx 29 | 30 | # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. 31 | # config.force_ssl = true 32 | 33 | # See everything in the log (default is :info) 34 | # config.log_level = :debug 35 | 36 | # Use a different logger for distributed setups 37 | # config.logger = SyslogLogger.new 38 | 39 | # Use a different cache store in production 40 | # config.cache_store = :mem_cache_store 41 | 42 | # Enable serving of images, stylesheets, and JavaScripts from an asset server 43 | # config.action_controller.asset_host = "http://assets.example.com" 44 | 45 | # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added) 46 | config.assets.precompile = %w( ios-checkboxes/ios-checkboxes.js ios-checkboxes/ios-checkboxes.css ios-checkboxes/*.png ) 47 | 48 | # Disable delivery errors, bad email addresses will be ignored 49 | # config.action_mailer.raise_delivery_errors = false 50 | 51 | # Enable threaded mode 52 | # config.threadsafe! 53 | 54 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to 55 | # the I18n.default_locale when a translation can not be found) 56 | config.i18n.fallbacks = true 57 | 58 | # Send deprecation notices to registered listeners 59 | config.active_support.deprecation = :notify 60 | end 61 | -------------------------------------------------------------------------------- /spec/dummy/config/environments/test.rb: -------------------------------------------------------------------------------- 1 | Dummy::Application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb 3 | 4 | # The test environment is used exclusively to run your application's 5 | # test suite. You never need to work with it otherwise. Remember that 6 | # your test database is "scratch space" for the test suite and is wiped 7 | # and recreated between test runs. Don't rely on the data there! 8 | config.cache_classes = true 9 | 10 | # Configure static asset server for tests with Cache-Control for performance 11 | config.serve_static_assets = true 12 | config.static_cache_control = "public, max-age=3600" 13 | 14 | # Log error messages when you accidentally call methods on nil 15 | config.whiny_nils = true 16 | 17 | # Show full error reports and disable caching 18 | config.consider_all_requests_local = true 19 | config.action_controller.perform_caching = false 20 | 21 | # Raise exceptions instead of rendering exception templates 22 | config.action_dispatch.show_exceptions = false 23 | 24 | # Disable request forgery protection in test environment 25 | config.action_controller.allow_forgery_protection = false 26 | 27 | # Tell Action Mailer not to deliver emails to the real world. 28 | # The :test delivery method accumulates sent emails in the 29 | # ActionMailer::Base.deliveries array. 30 | config.action_mailer.delivery_method = :test 31 | 32 | # Use SQL instead of Active Record's schema dumper when creating the test database. 33 | # This is necessary if your schema can't be completely dumped by the schema dumper, 34 | # like if you have constraints or database-specific column types 35 | # config.active_record.schema_format = :sql 36 | 37 | # Print deprecation notices to the stderr 38 | config.active_support.deprecation = :stderr 39 | end 40 | -------------------------------------------------------------------------------- /spec/dummy/config/initializers/backtrace_silencers.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. 4 | # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } 5 | 6 | # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. 7 | # Rails.backtrace_cleaner.remove_silencers! 8 | -------------------------------------------------------------------------------- /spec/dummy/config/initializers/inflections.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new inflection rules using the following format 4 | # (all these examples are active by default): 5 | # ActiveSupport::Inflector.inflections do |inflect| 6 | # inflect.plural /^(ox)$/i, '\1en' 7 | # inflect.singular /^(ox)en/i, '\1' 8 | # inflect.irregular 'person', 'people' 9 | # inflect.uncountable %w( fish sheep ) 10 | # end 11 | -------------------------------------------------------------------------------- /spec/dummy/config/initializers/mime_types.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new mime types for use in respond_to blocks: 4 | # Mime::Type.register "text/richtext", :rtf 5 | # Mime::Type.register_alias "text/html", :iphone 6 | -------------------------------------------------------------------------------- /spec/dummy/config/initializers/secret_token.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Your secret key for verifying the integrity of signed cookies. 4 | # If you change this key, all old signed cookies will become invalid! 5 | # Make sure the secret is at least 30 characters and all random, 6 | # no regular words or you'll be exposed to dictionary attacks. 7 | Dummy::Application.config.secret_token = '445dd15337325e92d38250d785ed40a8a673445af043599cb76d88852030b8378d5c79b7b39d68e5b2486ed80ae26f6ec2deb58b6fa467654a33097eee3fefd5' 8 | -------------------------------------------------------------------------------- /spec/dummy/config/initializers/session_store.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | Dummy::Application.config.session_store :cookie_store, key: '_dummy_session' 4 | 5 | # Use the database for sessions instead of the cookie-based default, 6 | # which shouldn't be used to store highly confidential information 7 | # (create the session table with "rails generate session_migration") 8 | # Dummy::Application.config.session_store :active_record_store 9 | -------------------------------------------------------------------------------- /spec/dummy/config/initializers/wrap_parameters.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | # 3 | # This file contains settings for ActionController::ParamsWrapper which 4 | # is enabled by default. 5 | 6 | # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. 7 | ActiveSupport.on_load(:action_controller) do 8 | wrap_parameters format: [:json] 9 | end 10 | 11 | # Disable root element in JSON by default. 12 | ActiveSupport.on_load(:active_record) do 13 | self.include_root_in_json = false 14 | end 15 | -------------------------------------------------------------------------------- /spec/dummy/config/locales/en.yml: -------------------------------------------------------------------------------- 1 | # Sample localization file for English. Add more files in this directory for other locales. 2 | # See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points. 3 | 4 | en: 5 | hello: "Hello world" 6 | -------------------------------------------------------------------------------- /spec/dummy/config/routes.rb: -------------------------------------------------------------------------------- 1 | Dummy::Application.routes.draw do 2 | # The priority is based upon order of creation: 3 | # first created -> highest priority. 4 | 5 | # Sample of regular route: 6 | # match 'products/:id' => 'catalog#view' 7 | # Keep in mind you can assign values other than :controller and :action 8 | 9 | # Sample of named route: 10 | # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase 11 | # This route can be invoked with purchase_url(:id => product.id) 12 | 13 | # Sample resource route (maps HTTP verbs to controller actions automatically): 14 | # resources :products 15 | 16 | # Sample resource route with options: 17 | # resources :products do 18 | # member do 19 | # get 'short' 20 | # post 'toggle' 21 | # end 22 | # 23 | # collection do 24 | # get 'sold' 25 | # end 26 | # end 27 | 28 | # Sample resource route with sub-resources: 29 | # resources :products do 30 | # resources :comments, :sales 31 | # resource :seller 32 | # end 33 | 34 | # Sample resource route with more complex sub-resources 35 | # resources :products do 36 | # resources :comments 37 | # resources :sales do 38 | # get 'recent', :on => :collection 39 | # end 40 | # end 41 | 42 | # Sample resource route within a namespace: 43 | # namespace :admin do 44 | # # Directs /admin/products/* to Admin::ProductsController 45 | # # (app/controllers/admin/products_controller.rb) 46 | # resources :products 47 | # end 48 | 49 | # You can have the root of your site routed with "root" 50 | # just remember to delete public/index.html. 51 | # root :to => 'welcome#index' 52 | 53 | # See how all your routes lay out with "rake routes" 54 | 55 | # This is a legacy wild controller route that's not recommended for RESTful applications. 56 | # Note: This route will make all actions in every controller accessible via GET requests. 57 | # match ':controller(/:action(/:id(.:format)))' 58 | end 59 | -------------------------------------------------------------------------------- /spec/dummy/lib/assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dnagir/ios-checkboxes/b6fc021e323c0393567442fda085d028d9c09948/spec/dummy/lib/assets/.gitkeep -------------------------------------------------------------------------------- /spec/dummy/log/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dnagir/ios-checkboxes/b6fc021e323c0393567442fda085d028d9c09948/spec/dummy/log/.gitkeep -------------------------------------------------------------------------------- /spec/dummy/public/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The page you were looking for doesn't exist (404) 5 | 17 | 18 | 19 | 20 | 21 |
22 |

The page you were looking for doesn't exist.

23 |

You may have mistyped the address or the page may have moved.

24 |
25 | 26 | 27 | -------------------------------------------------------------------------------- /spec/dummy/public/422.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The change you wanted was rejected (422) 5 | 17 | 18 | 19 | 20 | 21 |
22 |

The change you wanted was rejected.

23 |

Maybe you tried to change something you didn't have access to.

24 |
25 | 26 | 27 | -------------------------------------------------------------------------------- /spec/dummy/public/500.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | We're sorry, but something went wrong (500) 5 | 17 | 18 | 19 | 20 | 21 |
22 |

We're sorry, but something went wrong.

23 |

We've been notified about this issue and we'll take a look at it shortly.

24 |
25 | 26 | 27 | -------------------------------------------------------------------------------- /spec/dummy/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dnagir/ios-checkboxes/b6fc021e323c0393567442fda085d028d9c09948/spec/dummy/public/favicon.ico -------------------------------------------------------------------------------- /spec/dummy/script/rails: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. 3 | 4 | APP_PATH = File.expand_path('../../config/application', __FILE__) 5 | require File.expand_path('../../config/boot', __FILE__) 6 | require 'rails/commands' 7 | -------------------------------------------------------------------------------- /spec/ios-checkboxes_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe "iOS Checkboxes assets" do 4 | 5 | subject { ::Rails.application.assets } 6 | 7 | it { should serve "ios-checkboxes.js" } 8 | it { should serve "ios-checkboxes.css" } 9 | 10 | %w{on off slider slider_center slider_left slider_right}.each do |image_name| 11 | it { should serve "ios-checkboxes/#{image_name}.png" } 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /spec/javascripts/ios-checkboxes_spec.js.coffee: -------------------------------------------------------------------------------- 1 | #= require ios-checkboxes 2 | 3 | describe "iOS Checkboxes", -> 4 | 5 | iphonify = (rootClass='') -> 6 | setFixtures "
" 7 | check = $("#box") 8 | check.iphoneStyle() 9 | check.parent() 10 | 11 | simulateSwitch = (container) -> 12 | # This sends the up/down events to the element simulating that the button is pressed 13 | container.trigger $.Event 'mousedown', pageX: 1 14 | container.trigger $.Event 'mouseup', pageX: 1 15 | 16 | it "should have jQuery extensions", -> 17 | expect(jQuery.fn.iphoneStyle).toBeTruthy() 18 | 19 | it "should be able to switch with mouse", -> 20 | container = iphonify() 21 | input = container.find ':checkbox' 22 | initialVal = input.prop 'checked' 23 | 24 | simulateSwitch container 25 | expect( input.prop 'checked' ).toBe not initialVal 26 | 27 | simulateSwitch container 28 | expect( input.prop 'checked' ).toBe initialVal 29 | 30 | 31 | it "should apply css classes to the on/off button", -> 32 | wrap = iphonify() 33 | expect(wrap).toBe ".iPhoneCheckContainer" 34 | 35 | it "should apply styles for the checkboxes from the CSS", -> 36 | wrap = iphonify() 37 | # Make sure some basic CSS has been applied. 38 | # It's a basic test to make sure the CSS is actually loaded 39 | expect(wrap.css 'height') .toBe '27px' 40 | expect(wrap.css 'position') .toBe 'relative' 41 | expect(wrap.css 'cursor') .toBe 'pointer' 42 | expect(wrap.find('.iPhoneCheckHandle').css 'background-image').toMatch /ios-checkboxes/ 43 | 44 | it "should allow customizing the styles", -> 45 | wrap = iphonify('custom') 46 | label = wrap.find('label') 47 | handle = wrap.find('.iPhoneCheckHandle') 48 | expect(wrap.css 'height') .toBe '33px' 49 | expect(label.css 'height') .toBe '33px' 50 | expect(label.css 'line-height') .toBe '30px' 51 | expect(label.css 'font-size') .toBe '30px' 52 | expect(handle.css 'background-image') .toMatch /custom-path/ 53 | -------------------------------------------------------------------------------- /spec/javascripts/spec.css: -------------------------------------------------------------------------------- 1 | /* 2 | * =require ios-checkboxes 3 | * =require_tree ./support 4 | */ 5 | -------------------------------------------------------------------------------- /spec/javascripts/spec.js.coffee: -------------------------------------------------------------------------------- 1 | #=require jquery 2 | #=require_tree ./ 3 | -------------------------------------------------------------------------------- /spec/javascripts/support/custom-theme.css.sass: -------------------------------------------------------------------------------- 1 | @import "./ios-checkboxes/mixins" 2 | .custom 3 | $iphone-style-height: 33px 4 | $iphone-style-font-size: 30px 5 | $iphone-style-images-path: 'custom-path' 6 | +iphone-style 7 | 8 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | # Configure Rails Environment 2 | ENV["RAILS_ENV"] = "test" 3 | 4 | require File.expand_path("../dummy/config/environment.rb", __FILE__) 5 | require "rails/test_help" 6 | 7 | Rails.backtrace_cleaner.remove_silencers! 8 | 9 | # Load support files 10 | Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f } 11 | -------------------------------------------------------------------------------- /spec/support/asset_matchers.rb: -------------------------------------------------------------------------------- 1 | 2 | RSpec::Matchers.define :serve do |asset_name| 3 | match do |sprockets| 4 | !!sprockets[asset_name] 5 | end 6 | 7 | failure_message_for_should do |sprockets| 8 | "expected #{asset_name} to be served, but it wasn't" 9 | end 10 | 11 | failure_message_for_should_not do |sprockets| 12 | "expected #{asset_name} NOT to be served, but it was" 13 | end 14 | 15 | description do 16 | "serve #{asset_name}" 17 | end 18 | end 19 | 20 | RSpec::Matchers.define :contain do |content| 21 | match do |asset| 22 | asset.to_s.include? content 23 | end 24 | 25 | failure_message_for_should do |asset| 26 | "expected #{asset.logical_path} to contain #{content}" 27 | end 28 | 29 | failure_message_for_should_not do |asset| 30 | "expected #{asset.logical_path} to NOT contain #{content}" 31 | end 32 | 33 | description do 34 | "contain '#{content}'" 35 | end 36 | end 37 | 38 | --------------------------------------------------------------------------------