My Resume, Ready and Paused events work just fine. I have problem with online/offline events. When I put my device in Airplane mode and vice verse nothing happens. When I disconnect from Internet I don't get any result. This is My code:
var app ={
initialize:function() {
this.bindEvents();
this.testzone = {};
},
bindEvents:function(){
document.addEventListener("deviceready", this.onDeviceReady,false);
document.addEventListener("pause", this.onPause,false);
document.addEventListener("resume", this.onResume,false);
},
onDeviceReady:function() {
document.addEventListener("online", this.onOnline,false);
document.addEventListener("offline", this.onOffline,false);
console.log("Readyii");
app.testzone = document.getElementById("test-zone");
app.testzone.innerHTML = "Readyii";
},
onPause: function() {
app.testzone.innerHTML += "<br />Paused";
},
onResume: function() {
app.testzone.innerHTML += "<br />Resumed";
},
onOnline: function() {
app.testzone.innerHTML += "<br />Online";
},
onOffline: function() {
app.testzone.innerHTML += "<br />Offline";
}
}
The below codes were actually in bindEvents at first, but I moved them inside onDeviceReady:
document.addEventListener("online", this.onOnline,false);
document.addEventListener("offline", this.onOffline,false);
Change the scope of the method calls in your online and offline eventlisteners.
So instead of this.onOnline use app.onOnline (or replace app with the parent).
document.addEventListener("online", app.onOnline,false);
document.addEventListener("offline", app.onOffline,false);
instead of using addEventListener
document.addEventListener("online", onOnline, false);
document.addEventListener("offline", onOffline, false);
use this
if(window.navigator.onLine){ alert('online'); }else{ alert('offline'); }
after adding the "cordova plugin add cordova-plugin-network-information" the
window.navigation.onLine will work on mobile
Related
Taking inspiration from Google's page, I pasted this into my website:
var CACHE_NAME = 'my-site-cache-v1';
var urlsToCache = [
'serviceworker.css'
];
debugger // 1
self.addEventListener('install', function(event) {
debugger // 2
event.waitUntil(
caches.open(CACHE_NAME)
.then(function(cache) {
console.log('Opened cache');
return cache.addAll(urlsToCache);
})
);
});
Debugger 1 stops the program flow, but debugger 2 is never reached.
ServiceWorker.css exists.
I'm navigating to the page using the Incognito window with the developer toolbar open.
The code in your snippet above must be loaded in via register. You will need to be developing with https to see this work
if ('serviceWorker' in navigator) {
window.addEventListener('load', function() {
navigator.serviceWorker.register('./codeWithYourJsAbove.js').then((function(registration) {
console.log('ServiceWorker registration successful with scope: ', registration.scope);
}), function(err) {
console.log('ServiceWorker registration failed: ', err);
});
});
}
I have following javascript that is using a selection changed to fill in a select list.
$(function () {
$("#bedrijvenauto").each(function () {
var target = $(this);
var dest = target.attr("data-autocomplete-destination");
target.autocomplete({
source: target.attr("data-autocomplete-source"),
select: function (event, ui) {
alert('selected bedrijf');
event.preventDefault();
target.val(ui.item.label);
$(dest).val(ui.item.value);
$("#projectenauto").val("");
alert('selected bedrijf');
alert($('#BEDRIJF_ID').val());
$.getJSON("/Project/GetListViaJson", { bedrijf: $('#BEDRIJF_ID').val() }, function (data) {
alert('selected bedrijf');
alert(data);
$("#PROJECT_ID").empty();
$("#PROJECT_ID").append(new Option("Maak een selectie", 0));
for (var i = 0; i < data.length; ++i) {
alert(data[i].value + ' ' + data[i].label);
$("#PROJECT_ID").append(new Option(data[i].label, data[i].value));
}
});
},
focus: function (event, ui) {
event.preventDefault();
target.val(ui.item.label);
}
});
target.val($("#BEDRIJF_NAAM").val());
});
It works like a charm on my development pc. The alert are all coming out even the data is returning results. That is the difference with the development pc that does not give any results after the call to getJSON
I have the feeling I am missing a detail here.
I am not used to debugging on a webserver because I usually create GUI applications in WPF, and this is a student's work for his vacation and I now got to get it working without him being around anymore. Vacation is done :-(
But not for me.
The 404 error indicated in your comments means the url your creating is incorrect. Always make use of the #Url.Action() method to ensure they are correctly generated. In your script
var url = '#Url.Action("GetListViaJson", "Project")';
$.getJSON(url, { bedrijf: $('#BEDRIJF_ID').val() }, function (data) {
....
}
or if this is an external script, then add the var url = '#Url.Action(...)'; in the main view (razor code is not evaluated in external script files), or add it as a data- attribute to the element your handling
data-url = "#Url.Action(...)"
and get it again using var url = $(someElement).data('url');
i'd like to do user friendly action at my app.
The issue is:
I have one button. When user 'mousedown' on it, i send ajax query to server to get some info. What i want is to show that info only after user 'mouseup' on this button. In other words, when he releases mouse button.
The problem is that user can release mouse button before or after server answers to my ajax call, by i still want to show info only after release button.
I think i can do this with deferred stuff, by i don't have a lot experience in this. Can you give me some info, how to do this?
Example code:
.html
<input type='button' ng-start='start()' ng-end='end()' >
.js
$scope.start = function(){
$http.get(url, data).success(function(result){})
}
$scope.end = function(){
//show result from first function
}
Tried to do it with use of $q, but it appears that $q is not necessary.
.html
<input type='button' ng-mousedown='start()' ng-mouseup='end()' >
<div ng-show="loaded && resolved" ng-bind="processedResult"></div>
.js
$scope.start = function(){
$scope.resolved = false;
$scope.loaded = false;
$http.get(url, data).success(function(result){
$scope.loaded = true;
$scope.processedResult = processResult(result);
});
};
$scope.end = function(){
$scope.resolved = true;
};
I think, i've solved my problem with pretty promise feature.
.html
<input type='button' ng-start='start()' ng-end='end()' >
.js
$scope.start = function() {
promise = $q.when($scope.ApiCall())
.then(function(result){
return result.data;
}, function(error){
console.log(error);
})
;
};
$scope.end = function() {
promise.then(function(result){
processResult(result.datat);
});
};
$scope.ApiCall = function(){
var data = {};
return $http.get(url, {params: data});
}
I´m developing a TFS 2012 web access custom control and I need to change some workitem field values when the save workitem button is clicked.
I’ve just developed the same custom control for Visual Studio and I’ve performed these changes in the IWorkItemControl.FlushToDatasource method but I don't know how to achieve the same at web access control.
I’ve tried to change the workitem field values in the invalidate function when the workitem is being saved,
invalidate: function (flushing) {
if (this._workItem.isSaving()) {
this._workItem.getField("FieldName").setValue("newValue");
}
},
But it does not work, although the changes made while saving the workitem are included in the list of updated fields, they are not saved.
Any idea how can it be implemented by using the Javascript API?
Thanks.
Oscar
Can you try this:
_control: null,
_init: function() {
alert("_init() called!");
debugger;
if (this._workItem) {
var originalEstimate = this._workItem.getField("Microsoft.VSTS.Scheduling.OriginalEstimate").getValue();
alert('OriginalEstimate value is ' + originalEstimate);
console.log('this in _init');
console.log(this);
} else {
alert('_workItem is null or undefined!');
console.log('this in _init');
console.log(this);
}
this._base();
this._control = $("<div style='width:100%;height:100%;background-color:lightblue;'><button type='submit'>CLICK ME!</button></div>").appendTo(this._container).bind("click", delegate(this, this._onClick));
},
invalidate: function(flushing) {
alert("invalidate(flushing) called!");
var value = this._getField().getValue();
debugger;
if (this._workItem) {
var originalEstimate = this._workItem.getField("Microsoft.VSTS.Scheduling.OriginalEstimate").getValue();
alert('OriginalEstimate value is ' + originalEstimate);
console.log('this in _init');
console.log(this);
} else {
alert('_workItem is null or undefined!');
console.log('this in _init');
console.log(this);
}
alert(value);
},
clear: function() {
alert("clear() called!");
},
_onClick: function() {
alert("Butona tıklandı!");
}
I am using jPlayer to play audio files.
If I use the player on content, which is privided, when the page gets loaded, it works without any problems.
I also need it for HTML which is inserted by AJAX. Here it does not work. It seems, that the ready event is not triggered.
I wrote a function, which can be executed by click(). In that way, I can click it manually, when the HTML which contains the player is fully loaded. Here I have the same problem: The ready event is not triggered.
This is my function which works on non ajax inserted players fine:
$('.jp-jplayer').each(function () {
var src = $(this).attr('data-src');
var id = $(this).attr('id');
var post_id = $(this).attr('data-id');
alert('beg');
$('#' + id).jPlayer({
ready: function () {
$(this).jPlayer('setMedia', {
mp3: "/prelisten/_lofidl/change_of_heart_full_lofi.mp3",
});
alert('#' + id);
},
swfPath: "/wp-content/themes/Dark_3Chemical_DE_mit_Pagenavi/Dark_3Chemical_DE/audioplayer/js",
//////ERRRROOOOOR
solution: "flash, html",
supplied: "mp3",
wmode: "window",
cssSelectorAncestor: "#jp_container_" + post_id,
play: function () { // To avoid both jPlayers playing together.
$(this).jPlayer("pauseOthers");
},
repeat: function (event) { // Override the default jPlayer repeat event handler
if(event.jPlayer.options.loop) {
$(this).unbind(".jPlayerRepeat").unbind(".jPlayerNext");
$(this).bind($.jPlayer.event.ended + ".jPlayer.jPlayerRepeat", function () {
$(this).jPlayer("play");
debug($(this));
});
} else {
$(this).unbind(".jPlayerRepeat").unbind(".jPlayerNext");
$(this).bind($.jPlayer.event.ended + ".jPlayer.jPlayerNext", function () {
//$("#jquery_jplayer_4858").jPlayer("play", 0);
});
}
},
});
$("#jplayer_inspector").jPlayerInspector({
jPlayer: $('#' + id)
});
});
Currently I am setting the src manually to exclude any possible errors here.
How can I get this function running on AJAX inserted content?
EDIT:
This is the code, which fetches the html including the players:
$.get('/query_posts.php', {
paged: _page,
cats: cols
}, function(data) {
$('#search-results').append(data).fadeIn(300);
//create_player_scripts();
//set_players();
$('#search-results').find('input[name="cartLink"]').each(function() {
$(this).val($(this).closest('.post1').find('.post_headl a').attr('href'));
});
});
To make an AJAX page reload work I had to first destroy all jplayer instances. So I wrote a little function that grabs all instances of a jplayer on the site (by looking for jp-audio classes) and calls jplayer('destroy'); and jplayer('clearMedia'). This function gets called in the $.ajax({ beforeSend: destroyJplayerInstances(); })
UPDATE:
Here is a statement from the developer of jPlayer, Mark Panaghiston:
https://groups.google.com/forum/#!topic/jplayer/Q_aRhiyYvQo
Hope that helps!