form.js 1.2 KB

1234567891011121314151617181920212223242526272829303132
  1. (function (thread) {
  2. var id = thread ? thread.id : undefined
  3. , local = thread ? (thread.local || {}) : ($.state().local || {});
  4. var containerClass = id ? '.replyForm' : '.submitForm'
  5. , textAreaId = id ? '#replyText_' + id : '#submitText'
  6. , fileFieldId = id ? '#replyFile_' + id : '#submitFile'
  7. , formId = id ? '#replyForm_' + id : '#submitForm'
  8. , buttonText = id ? 'reply' : 'submit';
  9. var media = $.h(".mediaUploader", local.file
  10. ? [ $.h(".mediaUploaderPreview", _.media(
  11. { service: "blob"
  12. , type: local.file.type
  13. , src: URL.createObjectURL(local.file) }))
  14. , $.h(".mediaUploaderCancel",
  15. { onclick: $.emit("media/remove", id) }, "remove")
  16. , local.uploadProgress
  17. ? $.h(".mediaUploaderProgress", local.uploadProgress + "%")
  18. : null ]
  19. : $.h(".mediaUploaderAdd",
  20. { onclick: $.emit("media/select", id) },
  21. "upload (" + $.options.upload.type + ")"))
  22. return $.h("form" + containerClass + formId,
  23. [ media
  24. , $.h("textarea" + textAreaId)
  25. , $.h("button", { onclick: $.emit('post', id) }, buttonText) ])
  26. })