Skip to main content

Template.blog.onRendered(function(){
$('#editor1').trumbowyg(
{
btnsDef: {
        // Create a new dropdown
        image: {
            dropdown: ['insertImage', 'upload'],
            ico: 'insertImage'
        }
    },
    // Redefine the button pane
    btns: [
        ['viewHTML'],
        ['formatting'],
        ['strong', 'em', 'del'],
        ['superscript', 'subscript'],
        //['link'],
        ['insertImage'],
['justifyLeft', 'justifyCenter', 'justifyRight', 'justifyFull'],
        ['unorderedList', 'orderedList'],
        ['horizontalRule'],
        ['removeformat'],
        ['fullscreen']
    ],
    plugins: {
        // Add imagur parameters to upload plugin for demo purposes
        upload: {
            serverPath: 'https://api.imgur.com/3/image',
            fileFieldName: 'image',
            headers: {
                'Authorization': 'Client-ID xxxxxxxxxxxx'
            },
            urlPropertyName: 'data.link'
        }
    }
});
setTimeout(function(){
// <h2>Big monster&nbsp;</h2><p>Kosova long crowing rooster test.</p>/
$('#test').val('test');
},1000);
});
Template.blog.events({
'click #button':function(e){
e.preventDefault();
    // var editor1= $('#test').val();
    // $('#editor1').val(editor1);
    var x ='<div> <div style="text-align:center;margin-left: 40%"> <img id="Ankit" src="https:static.pexels.com/photos/248797/pexels-photo-248797.jpeg" alt="" style="height:100%;width:10%;"></div></div><br><br><p>sdfkldsmdslf;kmsdf</p>';
         $('#editor1').trumbowyg('html',x);

},'click #Ankit':function(e){

// var v = doGetCaretPosition($('#editor1'));
// alert(v);
 },
'click #button1':function(e){
e.preventDefault();
   /* var x ='<div> <div style="text-align:center;margin-left: 40%"> <img id="Ankit" src="https:static.pexels.com/photos/248797/pexels-photo-248797.jpeg" alt="" style="height:100%;width:10%;"></div></div><br><br><p>sdfkldsmdslf;kmsdf</p>';
    x=x+x;
 $('#editor1').trumbowyg('html',x);*/
// var cursorPosition = $('#editor1').prop("selectionStart");
// alert(cursorPosition);
// $('#editor1').trumbowyg('append', 'sometext');


  // var cursorPosition = getCurrentCursorPosition($('#editor1'));
  //  alert(cursorPosition);
  //  var editor  = $('#editor1').val();
  //  alert(editor.length+  " Total length");
  //  var lower = editor.substr(0,cursorPosition);
  //  var upper = editor.substr(lower.length,editor.length);
  //  alert(lower);
  //  alert(upper);
 $('#editor1').trumbowyg('restoreRange');

    // Insert text at the current position
    $('#editor1').trumbowyg('execCmd', {
        cmd: 'insertText',
        param: 'Anki',
        forceCss: false
    });


 },
'click .trumbowyg-insertImage-button ': function(){
// alert('cool');
$('#upload_profile').click();
$('.trumbowyg-fixed-top').hide();
},

  'change #upload_profile': function(e, template) {
  $('.trumbowyg-fixed-top').hide();
   var editor= $('#editor1').val();
    // var cursorPosition = $('#editor1').prop("selectionStart");
   //  var cursorPosition = getCurrentCursorPosition($('#editor1'));
   // alert(cursorPosition);
   // alert(editor.length+  " Total length");

   // var lower = editor.substr(0,cursorPosition);
   // var upper = editor.substr(lower.length,editor.length);
   // alert(lower);
   // alert(upper);
   // Session.set("lower",lower)
   //  Session.set("upper",upper);
    upload_profile_pic(e, template);

},
});




function upload_profile_pic(e,template){
    // e.preventDefault();
    // var files = e.currentTarget.files;
    if (e.currentTarget.files && e.currentTarget.files[0]) {
     var file = e.currentTarget.files[0];
      if (file) {
 
        var reader = new FileReader();
   var base64data="";
   reader.readAsDataURL(file);
   reader.onload = function () {
   console.log(reader.result);
   base64data = reader.result;

 var settings = {
  "async": true,
  "crossDomain": true,
  "url": "https://www.vayuz.com/testing/image_upload.php",
  "method": "POST",
  "headers": {
    "content-type": "application/x-www-form-urlencoded"
  },
  "data": {
    "image": base64data,
  }
}
var imagePath = base64data;
 $.ajax(settings).done(function (response) {
  console.log(response);
  alert(response);
  var imagePath = 'https://www.vayuz.com/testing' + response.substr(1, response.length);
  console.log(imagePath);
  Session.setPersistent("new_profile_image_url",imagePath);
   Meteor.call("upload_profile_image","a",imagePath,function(error,result){
        if(error){
          alert("Error");
        }else{
        //var data = Session.get("lower") + '<img id="Ankit" src="'+imagePath+ '" alt="" style="height:100%;width:10%;">' +Session.get("upper");
        $('#editor1').trumbowyg('restoreRange');

    // Insert text at the current position
    $('#editor1').trumbowyg('execCmd', {
        cmd: 'insertText',
        param: '<img id="Ankit" src="'+imagePath+ '" alt="" style="height:100%;width:10%;">',
        forceCss: false
    });

    $('#editor1').trumbowyg('html',data);
            alert("Profile Pic Changed");
             // toastr.success(Sucess, Profile Pic Changed);
         }
       
    });

    //var imagePath = Session.get("new_image_url");

});
}
 }
}
}


   /*
   **  Returns the caret (cursor) position of the specified text field.
   **  Return value range is 0-oField.length.
   */
   /*function doGetCaretPosition (oField) {

     // Initialize
     var iCaretPos = 0;

     // IE Support
     if (document.selection) {

       // Set focus on the element
       oField.focus ();
 
       // To get cursor position, get empty selection range
       var oSel = document.selection.createRange ();
 
       // Move selection start to 0 position
       oSel.moveStart ('character', -oField.value.length);
 
       // The caret position is selection length
       iCaretPos = oSel.text.length;
     }

     // Firefox support
     else if (oField.selectionStart || oField.selectionStart == '0')
       iCaretPos = oField.selectionStart;

     // Return results
     return (iCaretPos);
   }

*/
   /*
   **  Sets the caret (cursor) position of the specified text field.
   **  Valid positions are 0-oField.length.
   */
/*   function doSetCaretPosition (oField, iCaretPos) {

     // IE Support
     if (document.selection) {

       // Set focus on the element
       oField.focus ();
 
       // Create empty selection range
       var oSel = document.selection.createRange ();
 
       // Move selection start and end to 0 position
       oSel.moveStart ('character', -oField.value.length);
 
       // Move selection start and end to desired position
       oSel.moveStart ('character', iCaretPos);
       oSel.moveEnd ('character', 0);
       oSel.select ();
     }

     // Firefox support
     else if (oField.selectionStart || oField.selectionStart == '0') {
       oField.selectionStart = iCaretPos;
       oField.selectionEnd = iCaretPos;
       oField.focus ();
     }
   }
*/

function isChildOf(node, parentId) {
    while (node !== null) {
        if (node.id === parentId) {
            return true;
        }
        node = node.parentNode;
    }

    return false;
};

function getCurrentCursorPosition(parentId) {
    var selection = window.getSelection(),
        charCount = -1,
        node;

    if (selection.focusNode) {
        if (isChildOf(selection.focusNode, parentId)) {
            node = selection.focusNode;
            charCount = selection.focusOffset;

            while (node) {
                if (node.id === parentId) {
                    break;
                }

                if (node.previousSibling) {
                    node = node.previousSibling;
                    charCount += node.textContent.length;
                } else {
                     node = node.parentNode;
                     if (node === null) {
                         break
                     }
                }
           }
      }
   }

    return charCount;
};





































<template name="blog">
  <head>
  <title>Blog</title>
</head>
<div>
</div>

<div>
  <textarea id="editor1" ></textarea>
</div>
    <input type="file" id="upload_profile" accept="image/*" style="display:none;"/>
    <button id="button"> Ankit</button> 

<button id="button1"> Ankit1</button> 
</template>

Comments

Popular posts from this blog

Android Commands

meteor run android-device --mobile-server="https://sitename.com" metero build (BUIld Path/home/bird/Downloads/Meteor/bit/uploads ) --server="https://sitename.com"

Using LetsEncrypt to install free SSL on AWS server ec2 machine( Meteor version 1.6)

Installation of meteor project on AWS could be a real headache if you are not familiar with AWS environment. But with the help of various blogs on Medium, you can Do the installation and your project would be live. But there is one more thing that usually causes severe pain for Developers. that is the installation of SSL certificate. Most of the content on the web is almost 2-3 years old. So many things got changed since then. so we felt an utter need for a blog that could guide us through this process. let's start. 1. Login with SSH command on your Ubuntu machine. 2. Go to your project directory by typing cd /var/www/html/ 3. go inside your project and then in app-deploy folder. Now run mup stop command to stop the current instance that is running on the server. Now go out with cd .. command to HTML folder( cd /var/www/html/ ). 4. Now install LetsEncrypt on your virtual machine. type this command git clone https://github.com/letsencrypt/letse...
curl http://localhost:8042/studies/333b2c11-52e9feea-5516186e-ecd61f37-69da2603  curl http://localhost:8042/patients/dc65762c-f476e8b9-898834f4-2f8a5014-2599bc94 bird@bird-Lenovo-ideapad-310-15IKB:/media/bird/2AE477A5E4777245/Meteor/OrthancMirror/build$ curl http://localhost:8042/patients [    "333b2c11-52e9feea-5516186e-ecd61f37-69da2603",    "da39a3ee-5e6b4b0d-3255bfef-95601890-afd80709" ] bird@bird-Lenovo-ideapad-310-15IKB:/media/bird/2AE477A5E4777245/Meteor/OrthancMirror/build$ curl http://localhost:8042/studies [    "9b5629ef-c28c48db-b3593009-35fda9cb-7a0bb799",    "abae0b24-5a718d9e-1b560140-2cda3ae0-30b846cb" ] bird@bird-Lenovo-ideapad-310-15IKB:/media/bird/2AE477A5E4777245/Meteor/OrthancMirror/build$  curl http://localhost:8042/series [    "993a521c-1b11574c-92e1c71d-a048784c-36866be0",    "5f19601c-3e5fa872-e566e9f2-36aa3b31-dc719c3e" ] bird@bird-Lenovo-ideapad-310-15IKB:/med...