Messagebar

    Framework7 comes with special resizealbe toolbar for usage with Messages

    Messagebar layour is pretty simple:

    Where

    • - block with messagebar attachments. Optional
    • **messagebar-sheet** - block with messagebar sheet. Optional

    Messagebar place is very important, it should be inside of page and right before page-content:

    1. <div class="page">
    2. <!-- navbar -->
    3. <div class="navbar">...</div>
    4. <!-- messagebar -->
    5. <div class="toolbar messagebar">...</div>
    6. <!-- page-content/messages-content -->
    7. <div class="page-content messages-content">
    8. ... messages
    9. </div>
    10. </div>
    1. <div class="messagebar-sheet">
    2. <!-- selectable sheet image -->
    3. <label class="checkbox messagebar-sheet-image" style="background-image:url(path/to/image1.png)">
    4. <input type="checkbox">
    5. <i class="icon icon-checkbox"></i>
    6. </label>
    7. <!-- another selectable sheet image -->
    8. <label class="checkbox messagebar-sheet-image" style="background-image:url(path/to/image2.png)">
    9. <input type="checkbox">
    10. <i class="icon icon-checkbox"></i>
    11. </label>
    12. <!-- some custom sheet item -->
    13. <div class="messagebar-sheet-item">
    14. <!-- any custom content here -->
    15. </div>
    16. </div>

    Messages attachments block is designed to display currently attached message items/images:

    Messagebar App Methods

    Now, when we have Messagebar’ HTML, we need to initialize it. We need to use related App’s method:

    Let’s look on list of all available parameters:

    Messagebar Methods & Properties

    So to create Messagebar we have to call:

    1. var messagebar = app.messagebar.create({ /* parameters */ })

    Messagebar will fire the following DOM events on messagebar element and events on app and messagebar instance:

    Messagebar instance emits events on both self instance and app instance. App instance events has same names prefixed with messagebar.

    Messagebar Auto Initialization

    If you don’t need to use Messagebar API and your Messagebar is inside of the page and presented in DOM on moment of page initialization then it can be auto initialized with just adding additional **messagebar-init** class to messagebar element, and all required parameters can be passed using **data-** attributes:

    Parameters that used in camelCase, for example maxHeight, in data- attributes should be used in kebab-case as data-max-height

    1. <div class="page">
    2. <div class="navbar">
    3. <div class="title">Messages</div>
    4. </div>
    5. </div>
    6. <div class="toolbar messagebar">
    7. <div class="toolbar-inner">
    8. <a class="link toggle-sheet" href="#">
    9. <i class="icon f7-icons ios-only">camera_fill</i>
    10. <i class="icon material-icons md-only">camera_alt</i>
    11. </a>
    12. <div class="messagebar-area">
    13. <textarea placeholder="Message"></textarea>
    14. </div>
    15. <a class="link" href="#">Send</a>
    16. </div>
    17. <div class="messagebar-sheet"></div>
    18. </div>
    19. <div class="page-content messages-content">
    20. <div class="messages">
    21. ...
    22. </div>
    23. </div>
    24. </div>
    1. var app = new Framework7();
    2. var $$ = Dom7;
    3. // Init Messages
    4. var messages = app.messages.create({
    5. ...
    6. });
    7. // Init messagebar
    8. var messagebar = app.messagebar.create({
    9. el: '.messagebar',
    10. attachments: []
    11. });
    12. // Available Images
    13. var images = [
    14. 'http://lorempixel.com/300/300/cats/1/',
    15. 'http://lorempixel.com/200/300/cats/2/',
    16. 'http://lorempixel.com/400/300/cats/3/',
    17. 'http://lorempixel.com/300/150/cats/4/',
    18. 'http://lorempixel.com/150/300/cats/5/',
    19. 'http://lorempixel.com/300/300/cats/6/',
    20. 'http://lorempixel.com/300/300/cats/7/',
    21. 'http://lorempixel.com/200/300/cats/8/',
    22. 'http://lorempixel.com/400/300/cats/9/',
    23. 'http://lorempixel.com/300/150/cats/10/'
    24. // Create sheet items
    25. images.forEach(function (image) {
    26. sheetHtml +=
    27. '<label class="checkbox messagebar-sheet-image" style="background-image:url(' + image + ')">' +
    28. '<input type="checkbox">' +
    29. '<i class="icon icon-checkbox"></i>' +
    30. '</label>';
    31. });
    32. $$('.messagebar-sheet').html(sheetHtml);
    33. /*========================
    34. Handle Attachments
    35. ========================*/
    36. function checkAttachments() {
    37. if (messagebar.attachments.length > 0) {
    38. messagebar.attachmentsShow();
    39. messagebar.setPlaceholder('Add comment or Send');
    40. } else {
    41. messagebar.attachmentsHide();
    42. messagebar.setPlaceholder('Message');
    43. }
    44. }
    45. $$('.messagebar-sheet-image input').on('change', function (e) {
    46. var index = $$(e.target).parents('.messagebar-sheet-image').index();
    47. var image = images[index];
    48. if (e.target.checked) {
    49. // Add to attachments
    50. messagebar.attachments.unshift(image)
    51. } else {
    52. // Remove from attachments
    53. messagebar.attachments.splice(messagebar.attachments.indexOf(image), 1);
    54. }
    55. messagebar.renderAttachments();
    56. checkAttachments();
    57. });
    58. messagebar.on('attachmentDelete', function (messagebar, attachmentEl, attachmentIndex) {
    59. var image = messagebar.attachments.splice(attachmentIndex, 1)[0];
    60. messagebar.renderAttachments();
    61. checkAttachments();
    62. // Uncheck in sheet
    63. var imageIndex = images.indexOf(image);
    64. messagebar.$el.find('.messagebar-sheet .checkbox').eq(imageIndex).find('input').prop('checked', false);
    65. });
    66. /*========================
    67. Toggle Sheet
    68. ========================*/
    69. $$('a.toggle-sheet').on('click', function () {
    70. messagebar.sheetToggle();