image size listview jquerymobile - image

I'm trying to set a listview like that:
http://jquerymobile.com/demos/1.2.0/docs/lists/lists-thumbnails.html
I dinamicly generate my code
$('#calendarPage').live('pagebeforeshow', function(event) {
$('#calendarPage').live('pageshow', function(event) {
application.prev = 'menu.html';
//get the actu
application.readFile('calendar.json',function(data){
data = JSON.parse(data);
var listview = '<ul data-role="listview" class="ui-listview" id="calendarList" >';
for(elem in data){
var date = new Date(data[elem].date);
var day = date.getDate();
var month = date.getMonth() + 1;
var year = date.getYear();
var hours = date.getHours();
var min = date.getMinutes();
var s = date.getSeconds();
listview += '<li>';
listview += '<img src="'+application.api+data[elem].img+'" /><a href="actuOne.html?id='+elem+'" ><h3>'+data[elem].title+'</h3><p>'+day+'/'+month+'/'+year+' '+hours+':'+min+':'+s+'</p></a>';
listview += '</li>';
}
listview += '</ul>';
$('#calendarPage .content').html(listview);
$('#calendarList').listview();
});
});
});
Yhe listview is created but the images are not resized
I try adding class="ui-li-thumb" but it works poorly
Thanks

There's an error in your example, img tag must be inside a a tag, only then it will be resized.
Take a look at this example: http://jsfiddle.net/Gajotres/w5bcS/
<ul data-role="listview">
<li><a href="index.html">
<img src="http://www.warrenphotographic.co.uk/photography/bigs/05852-Retriever-puppy-yawning-white-background.jpg" title="sample"/>
<h3>Sample image</h3>
<p>Sample</p>
</a></li>
<li><a href="index.html">
<img src="http://www.warrenphotographic.co.uk/photography/bigs/05852-Retriever-puppy-yawning-white-background.jpg" title="sample"/>
<h3>Sample image</h3>
<p>Sample 2</p>
</a></li>
</ul>

Related

Showing popup on image click

I'm using this code to show images.
The problem is that it is showing popup only for the first image and not the rest.
Images are loaded from database so they all have the same id.
Is that the problem or something else?
Code :
if (ViewBag.ReceptiSearchAll != null)
{
<div class="col-6 col-lg">
#foreach (var images in ViewBag.ReceptiSearchImages)
{
if (images.Image != null)
{
imagePath = images.Image;
}
else
{
imagePath = images.ImageDefault;
}
<div class="card mb-3" style="max-width: 400px;border:none">
<div class="row no-gutters">
<div class="col-md-12">
<img id="imgrec" class="card-img-top" src="data:image;base64,#System.Convert.ToBase64String(imagePath)" alt="Slika recepta" width="250" height="200">
</div>
</div>
</div>
}
</div>
}
<script>
// Get the modal
var modal = document.getElementById("myModal");
// Get the image and insert it inside the modal - use its "alt" text as a caption
var img = document.getElementById("imgrec");
var modalImg = document.getElementById("img01");
var captionText = document.getElementById("caption");
img.onclick = function () {
modal.style.display = "block";
modalImg.src = this.src;
captionText.innerHTML = this.alt;
}
// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];
// When the user clicks on <span> (x), close the modal
span.onclick = function () {
modal.style.display = "none";
}
</script>
All your images have the same id.
<img id="imgrec" ...
id is meant to be a unique identifier.
var img = document.getElementById("imgrec");
For that reason, only your first image gets this.
img.onclick = function () {
modal.style.display = "block";
modalImg.src = this.src;
captionText.innerHTML = this.alt;
}

Laravel 5.6 ajax ----

Hello I have an ajax request to retrieve the list of products. the request not well knowing that my table produced is connected with a color table
table Product [id, name, imgs, color_id]
table color [id, name, code]
how can i get the color code via ajax:
Here is part of my code:
$('#product1').on('change', function(e) {
var product_id = e.target.value;
// Ajax Products Color
if(product_id > 0) {
$.get('/2c/ajax-compare?product_id=' + product_id, function(data) {
$('#productProperty1').empty();
$.each(data, function(index, prodObj) {
if(index == 0)
{
var square = '<a class="btn compare d-block mb-3 active-item">Compare<img class="pl-2 img-fluid" src="{{ asset('/asstes/images/bleu_active.png' ) }}" alt=""></a>';
var image = '<img class="img-fluid mb-3" src="{{ asset('') }}'+prodObj.imgs+' " alt="">';
}
//var color = '<p>'+prodObj.color_id+'</p>';
// here i want to get the color code "prodObj.color_id"
$('#productProperty1').append(square, image);
})
})
}
else {
$('#productProperty1').empty();
var square = '<a class="btn compare d-block mb-3">Compare<img class="pl-2 img-fluid" src="{{ asset('/asstes/images/white_desactive.png' ) }}" alt=""></a>';
var image = '<img class="img-fluid mb-3" src="{{ asset('/asstes/images/products/phones/default.png' ) }}" alt="">';
$('#productProperty1').append(square, image);
}
});

Codeigniter Ajax Pagination Links Triggers Off-Canvas To Open

On my ajax below I generate 2 lots of pagination results.
When I click on the pagination links for some reason it triggers my off canvas menu to open.
Question: How can I make sure that only when I click on the class
.navbar-brand will open off canvas?
<script type="text/javascript">
$(document).ready(function() {
var menuToggle = $('.navbar-brand');
var menuToggleIcon = menuToggle.find('.fa');
var offCanvas = $('.offcanvas');
var content = $('.content');
menuToggle.click(function() {
closeMenu(menuToggleIcon, offCanvas);
});
content.click(function() {
closeMenu(menuToggleIcon, offCanvas);
});
function closeMenu(menuToggleIcon, offCanvas) {
menuToggleIcon.toggleClass('fa-indent fa-outdent');
offCanvas.toggleClass('open');
}
});
</script>
<script type="text/javascript">
$(document).ready(function() {
function load_questions_data(page){
$.ajax({
url:"<?php echo base_url(); ?>dashboard/questions_pagination/" + page,
method:"GET",
dataType:"json",
success:function(data) {
$('#questions_table').html(data.questions_table);
$('#question_pagination_link').html(data.pagination1_link);
}
});
}
load_questions_data(1);
$(document).on("click", ".question-pag li a", function(event){
event.preventDefault();
var page = $(this).data("ci-pagination-page");
load_questions_data(page);
});
});
</script>
<script type="text/javascript">
$(document).ready(function() {
function load_users_data(page){
$.ajax({
url:"<?php echo base_url(); ?>dashboard/users_pagination/" + page,
method:"GET",
dataType:"json",
success:function(data) {
$('#users_table').html(data.users_table);
$('#user_pagination_link').html(data.pagination2_link);
}
});
}
load_users_data(1);
$(document).on("click", ".user-pag li a", function(event){
event.preventDefault();
var page = $(this).data("ci-pagination-page");
load_users_data(page);
});
});
</script>
Controller
<?php
class Dashboard extends MY_Controller {
public $data = array();
public function __construct() {
parent::__construct();
$this->load->model('user/user_model');
$this->load->model('forum/question_model');
$this->load->library('pagination');
}
public function index() {
$this->data['title'] = 'Dashboard';
$this->data['is_logged'] = $this->session->userdata('is_logged');
$this->data['navbar'] = $this->load->view('common/navbar', $this->data, TRUE);
$this->load->view('common/header', $this->data);
$this->load->view('common/dashboard', $this->data);
$this->load->view('common/footer', $this->data);
}
public function users_pagination() {
$config = array();
$config["base_url"] = "#";
$config["total_rows"] = $this->user_model->total_users();
$config["per_page"] = 2;
$config["uri_segment"] = 3;
$config["use_page_numbers"] = TRUE;
$config["num_links"] = 1;
$config["full_tag_open"] = '<ul class="pagination user-pag">';
$config["full_tag_close"] = '</ul>';
$config["first_tag_open"] = '<li>';
$config["first_tag_close"] = '</li>';
$config["last_tag_open"] = '<li>';
$config["last_tag_close"] = '</li>';
$config['next_link'] = '>';
$config["next_tag_open"] = '<li>';
$config["next_tag_close"] = '</li>';
$config["prev_link"] = "<";
$config["prev_tag_open"] = "<li>";
$config["prev_tag_close"] = "</li>";
$config["cur_tag_open"] = "<li class='active'><a href='#'>";
$config["cur_tag_close"] = "</a></li>";
$config["num_tag_open"] = "<li>";
$config["num_tag_close"] = "</li>";
$this->pagination->initialize($config);
$page = $this->uri->segment(3);
$start = ($page - 1) * $config["per_page"];
$output = array(
'pagination2_link' => $this->pagination->create_links(),
'users_table' => $this->user_model->get_ajax_users($config["per_page"], $start)
);
echo json_encode($output);
}
public function questions_pagination() {
$config = array();
$config["base_url"] = "#";
$config["total_rows"] = $this->question_model->total_questions();
$config["per_page"] = 2;
$config["uri_segment"] = 3;
$config["use_page_numbers"] = TRUE;
$config["num_links"] = 1;
$config["full_tag_open"] = '<ul class="pagination question-pag">';
$config["full_tag_close"] = '</ul>';
$config["first_tag_open"] = '<li>';
$config["first_tag_close"] = '</li>';
$config["last_tag_open"] = '<li>';
$config["last_tag_close"] = '</li>';
$config['next_link'] = '>';
$config["next_tag_open"] = '<li>';
$config["next_tag_close"] = '</li>';
$config["prev_link"] = "<";
$config["prev_tag_open"] = "<li>";
$config["prev_tag_close"] = "</li>";
$config["cur_tag_open"] = "<li class='active'><a href='#'>";
$config["cur_tag_close"] = "</a></li>";
$config["num_tag_open"] = "<li>";
$config["num_tag_close"] = "</li>";
$this->pagination->initialize($config);
$page = $this->uri->segment(3);
$start = ($page - 1) * $config["per_page"];
$output = array(
'pagination1_link' => $this->pagination->create_links(),
'questions_table' => $this->question_model->get_ajax_questions($config["per_page"], $start)
);
echo json_encode($output);
}
}
Full View
<!-- No Data is currently set inside offcanvas -->
<div class="offcanvas"></div>
<div class="wrap">
<?php echo $navbar;?>
<div class="container-fluid">
<div class="content">
<div class="row">
<div class="col-lg-12">
<div class="page-header">
<h2>Dashboard</h2>
</div>
</div>
</div>
</div>
</div>
<div class="container-fluid">
<div class="content">
<div class="row">
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-body">
<div id="questions_table"></div>
<div id="question_pagination_link"></div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-body">
<div id="users_table"></div>
<div id="user_pagination_link"></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
$(document).ready(function() {
function load_questions_data(page){
$.ajax({
url:"<?php echo base_url(); ?>dashboard/questions_pagination/" + page,
method:"GET",
dataType:"json",
success:function(data) {
$('#questions_table').html(data.questions_table);
$('#question_pagination_link').html(data.pagination1_link);
}
});
}
load_questions_data(1);
$(document).on("click", ".question-pag li a", function(event){
event.preventDefault();
var page = $(this).data("ci-pagination-page");
load_questions_data(page);
});
});
</script>
<script type="text/javascript">
$(document).ready(function() {
function load_users_data(page){
$.ajax({
url:"<?php echo base_url(); ?>dashboard/users_pagination/" + page,
method:"GET",
dataType:"json",
success:function(data) {
$('#users_table').html(data.users_table);
$('#user_pagination_link').html(data.pagination2_link);
}
});
}
load_users_data(1);
$(document).on("click", ".user-pag li a", function(event){
event.preventDefault();
var page = $(this).data("ci-pagination-page");
load_users_data(page);
});
});
</script>
<script type="text/javascript">
$(document).ready(function() {
var menuToggle = $('.navbar-brand');
var menuToggleIcon = menuToggle.find('.fa');
var offCanvas = $('.offcanvas');
var content = $('.content');
menuToggle.click(function() {
closeMenu(menuToggleIcon, offCanvas);
});
content.click(function() {
closeMenu(menuToggleIcon, offCanvas);
});
function closeMenu(menuToggleIcon, offCanvas) {
menuToggleIcon.toggleClass('fa-indent fa-outdent');
offCanvas.toggleClass('open');
}
});
</script>
You need to use event.stopPropagation() when you click on a pagination link like,
$(document).on("click", ".question-pag li a", function(event){
event.preventDefault();
event.stopPropagation(); // it will prevent your content click function
var page = $(this).data("ci-pagination-page");
load_questions_data(page);
});
And, for users data
$(document).on("click", ".user-pag li a", function(event){
event.preventDefault();
event.stopPropagation(); // it will prevent your content click function
var page = $(this).data("ci-pagination-page");
load_users_data(page);
});
Thanks to #Rohan Kumar for the answer with pagination links part
I have fixed the problem main problem was here in the off canvas script
New Code
<script type="text/javascript">
$(document).ready(function() {
var menuToggleIcon = $('.navbar-brand').find('.fa');
$('.navbar-brand').on('click', function() {
menuToggleIcon.toggleClass('fa-indent fa-outdent');
$('.offcanvas').toggleClass('open');
});
});
</script>
Old Script
<script type="text/javascript">
$(document).ready(function() {
var menuToggle = $('.navbar-brand');
var menuToggleIcon = menuToggle.find('.fa');
var offCanvas = $('.offcanvas');
var content = $('.content');
menuToggle.click(function() {
closeMenu(menuToggleIcon, offCanvas);
});
content.click(function() {
closeMenu(menuToggleIcon, offCanvas);
});
function closeMenu(menuToggleIcon, offCanvas) {
menuToggleIcon.toggleClass('fa-indent fa-outdent');
offCanvas.toggleClass('open');
}
});
</script>

How to link two ImageMap areas?

I have an image with complex poly areas setup to link to anchors within a page. In addition to this when hovered over the area is highlighted.
However I want this area to link up with a piece of text so that when either is hovered over they will both become highlighted.
I presumed if they held the same title and alt it would function in this manner.
Solution found. Below is the code from the fiddle I found that fixed the problem.
HTML
<!DOCTYPE html>
<body>
<div id="menu">
<ul>
<li class="menu-item-a">Part A</li>
<li class="menu-item-b">Part B</li>
<li class="menu-item-c">Part C</li>
<ul>
</div>
<img id="house" src="http://also.kottke.org/misc/images/filip-dujardin.jpg" style="" usemap="#house-map">
<map name="house-map">
<area shape="rect" name="part-a" coords="0,0,500,183" href="#" />
<area shape="rect" name="part-b" coords="0,183,500,366" href="#" />
<area shape="rect" name="part-c" coords="0,366,500,500" href="#" />
</map>
</body>
</html>
JS
jQuery(document).ready(function ($) {
$('#house').mapster({
mapKey: 'name',
singleSelect: true,
fillOpacity: 0.6,
fillColor: 'FF0000',
//
onMouseover: function (evt) {
var parts = evt.key.split('-');
var part = parts[1];
highlightArea(part);
},
//
onMouseout: function (evt) {
var parts = evt.key.split('-');
var part = parts[1];
highlightAreaX(part);
}
});
//
$('a').hover(function () {
var parts = $(this).closest('li').attr('class').split('-');
var part = parts[2];
highlightArea(part);
});
//
$('a').mouseleave(function () {
var parts = $(this).closest('li').attr('class').split('-');
var part = parts[2];
highlightAreaX(part);
});
//
function highlightArea(key) {
$('area[name=part-' + key + ']').mouseenter();
$('a').removeClass('hover');
$('li.menu-item-' + key + ' a').addClass('hover');
}
//
function highlightAreaX(key) {
$('area[name=part-' + key + ']').mouseout();
$('li.menu-item-' + key + ' a').removeClass('hover');
}
});
The main reason this was hard was because unfortunate the fiddle closed the initial function halfway through the code, thus causing wordpress to only load half of it. To resolve this simply move "});" to the end as I have in the above example.

How to receive an event at the END of a page transition with jquery mobile

Context :
I am trying to calculate the available vertical unused space on a jquery mobile page and use the result to size an element to use the maximum available space.
I can not start the calculation BEFORE the page has finished transitioning IN because the height of header, footer and content elements is set to 0 when the page is not visible.
I use the pageshow event to detect when the page transition is finished and do my calculation but found that the height of the footer is still 0 when the transition should be finished while it is in fact of 51px. also the page height return a height significantly smaller than the window or document height which is not the case once the transition is fully executed.
I have the impression that at the moment the pageshow event is triggered the page transition is in fact incomplete while according to the documentation it should be fired only once completed, aka all elements should have their final height.
Anybody know better or can point out some obvious mistake my understanding of this event ?
I have for now solved my problem by setting hard coded values but would much prefer to write a generic function that would work.
My code trimmed down :
Exert of the HTML page :
...
<div data-role="page" id="pWhereAmI">
<div data-role="header" data-id="mainHeader" data-position="fixed">
<h1>Where Am I ?</h1>
</div>
<div data-role="content" class="map-content">
<ul data-role="listview" data-inset="true">
<li>Position Unknown</li>
<li id="map_canvas"></li>
<li>Center the map</li>
</ul>
</div>
<div data-role="footer" class="nav-glyphish-example" data-id="mainFooter" data-position="fixed">
<div data-role="navbar" class="nav-glyphish-example" data-grid="d">
<ul>
<li><small>Login</small></li>
</ul>
</div>
</div>
</div><!-- /page pWhereAmI -->
...
Exert of the javascript code :
$('#pWhereAmI').live('pageshow',function(event, ui) {
pageFreeHeight = pageFreeHeight_calc('#pWhereAmI');
map_canvasHeight = $('#map_canvas').height() + pageFreeHeight;
$('#map_canvas').height(map_canvasHeight);
});
The function called at pageshow event time :
function pageFreeHeight_calc(pageSelector) {
if($(pageSelector).height != null) {
pageHeight = $(pageSelector).height();
}
else {
return null;
}
if($(pageSelector+' [data-role|="header"]').outerHeight(true) != null) {
headerHeight = $(pageSelector+' [data-role|="header"]').outerHeight(true);
}
else {
headerHeight = 0;
}
if($(pageSelector+' [data-role|="content"]').outerHeight(true) != null) {
contentHeight = $(pageSelector+' [data-role|="content"]').outerHeight(true);
}
else {
contentHeight = 0;
}
if($(pageSelector+' [data-role|="footer"]').outerHeight(true) != null) {
footerHeight = $(pageSelector+' [data-role|="footer"]').outerHeight(true);
}
else {
footerHeight = 0;
}
return pageHeight - headerHeight - contentHeight - footerHeight;
}
Hmm, I modified it a little but your code looks good to me. Here is a live example of what I have:
http://jsfiddle.net/phillpafford/gkPAG/22/
http://jsfiddle.net/phillpafford/gkPAG/28/ <-- Display elements heights after adjustments
JS:
$('#pWhereAmI').live('pageshow',function(event, ui) {
canvasHeight = $('#map_canvas').height(); // initialize the canvas height
pageFreeHeight = pageFreeHeight_calc('#pWhereAmI');
map_canvasHeight = canvasHeight + pageFreeHeight;
$('#map_canvas').height(map_canvasHeight).page();
});
function pageFreeHeight_calc(pageSelector) {
var pageHeight = null;
var headerHeight = 0;;
var contentHeight = 0;
var footerHeight = 0;
if($(pageSelector).height != null) {
pageHeight = $(pageSelector).height();
}
if($(pageSelector+' [data-role|="header"]').outerHeight(true) != null) {
headerHeight = $(pageSelector+' [data-role|="header"]').outerHeight(true);
}
if($(pageSelector+' [data-role|="content"]').outerHeight(true) != null) {
contentHeight = $(pageSelector+' [data-role|="content"]').outerHeight(true);
}
if($(pageSelector+' [data-role|="footer"]').outerHeight(true) != null) {
footerHeight = $(pageSelector+' [data-role|="footer"]').outerHeight(true);
}
alert(
'pageHeight: ' + pageHeight + "\n" +
'headerHeight: ' + headerHeight + "\n" +
'contentHeight: ' + contentHeight + "\n" +
'footerHeight: ' + footerHeight + "\n" +
'returnValue: ' + (pageHeight - headerHeight - contentHeight - footerHeight)
);
return pageHeight - headerHeight - contentHeight - footerHeight;
}
HTML:
<div data-role="page" id="home">
<div data-role="content">
<ul data-role="listview" data-inset="true" data-theme="c" data-dividertheme="f">
<li data-role="list-divider">Navigation</li>
<li>Where am I</li>
</ul>
</div>
</div>
<div data-role="page" id="pWhereAmI">
<div data-role="header" data-id="mainHeader" data-position="fixed">
<h1>Where Am I ?</h1>
</div>
<div data-role="content" class="map-content">
<ul data-role="listview" data-inset="true" data-theme="c" data-dividertheme="f">
<li data-role="list-divider">Navigation</li>
<li>Home</li>
</ul>
<br />
<ul data-role="listview" data-inset="true">
<li>Position Unknown</li>
<li id="map_canvas"></li>
<li>Center the map</li>
</ul>
</div>
<div data-role="footer" class="nav-glyphish-example" data-id="mainFooter" data-position="fixed">
<div data-role="navbar" class="nav-glyphish-example" data-grid="d">
<ul>
<li><small>Login</small></li>
</ul>
</div>
</div>
</div><!-- /page pWhereAmI -->

Resources