Note that there are some explanatory texts on larger screens.

plurals
  1. POApplying plugins to elements added after document ready
    primarykey
    data
    text
    <p>Hello I am working in a project in wich you are supposed to open some " chat-windows", this windows use a plugin for a custom scroll bar. I am accessing JSON to get the variables of the name of the person and his status then I generate a template with underscore and preppend it to the body of my HTML, when I do this the new window chat doesn't get the custom scroll plugin. I would like to ask if you guys know a way to achieve this because already what i got is something like this.</p> <pre><code>$(document).on("ready", functions); function functions() { // My jquery plugin $(".messages-container").slimScroll({ height: '200', size: '10px', position: 'right', color: '#535a61', alwaysVisible: false, distance: '0', railVisible: true, railColor: '#222', railOpacity: 0.3, wheelStep: 10, disableFadeOut: false, start: "bottom" }); $("#online .user-name").on("click", checkUser); } function checkUser(){ //this is the function that acces the JSON then pass parameter to another function to open the chat window.(I removed some code to go better straight to the point). if(user == jsonUserName){ displayChatWindow(jsonUserName, jsonUserStatus, jsonUserAvatar); } function displayChatWindow(user, status, avatar){ console.log(avatar); var template = _.template($("#windowTemplate").html(), {userName: user, userStatus: status, userAvatar: avatar}); $("body").prepend(template); $(".messages-container").slimScroll({ height: '200', size: '10px', position: 'right', color: '#535a61', alwaysVisible: false, distance: '0', railVisible: true, railColor: '#222', railOpacity: 0.3, wheelStep: 10, disableFadeOut: false, start: "bottom" }); $(".friend-window").draggable({handler: ".header"}); $(".chat input, .chat textarea").on("focus", cleanInputs); $(".chat input, .chat textarea").on("blur", setInputs); } </code></pre> <p>So far what I do is append the template and re-call all the functions. I will appreciate if you guys can help me figuring out how to achieve this, and also some advice If I am structuring good my code or i am doing absolutely wrong, I am learning and this will be good for me, thank you guys!</p> <p><strong>This is how the template looks like</strong></p> <pre><code>&lt;script type="text/template" id="windowTemplate"&gt; &lt;div class="chat friend-window"&gt; &lt;div class="status"&gt; &lt;input type="text" value="Preparando el reporte anual :)"&gt; &lt;/div&gt; &lt;div class="header"&gt; &lt;a href="#"&gt; &lt;figure class="profile-picture"&gt; &lt;img src= &lt;%= userAvatar %&gt; alt="Foto-perfil" titte="Foto perfil"&gt; &lt;/figure&gt; &lt;/a&gt; &lt;h5&gt; &lt;a href="#" id="username"&gt; &lt;%= userName %&gt; &lt;/a&gt; &lt;a href="#" id="conection-status"&gt; &lt;%= userStatus %&gt;&lt;/a&gt; &lt;/h5&gt; &lt;figure class="minimize minimize-others"&gt; &lt;a href="#"&gt;&lt;img src="img/minimize.png" alt="minimize" title="minimize"&gt;&lt;/a&gt; &lt;/figure&gt; &lt;/div&gt; &lt;div class="messages-section"&gt; &lt;div class="messages-container"&gt; &lt;ul&gt; &lt;li&gt; &lt;div class="message-recieved"&gt; &lt;div class="border-top"&gt;&lt;/div&gt; ola k ase?..chateando o ke ase? &lt;div class="border-bottom"&gt;&lt;/div&gt; &lt;/div&gt; &lt;/li&gt; &lt;li&gt; &lt;div class="message-sent"&gt; &lt;div class="border-top"&gt;&lt;/div&gt; bien gracias, queria saber como vas con el reporte, te falta mucho para terminarlo? &lt;div class="border-bottom"&gt;&lt;/div&gt; &lt;/div&gt; &lt;/li&gt; &lt;li&gt; &lt;div class="message-recieved"&gt; &lt;div class="border-top"&gt;&lt;/div&gt; Ya esta asi o mas terminado :) &lt;div class="border-bottom"&gt;&lt;/div&gt; &lt;/div&gt; &lt;/li&gt; &lt;li&gt; &lt;div class="message-sent"&gt; &lt;div class="border-top"&gt;&lt;/div&gt; ola ke ase, preparando el reporte anual o k ase? &lt;div class="border-bottom"&gt;&lt;/div&gt; &lt;/div&gt; &lt;/li&gt; &lt;li&gt; &lt;div class="message-recieved"&gt; &lt;div class="border-top"&gt;&lt;/div&gt; Ya esta asi o mas terminado :) &lt;div class="border-bottom"&gt;&lt;/div&gt; &lt;/div&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;div class="message-area"&gt; &lt;textarea rows="2" cols="10" value="Escribe tu mensaje..."&gt;Escribe tu mensaje...&lt;/textarea&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/script&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload