Home

Awesome

Summernote gallery

summernote-gallery extension/plugin/module for summernote WYSIWYG, provides a bootstrap image-gallery modal to select images from the server and add them to the summernote editor with the real path to the server instead of using base64 encoding.

For a complete module with more user-friendly components. see Summernote bricks

Demo

Demo link: http://eissasoubhi.github.io/summernote-gallery <br><br>

Summernote gallery demo

Installing

<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" >
<link href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/summernote@0.8.18/dist/summernote.min.css" rel="stylesheet">

<div id="summernote"></div>

<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/summernote@0.8.18/dist/summernote.min.js"></script>
<!-- summernote-gallery -->
<script src="dist/summernote-gallery.min.js" type="text/javascript"></script>
$('#summernote').summernote({
        toolbar: [
            // ['insert', ['picture', 'link', 'video', 'table', 'hr', 'summernoteGallery']],
            // ['font style', ['fontname', 'fontsize', 'color', 'bold', 'italic', 
            //'underline', 'strikethrough', 'superscript', 'subscript', 'clear']],
            // ['paragraph style', ['style', 'ol', 'ul', 'paragraph', 'height']],
            // ['misc', ['fullscreen', 'codeview', 'undo', 'redo', 'help']]
            ['extensions', ['summernoteGallery']],
        ],
        summernoteGallery: {
            source: {
                // data: [],
                url: 'http://eissasoubhi.github.io/summernote-gallery/server/example.json',
                responseDataKey: 'data',
                nextPageKey: 'links.next',
            },
            modal: {
                loadOnScroll: true,
                maxHeight: 300,
                title: "La galerie d'images",
                close_text: 'Fermer',
                ok_text: 'Ajouter',
                selectAll_text: 'Sélectionner Tout',
                deselectAll_text: 'Désélectionner Tout',
                buttonLabel: '<i class="fa fa-file-image-o"></i> Gallery'
            }
        }
    });

I used a json file server/example.json as the source.url just for the demo, for a practical example you can check out the PHP file server/example.php.

Options

The module has two main options: source and modal:<br> The source option has sub-options that handle data and ajax requests.<br> The modal option has sub-options that deal with the bootsrap modal.<br>

Sub-options:

Optiondescriptiondefaulttypeexample
sourceThis option is the parent of the following options:object
source.dataArray of objects with 'src' and 'title' properties[]array[{<br> "id": "1",<br> "url": "https://picsum.photos/id/40/200/200",<br> "title": "a galerie test"<br>}, {<br> "id": "2",<br> "url": "https://picsum.photos/id/50/200/200",<br> "title": "a galerie test"<br>}]
source.urlA full valid URL. the response of the URL must have data property that holds the data.<br> The data format is the same as the source.data's. the data property name can be changed with the source.responseDataKey option.<br> If modal.loadOnScroll is set to true, in addition to data, the response is expected to have links.next property for the next page URL, this property name can also be changed with the source.nextPageKey option.nullstringURL example: http://mywebsite.com/api/images?page=1 <br> Response example:<br> <br>{<br> "data": [{<br> "id": "1",<br> "url": "https://picsum.photos/id/40/200/200",<br> "title": "a galerie test"<br> }, {<br> "id": "2",<br> "url": "https://picsum.photos/id/50/200/200",<br> "title": "a galerie test"<br> }],<br> "links": {<br> "next": "http://mywebsite.com/api/images?page=2"<br> }<br>}
source.responseDataKeyThe property name that holds the data array from source.url.<br> For sub-properties, use dot notation, eg: "data.key.subkey"datastringIf the source.responseDataKey option value is "data.items",<br> The source.url response is expected to be: <br>{<br> "data": {<br> "items": [{<br> "id": "1",<br> "url": "https://picsum.photos/id/40/200/200",<br> "title": "a galerie test"<br> }, {<br> "id": "2",<br> "url": "https://picsum.photos/id/50/200/200",<br> "title": "a galerie test"<br> }]<br> },<br> "links": {<br> "next": "...."<br> }<br>}
source.nextPageKeyThe property name that holds the next page link from source.url.<br> For sub-properties, use dot notation, eg: "data.key.subkey"links.nextstringIf the source.nextPageKey option value is "next_page",<br> the source.url response is expected to be: <br>{<br> "data": [],<br> "next_page": "http://mywebsite.com/api/images?page=2"<br>}
source.formaterA callback function to format the data array (data from source.data) before handling it by the module, it must return an array of objects of type {id: "11", url: '', title: ''}(data, page, response) => {<br> return data<br>}function(data, page, response) => {<br> return data.map(image => {<br> return {<br> id: image.id<br> url: image.src+'?v=' + Date.now(),<br> title: image.title<br> }<br> })<br>}
modalThis option is the parent of the following options:object
modal.loadOnScrollReloads the next page data when the modal scroll is near to the bottom.<br> The module reloads the next page data using source.nextPageKey value to extract the next page link from the last source.url response, that means when modal.loadOnScroll is set to true, every request must provide the link to the next page, unless it's the last page, in that case, the value of the next page link has to be null or unset.falsebooleantrue
modal.heightThe modal body height500integer300
modal.titleThe modal titlesummernote image gallerystring
modal.closeTextThe modal close button textClosestringFermer
modal.saveTextThe modal save button textAddstringAjouter
modal.selectAllTextThe modal select-all button textSelect allstringSélectionner Tout
modal.deselectAllTextThe modal deselect-all button textDeselect allstringDésélectionner Tout
modal.messageContainerClassthe html element class containing the modal messagessnb-modal-messagestring
modal.selectClassNamethe class added to the selected image on the modalselected-imgstring
modal.validationsvalidation rules applied to each snb-brick data property before modal save action{<br> selectedImages: {<br> required: {<br> message: 'At least one image must be selected!'<br> }<br> }<br>}object
modal.validations.selectedImagesthe selected images from the modal{<br> required: {<br> message: 'At least one image must be selected!'<br> }<br>}object
buttonLabelThe text displayed on the plugin button, it accepts HTMLSN GallerystringMy Button

Feel free to modify the source file to suit your needs.

Contribution || Edit

Requirements: node v16

To run the plugin on local, head to the project root folder and run:

  1. npm install
  2. npm run start to start the project on 127.0.0.1:9090
  3. npm run dev to start the webpack watch mode
  4. Edit plugin files in the /src folder
  5. npm run build to generate the build in /dist folder

If you found any bugs or have suggestions, dont hesitate to throw it in the issues sections.

For more undestanding of how this module works take a look on the v1 branch or the summernote extension basic sample hello .

License

The contents of this repository is licensed under The MIT License.