From 232b02a082f9739601e57e06c5545b2ef9ff273b Mon Sep 17 00:00:00 2001 From: Leo Horie Date: Sun, 6 Apr 2014 22:09:20 -0400 Subject: [PATCH] fix autocompleter example in docs --- archive/v0.1.3/components.html | 6 +-- archive/v0.1.3/mithril.min.zip | Bin 20819 -> 20819 bytes docs/components.md | 78 ++++++++++++++++----------------- 3 files changed, 42 insertions(+), 42 deletions(-) diff --git a/archive/v0.1.3/components.html b/archive/v0.1.3/components.html index ef505066..4d5dea0e 100644 --- a/archive/v0.1.3/components.html +++ b/archive/v0.1.3/components.html @@ -126,17 +126,17 @@ autocompleter.controller = function(data, getter) { this.change = function(value) { this.value(value); - var data = value === "" ? [] : data.filter(function(item) { + var list = value === "" ? [] : data.filter(function(item) { return this.getter(item).toLowerCase().indexOf(value.toLowerCase()) > -1; }, this); - this.data(data); + this.data(list); }; //this method is called when an option is selected. It triggers an `onchange` event this.select = function(value) { this.value(value); this.data([]); - if (this.onchange) this.onchange({target: {value: value}}); + if (this.onchange) this.onchange({currentTarget: {value: value}}); }; } diff --git a/archive/v0.1.3/mithril.min.zip b/archive/v0.1.3/mithril.min.zip index f41f490c61fb87decdbacaf69b229affef628fab..263ab5e3416af8bc83736cf081dc8224c927b7f2 100644 GIT binary patch delta 45 vcmcb-i1G3wMxFp~W)?065Rl!tk>|M_lkCRLU*&Ea0_n+@0<1t3U!W@hKtT?j delta 45 vcmcb-i1G3wMxFp~W)?065cs)hBhPa=rk{&8f0es!2&5-p3a|oEe1Wb2cJUF> diff --git a/docs/components.md b/docs/components.md index f6667867..6be76e8a 100644 --- a/docs/components.md +++ b/docs/components.md @@ -87,40 +87,40 @@ Applications often reuse rich UI controls that aren't provided out of the box by var autocompleter = {}; autocompleter.controller = function(data, getter) { - //binding for the text input - this.value = m.prop(""); - //store for the list of items - this.data = m.prop([]); - - //method to determine what property of a list item to compare the text input's value to - this.getter = getter; - - //this method changes the relevance list depending on what's currently in the text input - this.change = function(value) { - this.value(value); - - var data = value === "" ? [] : data.filter(function(item) { - return this.getter(item).toLowerCase().indexOf(value.toLowerCase()) > -1; - }, this); - this.data(data); - }; - - //this method is called when an option is selected. It triggers an `onchange` event - this.select = function(value) { - this.value(value); - this.data([]); - if (this.onchange) this.onchange({target: {value: value}}); - }; + //binding for the text input + this.value = m.prop(""); + //store for the list of items + this.data = m.prop([]); + + //method to determine what property of a list item to compare the text input's value to + this.getter = getter; + + //this method changes the relevance list depending on what's currently in the text input + this.change = function(value) { + this.value(value); + + var list = value === "" ? [] : data.filter(function(item) { + return this.getter(item).toLowerCase().indexOf(value.toLowerCase()) > -1; + }, this); + this.data(list); + }; + + //this method is called when an option is selected. It triggers an `onchange` event + this.select = function(value) { + this.value(value); + this.data([]); + if (this.onchange) this.onchange({currentTarget: {value: value}}); + }; } autocompleter.view = function(ctrl, options) { - if (options) ctrl.onchange = options.onchange; - return [ - m("input", {oninput: m.withAttr("value", ctrl.change.bind(ctrl)), value: ctrl.value()}), - ctrl.data().map(function(item) { - return m("div", {data: ctrl.getter(item), onclick: m.withAttr("data", ctrl.select.bind(ctrl))}, ctrl.getter(item)); - }) - ]; + if (options) ctrl.onchange = options.onchange; + return [ + m("input", {oninput: m.withAttr("value", ctrl.change.bind(ctrl)), value: ctrl.value()}), + ctrl.data().map(function(item) { + return m("div", {data: ctrl.getter(item), onclick: m.withAttr("data", ctrl.select.bind(ctrl))}, ctrl.getter(item)); + }) + ]; } @@ -129,17 +129,17 @@ autocompleter.view = function(ctrl, options) { var dashboard = {} dashboard.controller = function() { - this.names = m.prop([{id: 1, name: "John"}, {id: 2, name: "Bob"}, {id: 2, name: "Mary"}]); - this.autocompleter = new autocompleter.controller(this.names(), function(item) { - return item.name; - }); + this.names = m.prop([{id: 1, name: "John"}, {id: 2, name: "Bob"}, {id: 2, name: "Mary"}]); + this.autocompleter = new autocompleter.controller(this.names(), function(item) { + return item.name; + }); }; dashboard.view = function(ctrl) { - //assuming there's an element w/ id = "example" somewhere on the page - return m("#example", [ - new autocompleter.view(ctrl.autocompleter, {onchange: m.withAttr("value", console.log)}), - ]); + //assuming there's an element w/ id = "example" somewhere on the page + return m("#example", [ + new autocompleter.view(ctrl.autocompleter, {onchange: m.withAttr("value", console.log)}), + ]); };