Skip to content

Commit

Permalink
Style preview container with image plugin data
Browse files Browse the repository at this point in the history
  • Loading branch information
lundberg committed Sep 24, 2013
1 parent f63f231 commit 0e7660a
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 9 deletions.
23 changes: 21 additions & 2 deletions djedi/static/djedi/plugins/img/js/img.coffee
Expand Up @@ -68,6 +68,11 @@ class CropTool

@$img.trigger 'crop:preview', @previewContainer

setPreviewAttributes: (attrs) ->
if not @preview?
@createPreview()
@previewContainer.attr attr, value for attr, value of attrs

resizePreview: =>
if not @preview?
@createPreview()
Expand Down Expand Up @@ -247,6 +252,7 @@ class window.ImageEditor extends window.Editor

# Field events
$('.dimension').on 'keyup', @resizeImage
$('#html-pane input').on 'keyup', => @updateImageAttributes()
@ratioButton.on 'click', @toggleAspectRatio
@ratioButton.tooltip()

Expand All @@ -256,12 +262,13 @@ class window.ImageEditor extends window.Editor

if node and node.data
@dropzone.dragDrop()
data = node.data
@updateForm node.data
@renderThumbnail node.data.url
else
@updateForm filename: '', width: '', height: '', id: '', 'class': '', alt: ''
@removeThumbnail()
data = filename: '', width: '', height: '', id: '', 'class': '', alt: ''

updateForm: (data) ->
# $('#filename').html node.data.filename
$("input[name='data[filename]']").val data.filename
$("input[name='data[width]']").val data.width
Expand Down Expand Up @@ -289,6 +296,7 @@ class window.ImageEditor extends window.Editor
# Initialize crop tool
$image.on 'crop:preview', (event, html) => @triggerRender html
@crop = new CropTool $image
@updateImageAttributes()
@crop.resizePreview()

removeThumbnail: ->
Expand Down Expand Up @@ -332,6 +340,17 @@ class window.ImageEditor extends window.Editor

@crop.resizePreview()
@crop.cropPreview()
@trigger 'node:resize'

getHtmlFields: ->
attrs = {}
for attr in ['id', 'class', 'alt']
attrs[attr] = $("input[name='data[#{attr}]']").val()
attrs

updateImageAttributes: ->
@crop.setPreviewAttributes @getHtmlFields()
@trigger 'node:resize'

toggleAspectRatio: =>
ratioInactive = @ratioButton.hasClass 'active'
Expand Down
50 changes: 43 additions & 7 deletions djedi/static/djedi/plugins/img/js/img.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0e7660a

Please sign in to comment.