2016-03-25 6 views
0

Bu işlemlerle, açılışta summernote ile özel düğmeler kullanmak benim id textarea olsun: (tamamlandı)summernote

  • tıklama özel düğme (yapıldı) ajax içerikli
  • açık modal
  • kullanıcı seçen bir textarea öğe (yapıldı)
  • modal çağrı geri arama düğmesi param ve yakın (tamamlandı)
  • fonksiyon geri arama bağlantısını ekle
(tamamlandı)

Peki, sorun nedir?

Dinamik olmak için textarea kimliğini geri arama işlevinde kullanmak istiyorum (son işleve bakın).

Soru: textarea kimliğini bağlamdan alabilir miyim? Başka bir yolla mı? (config.log dosyasında (context) bulunamıyorum;)

Ve soru 2: imleç konumu nasıl alınır? bağlantım ilk sırada eklendi.

<textarea id="description"></textarea> 
<script> 
summernote.run('description', 'full'); 
</script> 

cevap

0

var summernote = { 

    run: function(id, type) { 
     if(type && type === 'full') { 
      this.full(id); 
     } else { 
      this.simple(id); 
     } 
    }, 

    simple: function(id) { 
     // todo 
    }, 

    full: function(id) { 
     var summernote_params = { height:300, 
            lang: 'fr-FR', 
            toolbar: [ 
              ['misc', ['undo', 'redo']], 
              ['style', ['bold', 'italic', 'underline', 'clear']], 
              ['font', ['superscript', 'subscript']], 
              ['para', ['ul', 'ol']], 
              ['mybuttons', ['docimage', 'docdocument']], 
              ], 
            buttons: { 
              docimage: summernote.docImage, 
              docdocument: summernote.docDocument, 
              }, 
           }; 
     $('#'+id).summernote(summernote_params); 
    }, 

    docImage: function(context) { 
     var ui = $.summernote.ui; 
     var button = ui.button({ 
      contents: '<i class="fa fa-file-image-o"></i>', 
      tooltip: 'Insert image', 
      click: function() { 
       documents.run({filter:'image', callback:[summernote.docImageCallback, context]}); 
      } 
     }); 
     return button.render(); 
    }, 

    docImageCallback: function(context, doc) { 
     context.invoke('editor.insertImage', doc.url); 
    }, 

    docDocument: function(context) { 
     var ui = $.summernote.ui; 
     var button = ui.button({ 
      contents: '<i class="fa fa-file-o"></i>', 
      tooltip: 'Insert file', 
      click: function() { 
       documents.run({filter:'document', callback:[summernote.docDocumentCallback, context]}); 
      } 
     }); 
     return button.render(); 
    }, 

    docDocumentCallback: function(context, doc) { 
     // here i want to get id dynamically 
     $('#description').summernote('createLink', { 
      text: doc.name, 
      url: doc.url, 
      newWindow: true 
     }); 
    }, 

} 

Ve çağrı Yani her sorun için bir çözüm buldum.

Init'teki paramlar, bağlam içinde gönderilir.

var summernote = { 

... 

full: function(id) { 
    var summernote_params = { id: id, // <-- set id in context, (cutsom data) 
           height: 300, 
           lang: 'fr-FR', 
           toolbar: [ 
             ['misc', ['undo', 'redo']], 
             ['style', ['bold', 'italic', 'underline', 'clear']], 
             ['font', ['superscript', 'subscript']], 
             ['para', ['ul', 'ol']], 
             ['mybuttons', ['docimage', 'docdocument']], 
             ], 
           buttons: { 
             docimage: summernote.docImage, 
             docdocument: summernote.docDocument, 
             }, 
          }; 
    $('#'+id).summernote(summernote_params); 
}, 

... 

docDocumentCallback: function(context, doc) { 
    var id = context.options.id; // <-- get id from context 
    $('#'+id).summernote('createLink', { 
     text: doc.name, 
     url: doc.url, 
     newWindow: true 
    }); 
}, 

} 

Ve dış çağrısı ile imleç konumunu korumak için, sadece pozisyon kaydetmek ve geri arama işlevi ayarlayın: bağlamında id almak için ben sadece init eklemek

var summernote = { 

... 

docDocument: function(context) { 
    var ui = $.summernote.ui; 
    var button = ui.button({ 
     contents: '<i class="fa fa-file-o"></i>', 
     tooltip: app_i18n.summernote_document, 
     click: function() { 
      context.invoke('editor.saveRange'); // <-- save position cursor 
      documents.run({filter:'document', callback:[summernote.docDocumentCallback, context]}); 
     } 
    }); 
    return button.render(); 
}, 

docDocumentCallback: function(context, doc) { 
    context.invoke('editor.restoreRange'); // <-- set position cursor to the last save 
    if(context.options.id) { 
     $('#'+context.options.id).summernote('createLink', { 
      text: doc.name, 
      url: doc.url, 
      newWindow: true 
     }); 
    } 
}, 

}