Adding event handler to select permalink text on focus
authorAndrew Otto <acotto@gmail.com>
Fri, 13 Apr 2012 15:02:44 +0000 (11:02 -0400)
committerAndrew Otto <acotto@gmail.com>
Fri, 13 Apr 2012 15:02:44 +0000 (11:02 -0400)
lib/graph/graph-display-view.co
lib/template/graph-display.jade

index 00f3ec2..b5c241a 100644 (file)
@@ -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 ...
index efecac2..caa98c5 100644 (file)
@@ -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