I've got multiple HTML pages that use the JQMobile framework; within these pages I'm using iScroll to create a native scrolling effect, all works fine.
I run into problems when using the JQM page transitions with iScroll, since it's loaded via ajax I know that I need to refresh iScroll on the new page so that it can correctly calculate the height and width after the DOM has changed.
I've looked into this and experimented with code (tried refresh() and destroying and recreating) but can't see to get it work, the iScroll works it's just not getting refreshed on page change (therefore not working), any ideas?
Code below!
<div data-role="page">
<div data-role="header">
</div><!-- /header -->
<div data-role="content">
<div id="wrapper">
<div id="scroller">
<p>Page content goes here.</p>
Page 2
</div>
</div>
</div><!-- /content -->
<div data-role="footer">
<div data-role="navbar">
<ul>
<li><a data-ajax="false" href="javascript:void(0);" onClick="homepage();"><img width="34px" height="34px" src="images/home_IMG_v2.png" /><!--<span class="nav">Home</span>--></a></li>
<li><a data-ajax="false" href="Guide.html" class="ui-btn-active ui-state-persist"><img width="35px" height="33px" src="images/guide_IMG_v2.png"><!--<span class="nav">Guide</span>--></a></li>
<li><a data-ajax="false" href="TaxCalculator.html" /><img width="76px" height="34px" src="images/calculator_IMG_v2.png" /><!--<span id="calc" class="nav">Calculator</span>--></a></li>
</ul>
</div>
</div><!-- /footer -->
</div><!-- /page -->
Using refresh()
var myScroll;
function loaded() {
myScroll = new iScroll('wrapper', { hScrollbar: false, vScrollbar: false, checkDOMChanges: true});
setTimeout(function() {
myScroll.refresh();
}, 100);
}
document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);
document.addEventListener('DOMContentLoaded', function () { setTimeout(loaded, 200); }, false);
Destroying iScroll and recreating
var myScroll;
function loaded() {
myScroll = new iScroll('wrapper', { hScrollbar: false, vScrollbar: false, checkDOMChanges: true});
setTimeout(function() {
myScroll.destroy();
myScroll = null;
myScroll = new iScroll('wrapper', { hScrollbar: false, vScrollbar: false, checkDOMChanges: true});
}, 100);
}
document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);
document.addEventListener('DOMContentLoaded', function () { setTimeout(loaded, 200); }, false);
Try calling initialising iScroll when the jqm pageshow event fires e.g. in jqm 1.3.1:
$(document).on('pageshow', function (event, ui) {
myScroll = new iScroll('wrapper', { hScrollbar: false, vScrollbar: false, checkDOMChanges: true});
});
after domchanges you need refreshing iscroll
$('#videotagisc').iscrollview("refresh");
this not working means use setTimeout
setTimeout(function(){
$('#videotagisc').iscrollview("refresh");
},100);
var width = $( window ).width();
var height = $( window ).height();
var delay = 200;
var doit;
function keop() {
$("#wrapper").css({"height":height+"px","width":width+"px"});
setTimeout( function(){
myScroll.refresh() ;
} , 200 ) ;
}
/* < JQuery 1.8*/
window.addEventListener("load", function(){
clearTimeout(doit);
doit = setTimeout(keop, delay);
});
/* > JQuery 1.8*/
window.on("load", function(){
clearTimeout(doit);
doit = setTimeout(keop, delay);
});
Related
I am trying to populate a content into an bootstrap popover using angular and ajax. Although the data have been loaded correctly (as i can see in console.log) the result don't appear in the popover's content. I think the angular's loading is not ready yet when the bootstrap popover is loaded. Thus, how can i populate this popover immediately after angular load?
This is the code:
$(function() {
var p = $("#popover").popover({
content: $("#popover-content").html(),
html: true
});
});
(function () {
var app = angular.module("ng-app", []);
app.controller("NotificationsController", function ($scope, $http) {
$scope.links = [];
$scope.load = function () {
$http.get("json.php").success(function (response) {
console.log(response);
$scope.links = response;
// the response return is somethin like
// [
// {title: "Google", url: "http://www.google.com"},
// {title: "Gmail", url: "http://www.google.com"},
// ]
});
};
$scope.load();
});
})();
<ul class="nav navbar-nav">
<li data-ng-controller="NotificationsController as notification">
<a href="#" data-toggle="popover" id="popover" title="Notificações" data-placement="bottom" data-trigger="focus">
<span class="badge">{{links.length}}</span>
</a>
<div id="popover-content" style="display: none">
<div data-ng-repeat="link in links">
{{link.title}}
</div>
</div>
</li>
</ul>
Thanks in advance
You can put your function inner the controller, to get angular cycle. And, also, define your jquery call on a $timeout event.
Please look this sample on jsbin: jsbin
controller('c', function($scope, $timeout) {
$scope.getData = function() {
return $("#popover-content").html();
};
$timeout(function() {
$("#popover").popover({
content: $scope.getData,
html: true
});
});
}
I have been googling this and trying to find a solution which seems to be pretty much impossible, I have dropzone integrated in to my application with the remove button, I want to add an additional button to each thumb nail is this possible to do? so two buttons per each thumbnail?
I have added custom download button for each file check below code
var myDropzone = new Dropzone("#form", {
maxFilesize: 2, // MB
addRemoveLinks: true,
dictRemoveFileConfirmation : 'Sure Want To Delete',
init: function() {
this.on("success", function(file, responseText) {
var filename = file.name;
$('#form').append("<input type='hidden' data='"+filename+"' name='files[]' value='"+responseText+"'>");
});
this.on("complete",function(file){
var newNode = document.createElement('a');
newNode.className = 'btn btn-primary btn-xs downloadbtn';
newNode.href = "<?= SITE_URL.''.'upload/attachments/' ?>"+file.name;
newNode.target = "_blank";
newNode.innerHTML = '<i class="fa fa-download"></i> Download';
file.previewTemplate.appendChild(newNode);
});
}
});
Are you creating a custom theme for the thumbnail? That is the easiest way to add buttons etc. http://www.dropzonejs.com/#theming
for example:
<div id="preview-template" style="display:none">
<div class="documents_drop_file_thumb">
<div class="documents_drop_file_thumb_remove"><a class="dz-remove" href="javascript:undefined;" data-dz-remove=""><img src="<?php echo DIRECTORY_INDEX . "/"; ?>images/remove_file.png" alt=""></a></div>
<div class="documents_drop_file_thumb_EXTRABUTTON"><a class="dz-extraaction" href="javascript:undefined;"><img src="<?php echo DIRECTORY_INDEX . "/"; ?>images/extrabutton_file.png" alt=""></a></div>
<div class="documents_drop_file_thumb_image"><img data-dz-thumbnail /></div>
<div class="documents_drop_file_thumb_progress_status"><span data-dz-name></span></div>
<div class="documents_drop_file_thumb_progress"><span class="dz-upload" data-dz-uploadprogress></div>
<div class="documents_drop_file_thumb_progress_status"><span data-dz-errormessage></span></div>
</div>
Then all you need is a dropzone parameter when setting up your dz.
//Prepare the drop zone area
var myNewdDropzone = new Dropzone("#idOfForm", {
url: "my-ajax.php",
method: "POST",
addRemoveLinks: false,
clickable: true,
previewTemplate: document.querySelector('#preview-template').innerHTML,
init : function() {
this.on("addedfile", function(file) { new_file_added(file); });
this.on("thumbnail", function(file,fileurl) { new_thumbnail_added(file); });
this.on("removedfile", function(file) { new_file_removed(file); });
this.on("totaluploadprogress", function(progress) { display_progress(progress); });
this.on("queuecomplete", function() { all_files_uploaded(); });
//this.on("processing", function(file) { new_file_processed(file); });
}
});
Pay particular attention to:
EXTRABUTTON - that is your shiny new button area
addRemoveLinks - your template has them, so don't add new ones (with a nice icon, assuming you have a nice icon with that name)
previewTemplate - that sets up your new thumbnail template
this.on("etcetcetc") calls functions driven by events if you need them
Here's a simplified example of my knockout model. The problem I'm having is that as soon as the page loads, the quiz is loaded. Why does it get run straight away and how can I stop it so that it only get's run when I want, say, on the click of a button?
Do I even need to use subscribe to do this?
HTML:
<h1>Test</h1>
<button class="btn btn-primary" data-bind="click: quizCount(quizCount() + 1)">
Click Me
</button>
<hr />
<div data-bind="visible: !loaded()">No Quiz</div>
<div data-bind="visible: loaded">Quiz Loaded!</div>
<hr />
<h3>Debug</h3>
<div data-bind="text: ko.toJSON(quizModel)"></div>
Javascript:
<script type="text/javascript">
var quizModel = { };
// DOM ready.
$(function () {
function QuizViewModel() {
var self = this;
self.loaded = ko.observable(false);
self.questions = ko.observable();
self.quizCount = ko.observable();
};
quizModel = new QuizViewModel();
quizModel.quizCount.subscribe(function (newCount) {
$.getJSON('#Url.Action("GetNew", "api/quiz")', function (data) {
quizModel.questions(data.Questions);
}).complete(function () {
quizModel.loaded(true);
});
});
ko.applyBindings(quizModel);
})
</script>
Subscribe is only used for listening to changes in an observable so it will run immediately as soon as the observable gets a value.
You need to add this function to your viewmodel as a method, likely to be called getQuestions:
function QuizViewModel() {
var self = this;
self.loaded = ko.observable(false);
self.questions = ko.observable();
self.quizCount = ko.observable();
self.getQuestions = function(){
$.getJSON('#Url.Action("GetNew", "api/quiz")', function (data) {
self.questions(data.Questions);
}).complete(function () {
self.loaded(true);
});
}
};
then you can easily have a button or something that binds to this method on click:
<button data-bind="click: getQuestions">Get questions</button>
I have two pages...both are having same table content...the only difference is in their content loading technique..
1) http://myraipur.com/SuprError/Test2.php
Here the datatable content is loaded by simple “Tr” and “Td”. Modal window is working properly.
2) http://myraipur.com/SuprError/Test1.php
Here the datatable content is loaded via deferred loading. The modal window is not working.
can you please help me!!
Just to add a method I feel that is straight forward that worked for me. ( Also my first Stackoverflow post! )
First used the Javascript Modal function provided by,
http://dotnetspeak.com/2013/05/creating-simple-please-wait-dialog-with-twitter-bootstrap
var loading;
loading = loading || (function () {
var pleaseWaitDiv = $('<div class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true"><div class="modal-dialog modal-sm"><div class="modal-content"><div class="modal-header"><button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button><h4 class="modal-title" id="mySmallModalLabel">Loading Data</h4></div><div class="modal-body"><div class="progress"><div class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100" style="width: 100%"></div></div></div></div><!-- /.modal-content --></div><!-- /.modal-dialog -->');
return {
showPleaseWait: function() {
pleaseWaitDiv.modal();
},
hidePleaseWait: function () {
pleaseWaitDiv.modal('hide');
},
};
})();
And here is my Data table call
$(document).ready(function() {
$('#address')
.on( 'processing.dt', function ( e, settings, processing ) {
if (processing) {
$(document).ready(function() {
$('#address').click(loading.showPleaseWait());
});
} else {
$(document).ready(function() {
$('#address').click(loading.hidePleaseWait());
});
}
} )
.dataTable({
"Processing": false,
"sAjaxSource": "ajax/ajax_address_list.php",
"aoColumns": [
{ mData: 'add_cust' } ,
{ mData: 'add_main' },
{ mData: 'add_alias' }
],
"iDisplayLength": 50
});
} );
Hope this helps!
You need to run this code when your deferred is finished instead of document ready:
$("a[data-toggle=modal]").click(function (e) {
lv_target = $(this).attr('data-target');
lv_url = $(this).attr('href');
$(lv_target).load(lv_url);
});
I have a navigation which load dynamically content via ajax. But if I refresh the page or visit another url and go back the current content is away and I see the old content under the first menu tab.
What is the best way to solve this problem? Can you give me some code?
The index.php include the elements navigation.inc.php and main_container.inc.php
<?php include("inc/incfiles/header_registrated.inc.php"); ?>
<?php
if (!isset($_SESSION["userLogin"])) {
echo "<meta http-equiv=\"refresh\" content=\"0; url=http://localhost/project\">";
}
else {
echo "";
}
?>
<?php include("inc/incfiles/navigation.inc.php"); ?>
<?php include("inc/incfiles/main_container.inc.php"); ?>
<?php include("inc/incfiles/footer.inc.php"); ?>
navigation.inc.php:
<div class="navigation">
<ul>
<li id="1">
<div id="menuImage1" class="menuImage"></div>
<div class="menuText"><p>Punkt 1</p></div>
<div class="navigationDart"></div>
</li>
<li id="2">
<div id="menuImage2" class="menuImage"></div>
<div class="menuText"><p>Punkt 2</p></div>
</li>
<li id="3">
<div id="menuImage3" class="menuImage"></div>
<div class="menuText"><p>Punkt 3</p></div>
</li>
<li id="4">
<div id="menuImage4" class="menuImage"></div>
<div class="menuText"><p>Punkt 4</p></div>
</li>
<li id="5">
<div id="menuImage5" class="menuImage"></div>
<div class="menuText"><p>Punkt 5</p></div>
</li>
<li id="6">
<div id="menuImage6" class="menuImage"></div>
<div class="menuText"><p>Punkt 6</p></div>
</li>
</ul>
</div>
main_container.inc.php:
<div class="mainContainer">
<div class="containerHeader">
<div class="contentHeader">
</div>
</div>
<div class="contentContainer">
<div class="content">
</div>
<div class="advertisement">
</div>
</div>
</div>
Now the divs content, cnotentHeader and advertisement (in file main_content.inc.php) is filled via ajax. Also the navigation has some jquery effects which also have to be the same after page refresh.
$(document).ready(function() {
$.get('inc/incfiles/content_container/header/1.php', function(data) {
$('.contentHeader').html(data);
});
$.get('inc/incfiles/content_container/content/1.php', function(data) {
$('.content').html(data);
});
$.get('inc/incfiles/content_container/advertisement/1.php', function(data) {
$('.advertisement').html(data);
});
var current = '1.php';
$(".navigation li").click(function() {
var quelle = $(this).attr('id') + ".php";
// the current content doesn't load again
if(current === quelle) {
return;
}
current = quelle;
// content
$(".content").fadeOut(function() {
$(this).load("inc/incfiles/content_container/content/" + quelle).fadeIn('normal');
})
// advertisement
$(".advertisement").fadeOut(function() {
$(this).load("inc/incfiles/content_container/advertisement/" + quelle).fadeIn('normal');
})
// header
$(".contentHeader").fadeOut(function() {
$(this).load("inc/incfiles/content_container/header/" + quelle).fadeIn('normal');
})
});
$(".navigation li").click(function() {
$(".menuImage").removeClass("menuImageActive1");
$(".menuImage").removeClass("menuImageActive2");
$(".menuImage").removeClass("menuImageActive3");
$(".menuImage").removeClass("menuImageActive4");
$(".menuImage").removeClass("menuImageActive5");
$(".menuImage").removeClass("menuImageActive6");
});
$("#1").mousedown(function() {
$("#menuImage1").addClass("menuImageClick1"); // new class on mouse button press
});
$("#1").mouseup(function() {
$("#menuImage1").removeClass("menuImageClick1"); //remove class after mouse button release
});
$("#1").click(function() {
$("#menuImage1").addClass("menuImageActive1");
});
$("#2").mousedown(function() {
$("#menuImage2").addClass("menuImageClick2"); // new class on mouse button press
});
$("#2").mouseup(function() {
$("#menuImage2").removeClass("menuImageClick2"); //remove class after mouse button release
});
$("#2").click(function() {
$("#menuImage2").addClass("menuImageActive2");
});
$("#3").mousedown(function() {
$("#menuImage3").addClass("menuImageClick3"); // new class on mouse button press
});
$("#3").mouseup(function() {
$("#menuImage3").removeClass("menuImageClick3"); //remove class after mouse button release
});
$("#3").click(function() {
$("#menuImage3").addClass("menuImageActive3");
});
$("#4").mousedown(function() {
$("#menuImage4").addClass("menuImageClick4"); // new class on mouse button press
});
$("#4").mouseup(function() {
$("#menuImage4").removeClass("menuImageClick4"); //remove class after mouse button release
});
$("#4").click(function() {
$("#menuImage4").addClass("menuImageActive4");
});
$("#5").mousedown(function() {
$("#menuImage5").addClass("menuImageClick5"); // new class on mouse button press
});
$("#5").mouseup(function() {
$("#menuImage5").removeClass("menuImageClick5"); //remove class after mouse button release
});
$("#5").click(function() {
$("#menuImage5").addClass("menuImageActive5");
});
$("#6").mousedown(function() {
$("#menuImage6").addClass("menuImageClick6"); // new class on mouse button press
});
$("#6").mouseup(function() {
$("#menuImage6").removeClass("menuImageClick6"); //remove class after mouse button release
});
$("#6").click(function() {
$("#menuImage6").addClass("menuImageActive6");
});
$("#1").click(function(){
$(".navigationDart").animate({
top: "16px"
}, 500 );
});
$("#2").click(function(){
$(".navigationDart").animate({
top: "88px"
}, 500 );
// Get the src of the image
// var src = $(this).css("top");
// Send Ajax request to backend.php, with src set as "img" in the POST data
// $.post("/home.php", {"#2": top});
});
$("#3").click(function(){
$(".navigationDart").animate({
top: "160px"
}, 500 );
});
$("#4").click(function(){
$(".navigationDart").animate({
top: "232px"
}, 500 );
});
$("#5").click(function(){
$(".navigationDart").animate({
top: "304px"
}, 500 );
});
$("#6").click(function(){
$(".navigationDart").animate({
top: "376px"
}, 500 );
});
});
You can use sessions. When you load content through ajax, store that response into a session variable and in your navigation you can add an if condition
if(isset($_SESSION['ajaxresponse'])) etc.
Ok, in your php file which serves your ajax request, please add the following line
// assuming that your contents can be stored in a variable $contents
$_SESSION['mycontent'] = $contents;
Now where you display your ajax response, add the following line of code there
if(isset($_SESSION['mycontent']) && !empty($_SESSION['mycontent']))
echo $_SESSION['mycontent'];
Make sure you are declaring session_start();
Hope this would be helpful! Sorry! If I could not understand the scenario of your problem.