From 9ddd187088dda5835708a5eb9838a6749462dc3d Mon Sep 17 00:00:00 2001 From: Andrew Otto Date: Fri, 13 Apr 2012 11:02:44 -0400 Subject: [PATCH] Adding event handler to select permalink text on focus --- lib/graph/graph-display-view.co | 24 +++++++++++++++++------- lib/template/graph-display.jade | 4 ++-- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/lib/graph/graph-display-view.co b/lib/graph/graph-display-view.co index 00f3ec2..b5c241a 100644 --- a/lib/graph/graph-display-view.co +++ b/lib/graph/graph-display-view.co @@ -32,14 +32,15 @@ GraphDisplayView = exports.GraphDisplayView = BaseView.extend do # {{{ className : 'graph graph-display' template : require 'kraken/template/graph-display' - # events: - # 'click .redraw-button' : 'stopAndRender' - # 'click .load-button' : 'load' - + events: + # Select the whole permalink URI text when it receives focus. + 'focus .graph-permalink input' : 'onPermalinkFocus' + # 'click .redraw-button' : 'stopAndRender' + # 'click .load-button' : 'load' + data : {} ready : false - - + constructor: function GraphDisplayView BaseView ... @@ -259,7 +260,16 @@ GraphDisplayView = exports.GraphDisplayView = BaseView.extend do # {{{ # console.log "Graph.changed( options ) ->\n\tchanges: #{JSON.stringify changes}\n\toptions: #{JSON.stringify options}" #"\n\t^opts: #{JSON.stringify _.intersection _.keys(changes), _.keys(options)}" @chart?.updateOptions file:that if changes?.dataset - + /** + * Selects the graph permalink input field. + */ + onPermalinkFocus: (evt) -> + # defer to allow the select() to be the + # last action that happens. If we don't + # defer, the focusing click will + # unselect the text. + _.defer( ~> @$el.find '.graph-permalink input' .select() ) + # Needed because (sigh) _.debounce returns undefined stopAndRender: -> @render ... diff --git a/lib/template/graph-display.jade b/lib/template/graph-display.jade index efecac2..caa98c5 100644 --- a/lib/template/graph-display.jade +++ b/lib/template/graph-display.jade @@ -15,8 +15,8 @@ section.graph.graph-display(id=view.id) .span8 .graph-permalink - a(href='#{model.toLink()}') Permalink: - input.span6(value='#{model.toPermalink()}') + a(href="#{model.toLink()}") Permalink: + input.span6(value="#{model.toPermalink()}", readonly="readonly") //- .graph-notes -- 1.7.0.4