 
   focus: =>
     @inEdition = true
-    @$p.text "" if @$p.text() == App.Postit.defaultTitle
+    @p.textContent = "" if @p.textContent == App.Postit.defaultTitle
     true
 
   blur: =>
     @inEdition = false
-    @model.set title: App.Postit.defaultTitle if @$p.text() == ''
+    @model.set title: App.Postit.defaultTitle if @p.textContent == ''
     true
 
   updateTitle: (e) =>
-    title = @$p.text()
+    title = @p.textContent
     return if title == ''
     return if title == @model.get('title')
     @model.set color: '0b0b0b' if title == 'Mathilde'

    @

  buildSelector: ->
    @$p = @$ 'p'
    @shadow = @el.querySelector '.shadow'
    @gradient = @el.querySelector '.gradient'
    @gradient.draggable = true
    @el.querySelector('.resize').draggable = true


  update: =>
    return if @inEdition
    @p.textContent = @model.get 'title'
    setTimeout @adjustFontSize, 0
    @

  # TODO make this function a jQuery plugin
  adjustFontSize: =>
    size = 3
    w = _(@p.textContent.split(/\s+/)).max (s) -> s.length
    c = @p.cloneNode true
    c.textContent = w
    c.style.display = 'inline'
    c.style.visibility = 'hidden'
    c.style.fontSize = "#{size}em"
    document.body.appendChild c
    max = @model.get('size').w * @viewport.get('zoom')
    while c.scrollWidth > max
      break if size < 0.4
      size *= 0.85
      c.style.fontSize = "#{size.toFixed 1}em"
    document.body.removeChild c
    @p.style.fontSize = "#{size.toFixed 1}em"
    max = @model.get('size').h * @viewport.get('zoom')
    while @p.scrollHeight > max
      break if size < 0.4
      size *= 0.85
      @p.style.fontSize = "#{size.toFixed 1}em"
    @

  colorize: =>
    c = App.Colors.mix (@model.get 'color'), '#000000', 0.9
    gradient = "linear-gradient(top, #{c} 0%, ##{@model.get 'color'} 75%)"
    @gradient.style.background = "-moz-#{gradient}"
    @gradient.style.background = "-webkit-#{gradient}"
    @gradient.style.background = gradient
    @el.classList.add 'reverse' if @model.get('color')[0] == '0'
    @

