Problems with ionic back button - javascript

I have a problem with the back button of my application.
Initially I thought that the problem was in Cordova, but I have identified that the problem is actually in Ionic.
I found this code while researching for a solution:
// Disable BACK button on home
$ionicPlatform.registerBackButtonAction(function (event) {
if($state.current.name=="app.home"){
navigator.app.exitApp();
}
else {
navigator.app.backHistory();
}
}, 100);
However, it is giving the following error:
Uncaught ReferenceError: $ionicPlatform is not defined
I am putting that code within a new document called functionAngular.js and I add it at the end of the body tag. As I must inform this function ?
My problem is that:
I want my back button to send the user further back in the navigation stack instead of closing the application instantly.
I am grateful for this help.

I recommend you first add $ionicPlatform in controller, and in the first controller loaded, test every state (see below) that the back button should have different actions.
$ionicPlatform.registerBackButtonAction(function () {
if ($state.current.name == " login (example) ") {
ionic.Platform.exitApp();
}
if ($state.current.name == " main menu buttons (example) ") {
// Sample message "want to exit the application?" (YES/NO)
if (YES) {
$ionicViewSwitcher.nextDirection('back');
$state.go(' ????');
};
};
if ($state.current.name == " order (example) ") {
// Sample message "want to exit the order?" (YES/NO)
if (YES) {
$ionicViewSwitcher.nextDirection('back');
$state.go(' ????');
};
};
}, 100);

angular.module('EGLISE')
.run(function($ionicPlatform,$state,$ionicHistory){
$ionicPlatform.registerBackButtonAction(function (event) {
if($state.current.name=="app.home"){
navigator.app.exitApp();
}
else {
$ionicHistory.backHistory();
}
}, 100);
});
Please modify your functionAngular.js to the above code.

Related

YouTube modal static

We have a page with a YouTube video modal, but get the following error when clicking on the video:
Uncaught TypeError: $(...).on is not a function
at HTMLAnchorElement.<anonymous> ({bfd8100b-7a47-4b28-9e6d-e26f4a7d9ed9}_ytplayer001.js:747)
at HTMLAnchorElement.handle (jquery.tools.min.js:75)
at HTMLAnchorElement.o (jquery.tools.min.js:69)
The video modal pops up like it should, but shows a "snowy" screen and the video player controllers are non-responsive. I thought it might be related to a conflict issue and changed
}(jQuery));
to
}(jQuery.noConflict()));
but the problem still exists. I'm thinking I'm missing something very obvious, but after several days of troubleshooting, still can't figure it out.
UPDATE - When I remove the jquery.tools.min.js file, the video plays, but the form validation quits working. So there's something about that jquery.tools.min.js file that's clashing with the YouTube videos.
UPDATE - Replacing the jquery.tools.min.js with the current version fixed the issue with the video and form validation. All that remains is figuring out why the close button on the video modal is not working. When opening the video modal, the following error appears:
TypeError: $(...).on is not a function
$('.vid-close').on('click', function () {
Change this:
$(document).on('click', '.vid-close', function () {
$('#vidlightbox').hide();
if (videosource == "youtube") {
$('#vidcontent').empty();
att.entbus.ytPlayer.stopAll();
} else {
if (jwplayer('jwPlayer') != null) {
try {
jwplayer('jwPlayer').remove();
} catch(err) {}
}
}
});
To this:
$('.vid-close').on('click', function () {
$('#vidlightbox').hide();
if (videosource == "youtube") {
$('#vidcontent').empty();
att.entbus.ytPlayer.stopAll();
} else {
if (jwplayer('jwPlayer') != null) {
try {
jwplayer('jwPlayer').remove();
} catch(err) {}
}
}
});

Exit windows app confirmation button not working

I am developing a windows app with an exit button to exit the app with a confirmation. The button is placed on the top of the app using html5, jquery-mobile, ajax, and phonegap. The problem is with me, I used the code that it's written below and is not working in windows app.
Even the alert is not working.
So i used
var msg = new Windows.UI.Popups.MessageDialog("No image is selected");
msg.showAsync();
And it is working fine. Can anyone help me to find the problem out?
navigator.notification.confirm("Do you really want to close this app?", function (buttonIndex) {
ConfirmExit(buttonIndex);
},
"Confirmation",
"Yes,No"
);
function ConfirmExit(stat) {
alert("Inside ConfirmExit");
if (stat == "1") {
navigator.app.exitApp();
} else {
return;
};
};
The way you are calling the function, and the alert!
I haven't tried this but I think you may it a try
navigator.notification.confirm("Do you really want to close this app?"
, ConfirmExit,
"Confirmation",
["Yes","No"]
);
and there is navifator.notification.alert to alert a message
function ConfirmExit(stat) {
//alert("Inside ConfirmExit");
navigator.notification.alert("Inside ConfirmExit", null, "Alert", null)
if (stat == "1") {
navigator.app.exitApp();
}
};

turn on and off chrome extension

I am working on a chrome extension ,this extension have 2 icons in the browser action (On & Off) ;
basically when it is On the background execute the script.js (Inject the file:script.js)
using the chrome.tabs.executeScript(tab.id,{file:"script.js",function(){});
I had problems to turn it off !
I have tried to use messages communication between the background.js and the script.js but this does not work neither .
If I understand correctly, your extension should have two states, On and Off. Clicking the extension icon toggles it on/off.
In this case you should use storage so the extension knows what state it is in. So on a click event, use something like:
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.storage.sync.get('state', function(data) {
if (data.state === 'on') {
chrome.storage.sync.set({state: 'off'});
//do something, removing the script or whatever
} else {
chrome.storage.sync.set({state: 'on'});
//inject your script
}
});
});
Note though that this is happening at the extension/browser level and will apply to all tabs, so you may need something more complex that records both the tab ID and the state.
You then have the choice to either always run a content script and check the on/off state before performing some action, or inject and remove the script. I'm not sure if you remove a script though. Depending on what the script does, you may just want to refresh the page (i.e. if your script messes with the DOM and you want to undo that when turning the extension off).
background.js
var enable=false;
chrome.browserAction.onClicked.addListener(function (tab) {
enable = enable ? false : true;
if(enable){
//turn on...
chrome.browserAction.setIcon({ path: 'icon.png' });
chrome.browserAction.setBadgeText({ text: 'ON' });
chrome.tabs.executeScript(null, { file: 'content.js' });
}else{
//turn off...
chrome.browserAction.setIcon({ path: 'disable.png'});
chrome.browserAction.setBadgeText({ text: '' });
}
});
To add onto what #david-gilbertson stated for making it active and inactive for certain tabs, I have created that functionality here. I also took added some functions for removing and adding tabs to the array. Enjoy!
function addTab(array, new_tab_id)
{
array.push(new_tab_id);
//then call the set to update with modified value
chrome.storage.sync.set({
active_tabs:array
}, function() {
console.log("added tab");
});
}
function removeTab(array, rem_tab_id)
{
const index = array.indexOf(rem_tab_id);
if (index > -1) {
array.splice(index, 1);
}
//then call the set to update with modified value
chrome.storage.sync.set({
active_tabs:array
}, function() {
console.log("removed tab");
});
}
chrome.browserAction.onClicked.addListener(function (tab) {`enter code here`
chrome.storage.sync.get({active_tabs : []}, function(data) {
if (data.active_tabs.includes(request.tab_id)) {
removeTab(data.active_tabs, request.tab_id)
console.log("Turned Off ".concat(request.tab_id))
document.removeEventListener("mousemove", highlightCurrentHover, false);
} else {
addTab(data.active_tabs, request.tab_id)
console.log("Turned On ".concat(request.tab_id))
document.addEventListener('mousemove', highlightCurrentHover, false);
}
});
);

Error when using `delete` as property name

I have a form that is deleting a gallery from a database. The code was working until a couple of weeks ago and I had other problems with it having to switch from jquery.interface to jquery-ui but now when I try to re-submit my changes to the svn I get an error. invalid property id. the line that throws the error is this:
post:$("#post").val(), delete:true
Whole code snippet is:
var answer = confirm("This will permanently delete this entire gallery. Are you sure you want to proceed?");
if (answer) {
$.post(
"admin-ajax.php?action=gallery_submit",
{ post:$("#post").val(), delete:true },
function(data){
if (data == 1) { //success
$('body').html('<div class="success">Your gallery has been successfully deleted.</div>');
setTimeout(function() { tinyMCEPopup.close(); }, 2000);
} else { //error
alert('There was an error with deleting your gallery, and so, it was NOT deleted.\n\r\n\rThe following error was encountered:\r\n' + data);
}
}
);
Did some syntax change for $.post that I have not been aware of, I checked the docs and do not see anything that matches.
Delete is a reserved word, so you must quote it.
{ post:$("#post").val(), "delete":true },

FormNavigate with confirm box yes no button

When a user leaves a JSP page, I need to display a confirmation with yes no button "You have unsaved changes. Do you want to leave it without saving?". If the user presses "ok", then the user goes to the page s/he is navigating to. Otherwise, if "no" is pressed, the user stays on the page. My code is here:
var formdata_original=false;
jQuery(".outConfirmPlugin").click(function () {
if (formdata_original == false) {
con();
}
return formdata_original;
});
function con() {
$.confirm({
'title':'',
'message':settings.jsMessage,
'buttons':{
'Yes':{
'class':'blue',
'action':function () {
formdata_original = true;
}
},
'No':{
'class':'gray',
'action':function () {
}
}
}
});
};
I know my error is: function "con" and "return formdata_original;" - they are not synchronized. How can i do this?
try return simple value from you function, i mean
action':function () {
return true;
}
and when you call 'con' function you will be able to write
formdata_original = con();
In this case you can not worry about sinhronize
The second option is creation global object that belongs ot window or $. So try
window["formdata_original"] = false
and in your code inside confirm dialog
window["formdata_original"]=true.

Categories