-
Notifications
You must be signed in to change notification settings - Fork 6
Issues/8 #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Issues/8 #23
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,18 @@ | ||
| block('comments').content()(function() { | ||
| return this.data.comments.map(function(comment) { | ||
| return { | ||
| block: 'comment', | ||
| comment: comment | ||
| }; | ||
| }); | ||
| var comments = this.data.comments; | ||
|
|
||
| return [ | ||
| comments.map(function(comment) { | ||
| return { | ||
| block: 'comment', | ||
| comment: comment | ||
| }; | ||
| }), | ||
| { | ||
| elem: 'add-form', | ||
| content: { | ||
| block: 'forum-form' | ||
| } | ||
| } | ||
| ] | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,3 +21,8 @@ | |
|
|
||
| background-color: #e1e1e1; | ||
| } | ||
|
|
||
| .comments__add-form { | ||
| padding: 30px 0; | ||
| background-color: #fff; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| ({ | ||
| shouldDeps: 'comment' | ||
| shouldDeps: ['comment', 'forum-form'] | ||
| }) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| block('forum-form')( | ||
| tag()('form'), | ||
| js()(true) | ||
| ); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| block('forum-form').content()(function() { | ||
| var i18n = this.require('i18n'); | ||
|
|
||
| return [ | ||
| { | ||
| elem: 'forum-create', | ||
| content: [ | ||
| { | ||
| elem: 'header', | ||
| content: { | ||
| block: 'radio-group', | ||
| mods: { theme: 'islands', size: 'm', type: 'button' }, | ||
| name: 'radio-button', | ||
| val: 1, | ||
| options: [ | ||
| { | ||
| val: 1, | ||
| icon: { | ||
| block: 'icon', | ||
| mods: { view: 'markdown', size: '24' } | ||
| } | ||
| }, | ||
| { | ||
| val: 2, | ||
| disabled: true, | ||
| icon: { | ||
| block: 'icon', | ||
| mods: { view: 'preview', size: '24' } | ||
| } | ||
| } | ||
| ] | ||
| } | ||
| }, | ||
| { | ||
| elem: 'body', | ||
| content: [ | ||
| { | ||
| block: 'textarea', | ||
| name: 'body', | ||
| mods: { theme: 'islands', size: 'l', width: 'available' }, | ||
| mix: [{ block: 'forum-form', elem: 'view' }, { block: 'forum-form', elem: 'view_visible' }], | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. element name can't contain underscores as they separate names from modifiers
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how can I mix a block with element which has modifier(so, I wont to have like this: forum-form__view_visible)? I could not find this decision :(
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| placeholder: i18n(this.block, 'leaveMessage') | ||
| }, | ||
| { | ||
| elem: 'preview', | ||
| mix: { block: 'forum-form', elem: 'view' } | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| }, | ||
| { | ||
| elem: 'submit', | ||
| content: { | ||
| block: 'button', | ||
| mods: { theme: 'islands', size: 'm', view: 'action' }, | ||
| text: i18n(this.block, 'comment') | ||
| } | ||
| } | ||
| ] | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| .forum-form__forum-create { | ||
| margin-left: 120px; | ||
| } | ||
|
|
||
| .forum-form .forum-form__view { | ||
| display: none; | ||
| width: 100%; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| min-height: 150px; | ||
| margin-top: 10px; | ||
| resize: vertical; | ||
| } | ||
|
|
||
| .forum-form .forum-form__view_visible { | ||
| display: inline-block; | ||
| } | ||
|
|
||
| .forum-form__preview { | ||
| box-sizing: border-box; | ||
| border: 1px solid #e5e5e5; | ||
| background-color: #f5f5f5; | ||
| padding: 5px 20px; | ||
| } | ||
|
|
||
| .forum-form__body { | ||
| margin-top: 10px; | ||
| } | ||
|
|
||
| .forum-form__submit { | ||
| margin-left: 120px; | ||
| padding-top: 20px; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| ({ | ||
| shouldDeps: [ | ||
| { | ||
| block: 'icon', | ||
| mods: { view: ['markdown', 'preview'], size: '24' } | ||
| }, | ||
| { | ||
| block: 'radio-group', | ||
| mods: { | ||
| theme: 'islands', | ||
| size: 'm', | ||
| type: 'button' | ||
| } | ||
| }, | ||
| { | ||
| block: 'textarea', | ||
| mods: { | ||
| theme: 'islands', | ||
| size: 'm', | ||
| width: 'available' | ||
| } | ||
| }, | ||
| { | ||
| block: 'button', | ||
| mods: { theme: 'islands', size: 'm', view: 'action' } | ||
| } | ||
| ] | ||
| }) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| module.exports = { | ||
| 'forum-form': { | ||
| leaveMessage: 'Leave a comment', | ||
| comment: 'Comment' | ||
| } | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| module.exports = { | ||
| 'forum-form': { | ||
| leaveMessage: 'Ответить', | ||
| comment: 'Написать' | ||
| } | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| modules.define('forum-form', ['i-bem__dom', 'jquery'], | ||
| function(provide, BEMDOM, $) { | ||
|
|
||
| provide(BEMDOM.decl(this.name, { | ||
| onSetMod: { | ||
| js: { | ||
| inited: function() { | ||
| var textarea = this.findBlockInside('textarea'), | ||
| plainTextButton = this.findBlocksInside('button')[0], | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is not reliable way to find needed blocks. it'd be much better to mix elements of plainTextButton = this.findBlockInside('plain', 'button'),
previewButton = this.findBlockInside('preview', 'button');which means «find button on my own element |
||
| previewButton = this.findBlocksInside('button')[1]; | ||
|
|
||
| textarea.bindTo('keyup', function() { | ||
| $('.textarea').val() ? previewButton.delMod('disabled') : previewButton.setMod('disabled'); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's better to use API of previewButton.setMod('disabled', !!textarea.getVal()); |
||
| }); | ||
|
|
||
| previewButton.bindTo('click', function(){ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use BEM events: |
||
| if( $('.textarea').val() ){ | ||
| $.post('/comment-preview', { data : $('.textarea').val() }) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AJAX error should be handled as well (e.g. no internet connection, etc) |
||
| .then(function(data) { | ||
| $('.textarea').removeClass('forum-form__view_visible'); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BEM API should be used: Almost no direct jQuery selectors are allowed in |
||
| $('.forum-form__preview').addClass('forum-form__view_visible').html(data); | ||
| }); | ||
| } | ||
| }); | ||
|
|
||
| plainTextButton.bindTo('click', function(){ | ||
| $('.textarea').addClass('forum-form__view_visible'); | ||
| $('.forum-form__preview').removeClass('forum-form__view_visible'); | ||
| }); | ||
| } | ||
| } | ||
| } | ||
| })); | ||
|
|
||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| .icon_size_24 { | ||
| background-size: 24px; | ||
| margin: 0 10px; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| .icon_view_markdown { | ||
| background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="208" height="128" viewBox="0 0 208 128"><rect width="198" height="118" x="5" y="5" ry="10" stroke="#000" stroke-width="10" fill="none"/><path d="M30 98V30h20l20 25 20-25h20v68H90V59L70 84 50 59v39zm125 0l-30-33h20V30h20v35h20z"/></svg>'); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's better to keep icons as separate files. build system will inline them automatically |
||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why such strange values? use
markdownandpreview. so it'll be much easier to get the value onchangeevent instead of modifier usage.