From 22aaa24962631d4911ffd30c7ad9b2e1472a94bf Mon Sep 17 00:00:00 2001 From: Will Marshall Date: Wed, 30 Apr 2014 10:57:30 +1000 Subject: [PATCH] Disabling scroll increment/decrement on Number inputs --- .../darkswarm/directives/disable_scroll.js.coffee | 9 +++++++++ app/views/shop/shop/_products.html.haml | 2 ++ app/views/shop/shop/_variant.html.haml | 2 ++ 3 files changed, 13 insertions(+) create mode 100644 app/assets/javascripts/darkswarm/directives/disable_scroll.js.coffee diff --git a/app/assets/javascripts/darkswarm/directives/disable_scroll.js.coffee b/app/assets/javascripts/darkswarm/directives/disable_scroll.js.coffee new file mode 100644 index 0000000000..7c870ab860 --- /dev/null +++ b/app/assets/javascripts/darkswarm/directives/disable_scroll.js.coffee @@ -0,0 +1,9 @@ +Darkswarm.directive "ofnDisableScroll", ()-> + restrict: 'A' + + link: (scope, element, attrs)-> + element.bind 'focus', -> + element.bind 'mousewheel', (e)-> + e.preventDefault() + element.bind 'blur', -> + element.unbind 'mousewheel' diff --git a/app/views/shop/shop/_products.html.haml b/app/views/shop/shop/_products.html.haml index b48317f9e2..57f03632fa 100644 --- a/app/views/shop/shop/_products.html.haml +++ b/app/views/shop/shop/_products.html.haml @@ -49,6 +49,7 @@ %input{type: :number, value: nil, min: 0, + "ofn-disable-scroll" => true, max: "{{product.on_demand && 9999 || product.count_on_hand }}", name: "variants[{{product.master.id}}]", id: "variants_{{product.master.id}}", @@ -58,6 +59,7 @@ %span{"ng-show" => "product.group_buy && (product.variants.length == 0)"} %input{type: :number, min: 0, + "ofn-disable-scroll" => true, max: "{{product.on_demand && 9999 || product.count_on_hand }}", name: "variant_attributes[{{product.master.id}}][max_quantity]", "ng-model" => "product.max_quantity"} diff --git a/app/views/shop/shop/_variant.html.haml b/app/views/shop/shop/_variant.html.haml index fa9b00d5f3..15d5485090 100644 --- a/app/views/shop/shop/_variant.html.haml +++ b/app/views/shop/shop/_variant.html.haml @@ -6,6 +6,7 @@ %input{type: :number, value: nil, min: 0, + "ofn-disable-scroll" => true, max: "{{variant.on_demand && 9999 || variant.count_on_hand }}", name: "variants[{{variant.id}}]", id: "variants_{{variant.id}}", "ng-model" => "variant.quantity"} @@ -13,6 +14,7 @@ %span{"ng-show" => "product.group_buy"} %input{type: :number, min: 0, + "ofn-disable-scroll" => true, max: "{{variant.on_demand && 9999 || variant.count_on_hand }}", name: "variant_attributes[{{variant.id}}][max_quantity]", "ng-model" => "variant.max_quantity"}