From 278ee54b2e3b4cbceb0399d0b52e984420c9fcb6 Mon Sep 17 00:00:00 2001 From: Xuan Sang LE Date: Wed, 21 Mar 2018 11:59:01 +0100 Subject: [PATCH] fix slider --- src/core/BaseEvent.coffee | 6 +++--- src/core/BaseModel.coffee | 6 +++--- src/core/gui.coffee | 4 ++-- src/core/tags/afx-slider.tag | 20 +++++++++++++++++--- src/themes/antos/afx-slider.css | 1 + 5 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/core/BaseEvent.coffee b/src/core/BaseEvent.coffee index 5ef4310..efe7f06 100644 --- a/src/core/BaseEvent.coffee +++ b/src/core/BaseEvent.coffee @@ -16,9 +16,9 @@ # You should have received a copy of the GNU General Public License #along with this program. If not, see https://www.gnu.org/licenses/. class BaseEvent - constructor: (@name) -> + constructor: (@name, @force) -> @prevent = false - preventDefault:()-> - @prevent = true + preventDefault: () -> + @prevent = true if not @force this.OS.GUI.BaseEvent = BaseEvent \ No newline at end of file diff --git a/src/core/BaseModel.coffee b/src/core/BaseModel.coffee index 2c32936..922a331 100644 --- a/src/core/BaseModel.coffee +++ b/src/core/BaseModel.coffee @@ -33,9 +33,9 @@ class BaseModel _GUI.loadScheme p, @, @host quit: (force) -> - evt = new _GUI.BaseEvent("exit") - @onexit(evt) if not force - if force or not evt.prevent + evt = new _GUI.BaseEvent("exit", force) + @onexit(evt) + if not evt.prevent delete @.observable @dialog.quit() if @dialog _PM.kill @ diff --git a/src/core/gui.coffee b/src/core/gui.coffee index a066c50..fe803c0 100644 --- a/src/core/gui.coffee +++ b/src/core/gui.coffee @@ -132,14 +132,14 @@ self.OS.GUI = , __("Open with"), list forceLaunch: (app, args) -> - console.log "This method is used for developing only, please use the launch method instead" + console.warn "This method is used for developing only, please use the launch method instead" _GUI.unloadApp app _GUI.launch app, args unloadApp: (app) -> _PM.killAll app, true ($ _OS.APP[app].style).remove() if _OS.APP[app] and _OS.APP[app].style - _OS.APP[app] = undefined + delete _OS.APP[app] loadApp: (app, ok, err) -> path = "os://packages/#{app}" diff --git a/src/core/tags/afx-slider.tag b/src/core/tags/afx-slider.tag index 860d290..96fc3d9 100644 --- a/src/core/tags/afx-slider.tag +++ b/src/core/tags/afx-slider.tag @@ -10,6 +10,7 @@ this.dragable = eval(opts.dragable) else this.dragable = true + this.onchanging = opts.onchanging this.onchange = opts.onchange //this.rid = $(self.root).attr("data-id") || Math.floor(Math.random() * 100000) + 1 var self = this @@ -20,8 +21,11 @@ self[i] = v[i] else self[k] = v - if(k == "value" && self.onchange) - self.onchange(self.value) + if(k == "value") + { + if(self.onchange) self.onchange(self.value) + if(self.onchanging) self.onchanging(self.value) + } self.update() } self.root.get = function(k) @@ -60,9 +64,10 @@ left = left > maxw?maxw : left self.value = left*self.max/maxw calibrate() - if(self.onchange) self.onchange(self.value) + if(self.onchanging) self.onchanging(self.value) }) $(window).on("mouseup", function(e){ + if(self.onchange) self.onchange(self.value) $(window).unbind("mousemove", null) }) }) @@ -80,6 +85,15 @@ }) enable_dragging() } + $(self.refs.container).click( function(e){ + var offset = $(self.refs.container).offset() + var left = e.clientX - offset.left + var maxw = $(self.refs.container).width() + self.value = left*self.max/maxw + calibrate() + if(self.onchange) self.onchange(self.value) + if(self.onchanging) self.onchanging(self.value) + }) self.root.observable.on("calibrate",function(){ calibrate() }) diff --git a/src/themes/antos/afx-slider.css b/src/themes/antos/afx-slider.css index ef02999..8486a8c 100644 --- a/src/themes/antos/afx-slider.css +++ b/src/themes/antos/afx-slider.css @@ -11,6 +11,7 @@ afx-slider div.container{ background-color: #e6e6e6; position: relative; padding:0; + cursor: pointer; } afx-slider div.progress {