I have this next issue in which I am having quite a significant problem.
First of all, I am trying to integrate three div into my slider and all of them retain a Bootstrap 4 skeleton.
The code would be like this and furthermore it is being generated from another Jquery function in which I am inserting info from a Database. Therefore, I am putting this info into one of each card.
//FUNCIONES
//Crear especialista
function CrearEspecialistaCard(especialista, mostrarNombreEspecialidad) {
let cardHTML = "";
cardHTML += '<div><div class="col-xs-12 col-lg-3 col-md-3 float-left has_border_grey border_10 px-0 overflow-hidden mr-2 profile-box">'
+ '<div class="card d-inline"><div class="col-lg-6 col-md-6 bg-light float-left py-2 text-md-left text-center" style="z-index:101;"> ';
cardHTML += '<h2 class="text-secondary profile-name">' + ((especialista.sexo == "F") ? "Dra. " : "Dr. ")
+ especialista.nommed + " " + especialista.apemed + '</h2>' +
'<button class="btn btn-secondary btn-profile btn-sm my-2" data-toggle="modal" data-target="#modalDoctor' + especialista.idEspecialista + '"'
+ '>Ver perfil' + '</button>';
cardHTML += '<h3 class="spec-title">' + especialista.descesp + '</h3>' + '<h4 class="center-title">' +
'' + '</h4>'+ '<h5 class="prov-title mb-1">' + especialista.provincias + '</h5>';
cardHTML += '<p id="reservarCita" class=""> RESERVAR CITA</p>' +
(especialista.teleConsulta === true) ?
'<a class="d-inline-block mr-1" href="/videoConsulta"><img class="bg-purple py-1 px-1" src="/Content/Img/videoconsulta30.png" style="max-width:30px;" />' +
'</a>' : '';
cardHTML += (especialista.videoConsulta === true) ?
'<a class="d-inline-block mr-1" href="/teleConsulta"><img class="bg-purple-red py-1 px-1" src="/Content/Img/teleconsulta-30.png" style="max-width:30px;" />' +
'</a>' : '';
cardHTML += (especialista.consulta === true) ? '<a class="d-inline-block mr-1" href="/pedirCita">' +
'<img class="bg-light-purple py-1 px-1" src="/Content/Img/presencial30.png" style="max-width:30px;" />' +
'</a>' : '';
cardHTML += '</div>';
cardHTML += ' <div class="col-md-6 float-left" style="z-index:100;">' +
'<img class="profile-img img-fluid" src="/Content/Img/Medicos/CuadroAsistencial/FORMATO-MEDICOS.jpg" alt="Doctor" />' +
'</div>';
if (mostrarNombreEspecialidad != undefined && mostrarNombreEspecialidad == true) {
cardHTML += '<br /><span style="font-size:small;" class="colorcard bold">' + especialista.descesp + '</span>';
} else {
cardHTML += '<br />';
}
cardHTML += '</div></div></div>';
return cardHTML;
}
I am going to show you where I create the row which inserts one of every card with an anonymous function.
const MuestraEspecialistasFavoritos = (qRow) => {
let resultadoHTML = "";
let modalHTML = "";
resultadoHTML += '<div class="preview-carousel">'; // this is where I generate the class for my carousel
for (var a = 0; a < globalModeloFavoritos.length; a++) {
let toto = ca_model.listaEspecialistas.filter(b => b.idEspecialista == globalModeloFavoritos[a]);
if ( toto ) resultadoHTML += CrearEspecialistaCard(toto[0] , false);
if( toto )
var doctor = toto[0];
modalHTML += loadModal(doctor, toto[0].idEspecialista);
}
modalesRecientes.html(modalHTML);
resultadoHTML += '</div>';
qRow.html(resultadoHTML);
}
When I already have constructed my cards, which in this case they are functioning and being displayed as I want to, I am calling the slick slider so that I can interpret one of every card as one unique slider.
$('.preview-carousel').slick({
slidesToShow: 2,
slidesToScroll: 1
});
My slick.js is loaded as I already checked but it doesn't do absolutely nothing.
FYI every one of the cards generates a div firstly with no classes and no ids so I can be able to interpret every one of the items as if they were items of the slider.
Ok, found it already.
It wasn't that hard actually.
I was trying to run the slick function inside a document ready function.
With an on load functions, it works perfectly.
$(window).on('load', function() {
$('.preview-carousel').slick({
slidesToShow: 2,
slidesToScroll: 1
});
});
Related
I have this in JS and the code below. I want to send the data-id into modal and also when closing the modal to dismiss the data-id. how can I do that using javaScript???
fetch("https://data.uk/api/" + $searchValue).then(
res => {
res.json().then(
data => {
if (data.length > 0) {
var temp = "";
temp += "<thead>";
temp += "<tr>";
temp += "<th>ID</th>";
temp += "<th>Force Name</th>";
temp += "<th>Details</th>";
temp += "</tr>";
temp += "</thead>";
temp += "<tbody>";
data.forEach((itemData) => {
temp += "<tr><td>" + itemData.id + "</td>";
temp += "<td>" + itemData.name + "</td>";
temp += "<td><a href='#' data-id='" + itemData.id + "' data-toggle='modal' data-target='#myModal'>More Detail</a></td></tr>";
});
temp += "</tbody>";
document.getElementById('data').innerHTML = temp;
}
}
)
}
)
and I want to get each data-id value into modal using this
$("myModal").on("show.bs.modal", function(e) {
var b = $(e.relatedTarget);
var r = b.data("id");
var modal = $(this);
modal.find("#me").text(r);
})
and this is my modal, I want when I open the modal to be able to capture the data-id and display it in id="me"
<div class="modal-body" id="modal-body">
<div class="row m-0">
<div class="col-4">
People name & twitter
</div>
<div class="col-8">
Descriptions
<h2 id="me"></h2>
</div>
</div>
</div>
You can access data-... attribute with dataset property, e.g. given
<div id="my-element" data-id="myData"></div>
you can get it with
document.getElementById("my-element").dataset.id
The instafeed api stopped working on my site. The error I am getting is:
A cookie associated with a cross-site resource at https://instagram.com/ was set without the SameSite attribute. A future release of Chrome will only deliver cookies with cross-site requests if they are set with SameSite=None and Secure. You can review cookies in developer tools under Application>Storage>Cookies and see more details at https://www.chromestatus.com/feature/5088147346030592 and https://www.chromestatus.com/feature/5633521622188032.
Chrome changed something and I am trying to understand. Any help would be appreciated.
The site where I wrote this is here. http://galnova.com
var accessToken = '271323200.1677ed0.0a4c06efd9474022b9c3eb47bccf5657'; // use your own token 713486902779818|vM5scnvKTkbBmLbsSgBTPVi3Gqs
$.getJSON('https://api.instagram.com/v1/users/self/media/recent/?access_token='+accessToken+'&callback=?',function (insta) {
$.each(insta.data,function (photos,src) {
if ( photos === 6 ) { return false; }
var date = new Date(parseInt(this.created_time) * 1000);
// template
$(
'<div class="col-sm-6 col-md-3 col-lg-2 grip_wrap flx gonzo">' +
'<div class="grip_hang_topp"></div>' +
'<div class="col grip flex_el flx_ex">' +
'<a title="' + this.caption.text + '" class="fancybox zero lass" data-fancybox="gallery1" data-caption="' + this.caption.text + '" href="' + this.images.standard_resolution.url + '">' +
'<img src="' + this.images.standard_resolution.url + '" />' +
'</a>' +
'<div class="col coat2 truncate">' + this.caption.text + '</div>' +
'<div class="row nill">' +
'<span class="col-6 heart-wrap floated">' + '<i class="fa fa-heart">'+ '</i>' + this.likes.count +' <div class="summ">likes</div>'+'</span>' +
'<span class="col-6 comment-wrap floated">' + '<i class="second fa fa-comment">'+ '</i>' + this.comments.count +' <div class="summ">comments</div>'+'</span>' +
'</div>' +
'<div class="row nill">' +
'<span class="col-sm-12 check-wrap floated">' + '<i class="second fa fa-check">'+ '</i>' + 'Posted ' + (date.getMonth()+1) + '/' + date.getDate() + '/' + date.getFullYear().toString().substring(2) +'</span>' +
'</div>' +
'<div><button class="col-12 btn btn-outline-tertiary">UltraGallery <span class="fab fa-instagram"><\/span></button></div>' +
'</div>' +
'<div class="grip_hang_bott"></div>' +
'</div>'
).appendTo('#instafeed');
});
$(".grip").hover(function(e){
"use strict";
e.preventDefault();
if ($(window).width() > 991) {
return false;
}
});
});
Instagram Api has changed, read more about it here
I'm trying to filter a list with AJAX, I have an issue where the html only shows the last element. I have read a lot of similar SO questions and to no avail. I have variables, so I don't know whats the issue.
$("#programme").change(function () {
event.preventDefault();
var selected_programme = $(this).val();
$.ajax({
url: '{% url "gps_list" %}',
data: {
"selected_programme": selected_programme,
},
dataType: 'json',
success: function(response) {
var json = $.parseJSON(response);
$.each( json, function( key, values ) {
var valname = values.fields.name;
var valco = values.fields.country;
var valpro = values.fields.programme_type;
var valwhat = values.fields.what;
console.log(valname, key);
console.log(valco);
console.log(valpro);
console.log(valwhat);
$("#names").html(valname);
$("#country").html(valco);
$("#pro_types").html(valpro);
$("#whats").html(valwhat);
});
},
error: function(response) {
alert("oh no!");
}
});
});
HTML
<div class="row">
<div class="col-md-12">
<h2 class="my-4" id="names">
<small id="country"></small>
</h2>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="card mb-4">
<div class="card-body">
<h2 class="card-title" id="pro_types"></h2>
<p class="card-text" id="whats"></p>
</div>
</div>
</div>
</div>
When you do this:
$("#names").html(valname);
$("#country").html(valco);
$("#pro_types").html(valpro);
$("#whats").html(valwhat);
you're overwriting whatever those elements had in them before. Since you're doing that in a loop, naturally you only see the result of the last write.
You'll need to either:
Write to different elements, or
Append rather than replacing (via append)
The specifics will depend on your HTML structure.
(Now that you've added your HTML.) I would structure it differently. Don't have any row at all (or have a placeholder "loading" row) to start with. Then build rows and append them when you have a response. Something along these lines:
var entryTemplate =
'<div>' +
'<div class="row">' +
'<div class="col-md-12">' +
'<h2 class="my-4">' +
'<span class="names"></span>' + // *** Made it a span inside the h2
'<small class="country"></small>' +
'</h2>' +
'</div>' +
'</div>' +
'<div class="row">' +
'<div class="col-md-12">' +
'<div class="card mb-4">' +
'<div class="card-body">' +
'<h2 class="card-title pro_types"></h2>' +
'<p class="card-text whats"></p>' +
'</div>' +
'</div>' +
'</div>' +
'</div>' +
'</div>';
function success(response) {
var json = $.parseJSON(response);
var container = $("#container");
container.empty(); // Removes any previous rows
$.each( json, function( key, values ) {
var fields = values.fields;
var entry = $(entryTemplate);
entry.find(".names").text(fields.name);
entry.find(".country").text(fields.country);
entry.find(".pro_types").text(fields.programme_type);
entry.find(".whats").text(fields.what);
container.append(entry.children());
});
}
success(
'[' +
'{"fields": {' +
'"name": "Name 1",' +
'"country": "Country 1",' +
'"programme_type": "PT 1",' +
'"what": "What 1"' +
'}},' +
'{"fields": {' +
'"name": "Name 2",' +
'"country": "Country 2",' +
'"programme_type": "PT 2",' +
'"what": "What 2"' +
'}},' +
'{"fields": {' +
'"name": "Name 3",' +
'"country": "Country 3",' +
'"programme_type": "PT 3",' +
'"what": "What 3"' +
'}}' +
']'
);
setTimeout(function() {
success(
'[' +
'{"fields": {' +
'"name": "Name 4",' +
'"country": "Country 4",' +
'"programme_type": "PT 4",' +
'"what": "What 4"' +
'}},' +
'{"fields": {' +
'"name": "Name 5",' +
'"country": "Country 5",' +
'"programme_type": "PT 5",' +
'"what": "What 5"' +
'}},' +
'{"fields": {' +
'"name": "Name 6",' +
'"country": "Country 6",' +
'"programme_type": "PT 6",' +
'"what": "What 6"' +
'}}' +
']'
);
}, 2000);
<div id="container"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
I am developing an app with the help of ionic 3
in the application i am generating dynamic html from .ts file and appending in HTML . Now i want to bind and click event to html
After user done an click event i want to refresh the content present in the dynamically generated html
please help to solve this
enter code here
my .ts file
with the below code i am generating html and appending to html
outputHtml = '<div id="rpl_crt"><div class="sys_ot"><h6 class="itm_nme">My Cart</h6>';
var innerHTML = '';
let amount = 0;
let savings = 0;
for (let dt in data) {
amount += data[cart].vv.value;
savings += data[cart].aa.value;
innerHTML += '<div class="cartlist">'
innerHTML += '<div class="row ">'
innerHTML += '<div col-3 class="itemimg">'
let img_url=data[cart].product.images ? ConfigurationPage.commonURL+data[dt].aa.images[1].url:'assets/img/place_holder.png'
innerHTML += '<img src="'+img_url+'" >'
innerHTML += '</div>'
innerHTML += '<div col-9>'
innerHTML += '<h6>' + data[dt].aa.name + '</h6>'
innerHTML += '</div>'
innerHTML += '</div>'
innerHTML +='<div class="btn_qnty row">'
innerHTML += '<div col-5>'
innerHTML += '<div class="row">'
innerHTML += '<div col-3 click="abc(dt)"><span class="circle">-</span></div>'
innerHTML += '<div text-center col-6 >'+data[dt].q+'</div>'
innerHTML += '<div col-3 (click)="xyz(dt)"><span class="circle " >+</span></div>'///I want an click event here to do some action
//
innerHTML += '</div>'
innerHTML += '</div>'
innerHTML += '<div col-7>'
innerHTML += '<div class="prd_dtl">'
innerHTML += '<div class="proctprice">'
if (data[dt].ss.value != 0) {
innerHTML += '<span class="orgin_prc">' + this.currency.transform((parseFloat(data[dt].tp.value) + parseFloat(data[dt].ss.value)), 'INR') + '</span>'
}
innerHTML += '<span class="dsc_prc">' + this.currency.transform(data[dt].tp.value, 'INR') + '</span>'
innerHTML += '</div>'
if (data[cart].savings.value != 0) {
innerHTML += '<p class="save_prc">' + this.currency.transform(data[dt].ss.value, 'INR') + '</p>'
}
innerHTML += '</div>'
innerHTML += '</div>'
// innerHTML += '<div class="quantity">' + data[dt].qt+ '</div>'
innerHTML += '</div>'
innerHTML += '</div>'
let abc={
code:data[dt].aa.code,
data:data[dt]
}
clickEventMethod.push(abc);
}
this.totalAmount = amount;
this.totalSaving = savings;
// outputHtml += '</ion-list>';
let footerHtml = '<div class="row cartfooter">'
footerHtml += '<div col-4><p>Total amount</p>' + this.currency.transform(this.totalAmount, 'INR') + '</div>'
footerHtml += '<div col-4><p>Total amount</p>' + this.currency.transform(this.totalSaving, 'INR') + '</div>'
footerHtml += '<div col-4><p>Say <strong>Checkout</strong> to checkout all items</p></div>'
console.log(clickEventMethod,'clickEventMethod')
outputHtml += innerHTML + footerHtml + '</div></div>';
this.appenData.nativeElement.insertAdjacentHTML('beforeend', outputHtml);//Appending the data at the end of the ion-content // break;
HTML
<ion-header [ngClass]="!isFromHome ? 'leftPaddingCssTitle':'cssTitle'">
<ion-navbar color="danger">
<ion-title>{{headerName}}</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
<div class="hint">
<p>To go back , say <b>Go Back</b></p>
<p>To Go cart , Say <b>Open Cart </b> or <b>Go to Cart</b></p>
</div>
<div class="main" #appenData id="main">
</div>
<ion-content>
So, actually I have different type of files (pdf, docx,etc) in my Parse Javascript app. The problem is that when I download a file using the url() method I get the entire name "tfss-ad38e137...-filename.pdf" but I want to download the file just as "filename.pdf". I have already tried using the download attribute on the <a> element with no solution.
So, I dynamically add this code:
query3.find({
success: function(results) {
console.log("ID CARPETA: " + idCarpeta);
//Si los resultados son mayores a 0 entonces aplicamos el height al div
if( results.length > 0)
{
setTimeout(function(){
$('#' + idCarpeta).height(130);
}, 300);
}
// Do something with the returned Parse.Object values
for (var i = 0; i < results.length; i++) {
var object = results[i];
var archivo = object.get('archivo');
var nombre= archivo.name();
console.log("Name: " + nombre);
var nameParts = nombre.split("-");
var filename = nameParts[nameParts.length - 1];
//ahora encontramos el tipo de archivo
var filenameParts = filename.split(".");
var tipo = filenameParts[1];
console.log("Tipo de file: " + tipo);
if(tipo == "pdf")
{
codigo = '<div id="tipo ' + contador + '" class="col-md-2 col-sm-2 box2 clearfix tipo' + contador + '">' +
'<div class="box3">' +
'<p><i class="icono-archivo fa fa-file-pdf-o"></i></p>' +
'<p><b>' + filename + '</b></p>' +
'</div>' +
'<div class="mask mask' + contador + '"><a download="' + filename + '" href="' + archivo.url() + '" ><span class="fa fa-download fa-3x"></span><span class="descargar">Descargar</span></div></a>' +
'</div>';
}
if(tipo == "jpeg" || tipo == "jpg")
{
codigo = '<div id="tipo ' + contador + '" class="col-md-2 col-sm-2 box2 clearfix tipo' + contador + '">' +
'<div class="box3">' +
'<p><i class="icono-archivo fa fa-file-image-o"></i></p>' +
'<p><b>' + filename + '</b></p>' +
'</div>' +
'<div class="mask mask' + contador + '"><a download="' + filename + '" href="' + archivo.url() + '" ><span class="fa fa-download fa-3x"></span><span class="descargar">Descargar</span></div></a>' +
'</div>';
...
}
As you can see I have the file name in the filename variable and try to use this in the "download" attribute but with no success. Please if somebody knows I would really appreciate it, is really ugly to download files with that large name.