How to Disable JqueryUI Accordian Section - javascript

Hi guys I'm trying to disable queryUI section ,I have only two section , so far I have tried some of my hacks but none seems to work ,
Here what I have tried so far,
//Enable section1 by remove attributes
$('#subfacEdit').removeAttr("disabled");//div
$('#subfacEdit').removeAttr("display");//div
$('#HeadersubfacEdit').removeAttr("disabled");//H3
$('#HeadersubfacEdit').removeAttr("display");//H3
//Disable section2
$('#facEdit').attr("disabled", "disabled");//div
$('#facEdit').attr("display", "none");//div
$('#HeaderfacEdit').attr("disabled", "disabled");//H3
$('#HeaderfacEdit').attr("display", "none");//H3
$('#editAccdordian').accordion("activate", 1);//activate section2
Analysis:
Div does becomes disabled but I guess display attributes is not applied,I only want make sections unclickable by any means.
I have tried MasterMinds Solution with little change ?
http://jsfiddle.net/X8MFf/15/

You could add a special data- attribute to the ones you want to disable, say data-enabled="false". Then, using the beforeActivate event, prevent from switching. Something along the lines of
$( "#EditAccdordian" ).on( "accordionbeforeactivate", function( event, ui ) {
if( ui.newHeader && ui.newHeader.attr('data-enabled') == 'false') {
event.preventDefault();
}
} );
You can also bind the event in the accordion creation.
$( "#EditAccdordian" ).accordion({
beforeActivate: function( event, ui ) {
if( ui.newHeader && ui.newHeader.attr('data-enabled') == 'false') {
event.preventDefault();
}
}
});
Your disabled header should now look like:
<h3 id="HeaderfacEdit" data-enabled="false">Header content</h3>
EDIT:
I removed the jquery selection of ui.newHeader because it is a jquery object. Validation of the object should be done as it is empty when collapsing (see documentation).

Try this will work for you...
$(".DISABLE").click(function(){
$(this).next().hide();
$("#accordion").accordion({active:current});
});
Complete Example
...
//JAVASCRIPT
$(document).ready(function() {
var $accordion = $("#accordion").accordion({ collapsible: true });
$( "#accordion" ).accordion( "option", "clearStyle", true );
var current=null;
$("#accordion h3:not(.DISABLE)").click(function(){
current = $accordion.accordion("option","active");
});
$(".DISABLE").click(function(){
$(this).next().hide();
$("#accordion").accordion({active:current});
});
});
...
//HTML
<div id="accordion">
<h3>Section 1</h3>
<div>
MUK - 1
</div>
<h3 **class="DISABLE"**>Section 2 (Disabled)</h3>
<div>
MUK - 2
</div>
<h3>Section 3</h3>
<div>
MUK - 3
</div>
<h3>Section 4</h3>
<div>
MUK - 4
</div>
</div>

Related

Open and close divs with jquery

I am doing a comment system for my webpage.
The website shows a group of elements from the database, that everyone can comment:
Element 1 ($element_id=1)-> Read comments...
Element 2 ($element_id=2)-> Read comments...
Element 3 ($element_id=3)-> Read comments...
When someone want to read comments of one element, can click in the "Read comments...", and a new div opens:
<div class="comments_more" id="comments_more"> Read comments...
<div class="comments_div" id="comments_div" >
<?php include/comments.php ?>
<?php echo $element_id; ?>
</div> </div>
The jquery code to open the div works perfect for every element:
$(document).ready(function(){
$( '.comments_more' ).click(function() {
$(this).find( '#comments_div' ).show('slide');
});
})
Now, I found a nice jquery to close the div when user clicks outside of it:
$(document).mouseup(function (e){
var container = $("#comments_div");
if (!container.is(e.target) // if the target of the click isn't the container...
&& container.has(e.target).length === 0) // ... nor a descendant of the container
{ container.hide(); }
});
The problem is that it only works for the first "Read comments..." (first element).
You can't have multiple IDs on one page, try using a class as a selector instead like:
$(".comments_div")
I'm guessing here at what the repeated HTML looks like, but try something like this:
$(document).ready(function() {
$('.comments_more').click(function() {
$(this).find('.comments_div').show('slide');
});
})
$(document).mouseup(function(e) {
var container = $(".comments_div");
if (!container.is(e.target) && container.has(e.target).length === 0)
{
container.hide();
}
});
.comments_div {
display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div class="comments_more"> Read comments...
<div class="comments_div">
Comments 1
</div>
</div>
<div class="comments_more"> Read comments...
<div class="comments_div">
Comments 2
</div>
</div>
<div class="comments_more"> Read comments...
<div class="comments_div">
Comments 3
</div>
</div>

Toggle elements view on buttons click

I have different divs which all have the same class "textBox".
At the same time there should always just be one box displayed. For most Boxes there is a button on the bottom of my page which can be clicked and triggers
to make the box visible and hide the box which is already shown at this moment.
Edit: Fiddle https://jsfiddle.net/8uvsq7ta/
For this I have this JS-code:
$( "#gettingStartedButton" ).click( function () {
if (! $( "#gettingStarted" ).is( ":visible" ) ) {
if ( $( "#extension" ).is( ":visible" ) ) {
$( "#extension" ).fadeOut( function () {
$( "#gettingStarted" ).fadeIn();
});
}
else if ( $( "#executingBox" ).is( ":visible" ) ) {
$( "#executingBox" ).fadeOut( function () {
$( "#gettingStarted" ).fadeIn();
});
}
else if ( $( "#feedback" ).is( ":visible" ) ) {
$( "#feedback" ).fadeOut( function () {
$( "#gettingStarted" ).fadeIn();
});
}
else if ( $( "#impressum" ).is( ":visible" ) ) {
$( "#impressum" ).fadeOut( function () {
$( "#gettingStarted" ).fadeIn();
});
}
else if ( $( "#registration" ).is( ":visible" ) ) {
$( "#registration" ).fadeOut( function () {
$( "#gettingStarted" ).fadeIn();
});
}
}
else {
$( "#gettingStarted" ).fadeOut( function () {
$( "#executingBox" ).fadeIn();
});
}
});
The div boxes look like this:
<div id="gettingStarted" class="textBox">
test blabla
</div>
<div id="feedback" class="textBox">
test blabla
</div>
<div id="registration" class="textBox">
test blabla
</div>
<div id="impressum" class="textBox">
test blabla
</div>
CSS:
.textBox {
diplay: none;
}
This Code checks if the box is already shown and if yes it checks EVERY OTHER BOX to get the one which is visible and then fade it out to afterwards fade the reffered box in.
My problem is, I need this part of code for every box. I think there should be a better way to accomplish this.
What I am searching is kind a method openBox(id) where I give the id of the box as paramete and it automatically detects all other boxes with the class parameter and detects which is already faded in, then fades this out to fade the box with the id in.
Sadly my javascript skills aren't that good, so I seek to find some advices or examples how to achieve this.
Thank you very much for every input you can give me.
var $textBox = $(".textBox"); // get 'em all!
$textBox.eq(0).fadeIn(); // FadeIn first one
$("[data-showid]").on("click", function(){ // Buttons click (Use data-* attribute!)
var $box = $("#"+ this.dataset.showid); // Get the target box ID element
$textBox.not($box).hide(); // Hide all bot targeted one
$box.stop().fadeToggle(); // FadeToggle target box
});
.textBox{display:none;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="gettingStarted" class="textBox">getting started blabla</div>
<div id="feedback" class="textBox">feedback blabla</div>
<div id="impressum" class="textBox">impressum blabla</div>
<button data-showid="gettingStarted">GS</button>
<button data-showid="feedback">FB</button>
<button data-showid="impressum">Imp</button>
If you don't want the current box to toggle, than instead of .fadeToggle() use .fadeIn().
http://api.jquery.com/fadetoggle/
https://api.jquery.com/data/
https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dataset
With the addition of a data-* attribute on your button to link it to its content:
<button id="gettingStartedButton" data-link="gettingStarted">GS</button>
<button id="feedbackButton" data-link="feedback">FB</button>
<button id="impressumButton" data-link="impressum">Imp</button>
The javascript becomes very simple:
$( "#gettingStarted" ).fadeIn();
$('button').click(function(){
var link = $(this).data('link');
$('.textBox:visible').fadeOut(function(){
$('#' + link).fadeIn()
});
})
Updated fiddle: https://jsfiddle.net/8uvsq7ta/2/
I did it using class. The HTML would be like :
<div class="textBox gettingStartedButton" style="display: none;"> 1 test blabla </div>
<div style="display: none;" id="feedback" class="textBox .gettingStartedButton gettingStartedButton"> 2 test blabla </div>
<div id="registration" class="textBox gettingStartedButton" style="display: block;">3 test blabla </div>
<div id="impressum" class="textBox"> 4 test blabla </div>
And use the code below. Keep any element visible at first. Then on click of that element it fades it out and fades the next element in. and adds the class "gettingStartedButton" to the visible element to run click event again.
$( ".gettingStartedButton" ).on('click', function () {
var visible_element = $('.textBox:visible');
visible_element.next().fadeIn();
visible_element.next().removeClass('gettingStartedButton');
visible_element.next().addClass('gettingStartedButton');
visible_element.fadeOut();
});

jquery draggable on few divs

Picture:
<div id="grid-wrapper">
<div id="grid"></div>
<div id="grid"></div>
<div id="grid"></div>
<div id="grid"></div>
</div>
I want to change class on two divs when I drop my span, and remove draggable.
I have this:
$( ".dragandrop" ).draggable({ snap: "#grid" });
$("#grid").droppable({
drop: function( event, ui ) {
$( this )
.addClass( "droped" )
}
});
This code add me .droppable only on first div, and doesn't add class "droped", I can't do removing .draggable. Can you help me?
First off, be careful using the same id for multiple elements. It can cause really weird issues (see this post).
Second, make sure you add the draganddrop class to the appropriate elements that you want to, well, drag and drop.
And you want to removed the draggable on an element once you dropped it? I think what you want looks something like this:
$( ".dragandrop" ).draggable({
snap: ".dragandrop" ,
stop: function(event, ui){
$( this ).addClass( "droped" );
$( this ).draggable( 'disable' );
}
});
$(".dragandrop").droppable({});
div{
padding: 20px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
<div id="grid-wrapper">
<div id="grid1" style="background:orange;" class="dragandrop">a</div>
<div id="grid2" style="background:red;" class="dragandrop">b</div>
<div id="grid3" style="background:green;" class="dragandrop">c</div>
<div id="grid4" style="background:yellow;" class="dragandrop">d</div>
</div>
You may also want to add in some logic to keep the active div on top.

paragraph Select() doesn't work in javascript

Here is my html code
<div id="dialog" title="Basic dialog" style="display: none">
<p id="para">Copy this key</p>
<p id="key">4567887654345678</p>
</div>
<button>Open dialog</button>
The div appears as a dialog on button click, and I would like to have the "key" text selected when the dialog opens
Here is the javascript for the same, but the < p> doesn't appear to be selected
$(function() {
$( "button" ).click(function() {
$("#dialog" ).dialog();
$( "#dialog" ).show( "slow" );
$("#key").select();
});
});
How can I make the < p> be pre-selected ?
Change the key paragraph to an editable element, such as a textarea:
<textarea id="key">4567887654345678</textarea>
JSFiddle
It appears you need an editable text field to select text in.
I think you should use jQuery dialog open event:
$( "#dialog" ).dialog({
open: function( event, ui ) {
$("#key").select();
}
});
JSFiddle

collapse and expand tabs jquery / simple accordion

I have query regarding Accordion tabs ..
I have used Accordion Menu plugin Below code i have used for the tabs in the page .
[accordions]
[accordion title ="about"]**Content 1** [/accordion ]
[accordion title="Home"]**Content 2** [/accordion ]
[/accordions]
The web page looks like as follows:
I want first both these tabs to be collapsed and.When clicked on ABOUT it should expand and display the content .And once clicked on Home it should collapse ABOUT tab and expand the home page
By jquery i can achieve this but i dont know which script to download and work with it..
Any ideas??
Thanks in advance
I have two different methods for simple accordion; 1st with close button, 2nd is with hover trigger.
1) Here is JsFiddle example with close button:
jQuery:
$('.content').slideUp(400);//reset panels
$('.panel').click(function() {//open
var takeID = $(this).attr('id');//takes id from clicked ele
$('#'+takeID+'C').slideDown(400);
//show's clicked ele's id macthed div = 1second
});
$('span').click(function() {//close
var takeID = $(this).attr('id').replace('Close','');
//strip close from id = 1second
$('#'+takeID+'C').slideUp(400);//hide clicked close button's panel
});​
html:
<div class="panel" id="panel1">panel1</div>
<div id="panel1C">content1
<span id="panel1Close">X</span>
</div>
<div class="panel" id="panel2">panel2</div>
<div id="panel2C">content2
<span id="panel2Close">X</span>
</div>
<div class="panel" id="panel3">panel3</div>
<div id="panel3C">content3
<span id="panel3Close">X</span>
</div>
-------
​
2) Here is JsFiddle example with hover trigger:
$('.panel').hover(function() {
var takeID = $(this).attr('id');//takes id from clicked ele
$('.content').stop(false,true).slideUp(400);//close
//used stop for prevent conflict
$('#'+takeID+'C').stop(false,true).slideDown(400);//open
//show's clicked ele's id macthed div
});​
In case you use jQuery UI Accordion, you can add simple event to your accordion.
or add event:
$( ".selector" ).bind( "accordioncreate", function(event, ui) {
$( ".selector" ).accordion( "option", "active", -1 )
});

Categories

Resources