I have a main menu and one of its options has an accordion effect on toggle with the following script:
$(document).ready(function(){
$(function(){
$("#accordion").accordion({
active: false,
autoHeight: false,
collapsible: true
});
});
});
When one of its sub-options is selected I add an active class with this:
jQuery.fn.slideFadeToggle = function(speed, easing, callback){
return this.animate({opacity: 'toggle', width: 'toggle'}, speed, easing, callback);
};
$(document).ready(function(){
$("#subNavUs").hide();
$("#us").click(function () {
$("#subNavSys").hide();
$("#subNavApp").hide();
$("#subNavAcc").hide();
$("#subNavUs").slideFadeToggle(800);
$('*').removeClass('active');
$(this).addClass('active');
return true;
});
$("#subNavSys").hide();
$("#sys").click(function () {
$("#subNavUs").hide();
$("#subNavApp").hide();
$("#subNavAcc").hide();
$("#subNavSys").slideFadeToggle(800);
$('*').removeClass('active');
$(this).addClass('active');
return true;
});
And this triggers a sub-menu, but when I select any of this new sub-menu's options to load a new page both the accordion menu and the sub-menu are back hidden. How can I make them stay open and show the active class I want to assign them?
Just added "navigation: true" to the accordion function. It was a beginner's mistake but I finally got it to work :)
I post it in case someone might have the same issue.
Related
I'm running into an issue where if a focus even is fired of by javascript on the current window's page it steals focus from my addons input. Is there a way to force an input in a panel to stay focused.
$(inputSelector).focusout(function(){
$(inputSelector).focus();
});
$(inputSelector).blur(function(){
$(inputSelector).focus();
});
I have tried the above which seems to work on my test page but not in my panel :(.
According to the docs -> https://developer.mozilla.org/en-US/Add-ons/SDK/High-Level_APIs/panel
Setting focus to false should
Set to false to prevent taking the focus away when the panel is shown.
Only turn this off if necessary, to prevent accessibility issue.
Optional, default to true.
I have set my panel up as such.
var text_entry = require("sdk/panel").Panel({
width: text_entry_width,
height: text_entry_h,
focus: false, // doesnt seem to work....
contentURL: data.url("entry.html"),
contentScriptFile: [
data.url("jquery-2.1.1.min.js"),
data.url("text.js")
],
contentStyleFile: [
data.url("styles.css")
]
});
It doesn't append that setting it to false works :(.
Any help, guidance or comments would be awesome :) Cheers.
_____________ UPDATE ____________________________________________
There seemed to be some confusion of my bad explaining :( so i have uploaded a video to youtube that will hopefully explain the issue a bit better.
https://www.youtube.com/watch?v=5fhJzpa515Y&feature=youtu.be
Also below find some more code.
Panel Html
<html>
<head></head>
<body>
<div id="resultTableTop" class="resultTable"></div>
<input type="text" id="edit-box"></input>
<div id="resultTableBottom" class="resultTable"></div>
</body>
</html>
Hot Key Code
var showHotKey = Hotkey({
combo: "accel-t",
onPress: function() {
text_entry.show();
}
});
Panel js show listenter
self.port.on("show", function onShow() {
$('input').focus();
console.log('hi');
});
Hopefully this is a bit clearer now :) thanks for the help so far :).
This code focuses panel's input field when it opens:
main.js file:
//main.js file
var text_entry = require("sdk/panel").Panel({
focus: true, //THIS SHOULD BE TRUE
contentURL: data.url("panel.html"),
contentScriptFile: [
data.url("js/libs/jquery-1.11.1.js"),
data.url("get-text.js")
]
});
text_entry.on("show", function() {
text_entry.port.emit("show");
});
get-text.js file which is injected into panel:
//data/get-text.js file
self.port.on("show", function onShow() {
$('input').focus();
});
Here is a hacky, untested, solution:
var { viewFor } = require("sdk/view/core");
var { Panel } = require("sdk/panel");
var panel = Panel({
..
onShow: function() {
var view = viewFor(panel);
view.setAttribute("noautohide", "true");
}
})
For more information of the panel noautohide attribute click here.
I have a button which when clicked the first time it will load another html page.
When it is clicked the second time it will empty a div of the loaded page.
However, for some reason the loaded content keeps reappearing after the second click....
CSS:
#boatdiv {
width: 100%;
}
.clicked {}
HTML
<button id="load"></button>
<div id="boatdiv"></div>
jQuery
$(document).ready(function() {
$.ajaxSetup ({
cache: false
});
var loadURL = "AjaxLoad_injection.html";
$("#load").on("click", function() {
if(!($(this).hasClass("clicked"))){ //checks if button has NOT been clicked
$("#boatdiv").html("<p>loading...</p>").load(loadURL);
}
else {
$("#boatdiv").empty();
}
$("#boatdiv").toggleClass("clicked");
}
);
}); // end ready
What's going on?
You test $(#load) but toggle $("boatdiv").
Try :
$("#load").on("click", function() {
if(!($(this).hasClass("clicked"))){ //checks if button has NOT been clicked
$("#boatdiv").html("<p>loading...</p>").load(loadURL);
}
else {
$("#boatdiv").empty();
}
$(this).toggleClass("clicked");
});
You are toggling class on wrong element. You want it to toggle on the element being clicked. Same as code I gave you in last post.
Simple to walk through it, you are testing this... so need to toglle the class on this
Use
$(this).togglClass('clicked')
Remember that ajax calls are asynchronous. You may be clicking the button a second time before the ajax call has returned.
You could disable the button during the ajax call, like this:
$('#load').on('click', function() {
if (!$(this).hasClass("clicked")) {
$('#load').attr('disabled', true);
$("#boatdiv").html("<p>loading...</p>").load(loadURL, function() {
$('#load').attr('disabled', false);
});
} else {
$('#boatdiv').empty();
}
//$('#boatdiv').toggleClass("clicked");
$('#load').toggleClass("clicked");
});
The button is disabled before the ajax call. A callback function is passed as a second parameter to the "load()" function. It will be called when the ajax call returns. It will re-enable the button.
EDIT: I missed that the wrong element was getting the class toggled, but I still think you want to disable the button during the ajax call or things can get messed up.
I want to write code on Refresh button click of JQGrid. Is there any event for that?
If you need to do some actions before refresh will be started you should use beforeRefresh callback:
$("#grid_id").jqGrid('navGrid', '#gridpager', {
beforeRefresh: function () {
// some code here
}
});
If you need absolute another implementation of grid Refreshing where you will not call $("#grid_id").trigger("reloadGrid"); (which sound strange) you can do this by the usage of refresh: false option to remove the standard Refresh button and using navButtonAdd to add your custom button which looks exactly like the original one:
$("#grid_id").jqGrid('navGrid', '#gridpager', {refresh: false});
$("#grid_id").jqGrid('navButtonAdd', "#gridpager", {
caption: "", title: "Reload Grid", buttonicon: "ui-icon-refresh",
onClickButton: function () {
alert('"Refresh" button is clicked!');
}
});
The css for refresh button is ui-icon-refresh
so you can write your custom code on this css like
jQuery('.ui-icon-refresh').click(function(){
// do your work
});
I want to hide a button until other button is getting submitted.
ex. button1 is hidden.
button 2 visible
if(button2 submitted)
button 1 get visible.
can you tell a method to do that??
I'm rather new to jQuery, but I believe this may work:
HTML:
<form id="someform">
...
</form>
JS:
$(function() {
$('#button1').hide();
}
$('#someform').submit(function() {
$('#button2').show();
}
Try this:
$('#button1').bind('click', function() {
$(this).hide();
$('#button2).show();
});
$('#button2').bind('click, function() {
$(this).hide();
$('#button1).show()
});
I have a main window (app.js) and two sub-windows (login.js and signUp.js)
Here is my app.js
var login=Titanium.UI.createWindow({
url:'wins/login.js',
title:'Login',
backgroundColor:'#CCC',
navBarHidden:true
});
var signUp=Titanium.UI.createWindow({
url:'wins/signUp.js',
title:'Sign-up',
backgroundColor:'#CCC',
navBarHidden:true
});
login.open({fullscreen:true});
Now I want to open signUp.js from with login.js. Is there any way to do this? I've tried googling and reading over the documentation to no avail.
just typed this up, not perfect, but this is the general idea.
// create buttons on main window
var loginBtn = Titanium.UI.createButton({
title : 'LOGIN'
});
var signUpBtn = Titanium.UI.createButton({
title : 'SIGN UP'
});
// add to window
mainWindow.add(loginBtn);
mainWindow.add(signUpBtn);
// associate click events
loginBtn.addEventListener('click', function() {
Ti.API.log('loginBtn button clicked, show window');
login.open();
});
signUpBtn.addEventListener('click', function() {
Ti.API.log('signUpBtn button clicked, show window');
signUp.open();
});