Knockout action

I use knockout as the main structure in my application, and it should support tablets and mobile devices. Since the structure is built on binding handlers, I wonder how you can achieve a custom binding to actions (for example, swipe your finger across the screen and other specific devices), or can something similar be done?

+6
source share
4 answers

Maybe it's too late, but here is a library that adds a binding binding to knockoutjs: https://github.com/yaroslavya/knockouch

+6
source
  • Create a bindingHandler . Here you give an example of a real project.

     ko.bindingHandlers.swipeSections = { init: function (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) { var elem = $(element); var params = valueAccessor().split('##'); elem.unbind('swipe'); elem.swipe({ swipeLeft: function (event, direction, distance, duration, fingerCount) { //process }, swipeRight: function (event, direction, distance, duration, fingerCount) { //process } }); } 

    };

  • Using the swipe library: https://github.com/mattbryson/TouchSwipe-Jquery-Plugin

     script type="text/javascript" src="scripts/jquery.touchSwipe.js" 
  • Define an element binding

     div id="myid" class="section" data-bind="swipeSections: 'leftPanel##rightPanel'" 
+1
source

There are no built-in bindings for specific frameworks, as knockout.js has no dependencies on any other frameworks. There must be a trivial task to convert your jQuery selector code into binding handlers that reference the @niko link above.

0
source

I don't know if this helps, but here is a pointer.

  • Use a library such as Hammer.js to receive multi-touch actions.
  • Write your own binding handler and call the default event binding for the knockout. something like this for a napkin. (violin author uses tap.js)

http://jsfiddle.net/snaptopixel/spByj/

now everything you do in your html

 <button data-bind="tap:doSomething">Click Me</button> 

where doSomething is a function.

0
source

Source: https://habr.com/ru/post/914888/


All Articles