Menu with MooTools - ajax

I am using joomla 2.5 and I want to modified a <div> tag with ajax and mootools
In my index.php file I have this:
<div id="content" class="column grid_16">
<div id="content" class="column grid_4">
<jdoc:include type="modules" name="menuHardware" style="none"/>
<jdoc:include type="modules" name="menuArq" style="none"/>
</div>
<div id="content" class="column grid_9">
<jdoc:include type="modules" name="mod_arq" style="none"/>
</div>
<jdoc:include type="component" />
<jdoc:include type="modules" name="mod_fabricante" style="none"/>
<jdoc:include type="modules" name="mod_noticias" style="none"/>
</div>
This is my code in <jdoc:include type="modules" name="menuArq" style="none"/>:
<div id="content" class="column grid_4">
<ul class="menu">
<li class="item-129">Descripción</li>
<li class="item-130">Descripción</li>
<li class="item-131">Descripción</li>
<li class="item-132">Descripción</li>
<li class="item-133">Descripción</li>
</ul>
</div>
And my module <jdoc:include type="modules" name="mod_arq" style="none"/> have this:
<div id="myDivTobeChanged">some text for change</div>
So finally my page is:
<div id="content" class="column grid_16">
<div id="content" class="column grid_4">
<ul class="menu">
<li class="item-129">
Descripción
</li>
<li class="item-130">
<li class="item-131">
<li class="item-132">
<li class="item-133">
</ul>
</div>
<div id="content" class="column grid_9">
<div id="myDivTobeChanged">some text for change</div>
</div>
when I click here <li class="item-129">Descripción</li> I want to change this
<div id="myDivTobeChanged">some text for change</div>
This is my script to call ajax:
$$('.item-129').addEvent('click', function(event){
event.stop();
var req= new Request({
method: 'get',
url: '<?php echo JURI::root()?>index.php',
data: {'do': '1'},
onComplete: function(responseText){
$('myDivTobeChanged').set('html', responseText);
}
}).send();
});
But this don´t work only change to description page but not inside the <div> tag.

I see the div in your code has class 'grid_4', but the one you try to modify has 'column grid_9'. If you want to change the contents of a particular div it would be much better to refer to it by id or you will have to fetch an array of elements having particular class via $$('.grid-9').
Another problem is that you mix pure JavaScript with MooTools, that is generally a bad idea. If a MooTools library provide a function to solve your problem, it is better to use it rather than standard JavaScript. For example to change HTML contents of an element, use set('html', someHTML) rather than innerHTML method.
So, try giving your div to be changed an id and changing you line
document.getElementsByClassName('column grid_9').innerHTML= responseText;
to something like this:
document.id('#myDivTobeChanged').set('html', responseText);
This is a complete solution for illustration purposes that works. You can use it for reference:
//javascript
<script type="text/javascript">
window.addEvent('domready', function(){
$$('.item-129').addEvent('click', function(event){
event.stop();
var req = new Request({
method: 'get',
url: 'http://someurl.com/test.php',
data: { 'do' : '1' },
onComplete: function(responseText) {
$('myDivTobeChanged').set('html', responseText);
}
}).send();
});
});
</script>
//sample html
<div id="content" class="column grid_4">
<ul class="menu">
<li class="item-129">Descripción</li>
<li class="item-130">Descripción</li>
<li class="item-131">Descripción</li>
<li class="item-132">Descripción</li>
<li class="item-133">Descripción</li>
</ul>
</div>
<div id="myDivTobeChanged">som text for change</div>
Just make change the address the Request is send to and customize the id of the target HTML div to be changed

Related

Drupal dropdown menu that moves content down

I need to have a menu/mega menu that will shift the content down when the dropdown opens like on Facebook for Business menu: https://www.facebook.com/business
I saw the same effect on Avast: http://www.avast.com
Thanks for the help, it's much appreciated!
For behavior you want you can use: slideDown() function of JQuery. Then you can bind mouseover and mouseout events over menu items and call slideDown and slideUp function.
Example in JSFiddle
HTML:
<div class="container">
<div class="navbar navbar-default">
<div class="navbar-header">
<a class="navbar-brand" href="#">Bootstrap 3</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="dropdown active menu-item" data-menuItem="#getstarted">
Getting started <b class="caret"></b>
</li>
<li class="menu-item" data-menuItem="#css">CSS</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="active">Customize</li>
</ul>
</div>
</div>
<div class="col-xs-12 menu-panel" hidden="" id="getstarted">
<ul>
<li>Sign-in page</li>
<li>Sticky footer</li>
<li>Offcanvas</li>
<li>Carousel</li>
<li>Theme</li>
</ul>
</div>
<div class="col-xs-12 menu-panel" hidden="" id="css">
<ul>
<li>Sign-in page</li>
<li>Sticky footer</li>
</ul>
</div>
</div>
JavaScript:
$(".menu-item").mouseenter(
function(e){
e.preventDefault();
e.stopPropagation();
var $active=$(".active-menu-panel");
$active.removeClass("active-menu-panel").hide();
var selector=$(this).attr("data-menuItem");
if($active.length){
$(selector).addClass("active-menu-panel").show();
} else {
$(selector).addClass("active-menu-panel").slideDown();
}
}
);
$(".menu-panel").mouseleave(function(){
$(this).removeClass("active-menu-panel").slideUp();
});

FlexSlider click on pictures to bring up LightBox like ability

I have a FlexSlider/Carousel plug in working great on my site. Now, I would like to be able to click on the Slider image to bring up a lightbox like plug in so I can 'blow up' the images to be able to see more detail. I have read and tried to implement a lightbox: true attribute which sounds like it is supposed to do what I am looking for, but it doesn't seem to work. I can't click on the slider image to do anything.
<div id="main" role="main">
<section class="slider">
<div id="slider" class="flexslider">
<ul class="slides">
<li>
<img src="~/Images/Products/WoodenSign/PNG/1-AMORE.PNG" />
</li>
<li>
<img src="~/Images/Products/WoodenSign/PNG/2-LOVE.PNG" />
</li>
</ul>
</div>
<div id="carousel" class="flexslider">
<ul class="slides">
<li>
<img src="~/Images/Products/WoodenSign/PNG/1-AMORE.PNG" />
</li>
<li>
<img src="~/Images/Products/WoodenSign/PNG/2-LOVE.PNG" />
</li>
</ul>
</div>
</section>
</div>
<!-- jQuery -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="js/libs/jquery-1.7.min.js">\x3C/script>')</script>
<!-- FlexSlider -->
<script defer src="~/Scripts/jquery.flexslider.js"></script>
<script type="text/javascript">
$(function(){
SyntaxHighlighter.all();
});
$(window).load(function(){
$('#carousel').flexslider({
animation: "slide",
controlNav: false,
animationLoop: true,
slideshow: true,
itemWidth: 100,
itemMargin: 0,
asNavFor: '#slider'
});
$('#slider').flexslider({
animation: "slide",
controlNav: false,
animationLoop: true,
slideshow: true,
sync: "#carousel",
start: function(slider){
$('body').removeClass('loading');
},
lightbox: true
});
});
Just in case someone needs this. Try this:
<div id="slider" class="flexslider">
<ul class="slides">
<li>
<a href="~/Images/Products/WoodenSign/PNG/1-AMORE.PNG" data-lightbox="1000 500">
<img src="~/Images/Products/WoodenSign/PNG/1-AMORE.PNG" />
</a>
</li>
<li>
<img src="~/Images/Products/WoodenSign/PNG/2-LOVE.PNG" />
</li>
</ul>
</div>
A solution I'm using on a current WordPress project is "Responsive Lightbox" by dFactory. It uses the HTML element rel="lightbox" as a hook. Instant lightbox galleries!
<div class="flexslider">
<ul class="slides">
<li>
<a href="large-image-01.jpg" rel="lightbox">
<img src="thumb-image-01.jpg" />
</a>
</li>
<li>
<a href="large-image-01.jpg" rel="lightbox">
<img src="thumb-image-01.jpg" />
</a>
</li>
</ul>
</div>
<div class="flexslider">
<ul class="slides">
<li>
<a href="large-image-01.jpg" rel="lightbox">
<img src="thumb-image-01.jpg" />
</a>
</li>
<li>
<a href="large-image-01.jpg" rel="lightbox">
<img src="thumb-image-01.jpg" />
</a>
</li>
</ul> </div>
This is the one that worked for me - I also added a target="blank" to open a new window.

Navigating and updating content in a CodeIgniter application

I am using CI with Twitter Bootstrap for a basic site:
In my main layout view this is how the main content area is setup:
<div class="container-fluid">
<div class="row-fluid">
<div class="span1"></div>
<div class="span8">
<?php echo $this->load->view($subview); ?>
</div>
<div class="span3" id="sidebar">
<?php echo $this->load->view($this->global_data['sidebarview']); ?>
</div>
</div>
</div>
One sidebar view is this:
<div class="container-fluid" id="sidebar-about">
<div class="well sidebar-nav">
<ul class="nav nav-list">
<li class="nav-header"><i class="icon-info-sign"></i> More about us</li>
<li class="active">Who are we?</li>
<li>Why we did it?</li>
<li>What we promise?</li>
<li class="nav-header"><i class="icon-asterisk"></i> Services</li>
<li>Free</li>
<li>Premium</li>
</ul>
</div><!--/.well -->
</div><!--/span-->
Every link in this sidebar i want to update the div with class="span8" from my main layout.
How should i do that? Should i use ajax calls to update the content of the span8 div? or just create more methods in about controller?

Rails3 Twitter Bootstrap: async loading of a div

I have a set of nav-pills vertically stacked along the left. Each time I click on a pill I would like the div "report-html-content" to be loaded with the contents of html produced by the controller action corresponding to: program_reports_path(#program).
Seems very simple (sure, sure.) Here's the view:
<div class="container">
<div class="row">
<div class="span2">
<ul class="nav nav-pills nav-stacked">
<li>
Trend lines for all questions
</li>
<li>
<%= link_to "Summary of all questions", program_reports_path(#program),
:remote => true, id: "reports-navlist", data: {toggle: "tab"} %>
</li>
<li class="active">
Trend lines for all questions
</li>
<li>
Details on all questions
</li>
</ul>
</div>
<div class="span10" id="report-html-content">
</div>
</div>
</div>
Here's the controller action:
def report1
#program = Program.find(params[:program_id])
render :partial => "report1", layout: false
end
It ALMOST works. Except that asking a nav-pill set to do a remote: true to a different URL for some reason makes the activation and deactivation of the tabs not work anymore.
I have two questions:
1) Can you see my bug?
2) What's the best practice way for me to achieve this with Rails 3 and Twitter Bootstrap, noting that I definitely want the content of the clicked tab to be fetched with ajax because those reports can be costly to compute.
Thank you!
Overwrite show event like this:
<div class="container">
<div class="row">
<div class="span2">
<ul id="tabs" class="nav nav-pills nav-stacked">
<li>
Trend lines for all questions
</li>
<li>
Summary of all questions
</li>
<li class="active">
Trend lines for all questions
</li>
<li>
Details on all questions
</li>
</ul>
</div>
<div class="span10" id="report-html-content">
</div>
</div>
</div>
<script>
$(function() {
$('#tabs').bind('show', function(e) {
if ($(e.target).attr('id') == 'reports-navlist')
$.ajax({
url: '<%= program_reports_path(#program) -%>',
data: { toggle: "tab" }
})
});
});
</script>
You can read more about tabs events at http://twitter.github.com/bootstrap/javascript.html#tabs

Joomla - Multiple Instances of Module Divs

I'm used to using Joomla 1.5, and am trying to switch to 2.5.
I have 2 modules in the right position, I expect that there would be 2 boxes (which is what I want), one box for each module. But for some reason it's just adding the second module to the first box.
It's not copying the divs (main_top_box, main_mid_box, main_bottom_box) inside the if statement: <?php if($this->countModules('right')) { ?>, instead it's just putting the <jdoc:include type="modules" name="right"/> commands side by side.
You were able to do this with the code I've used in Joomla 1.5. Have they removed this functionality?
Here's what I see:
Here's what I should see:
Joomla Code:
<?php if($this->countModules('right')) { ?>
<div class="main_top_box">
<div class="main_mid_box">
<div class="main_bottom_box">
<jdoc:include type="modules" name="right"/>
</div>
</div>
</div>
<?php } ?>
Code Output(Source):
<div class="main_top_box">
<div class="main_mid_box">
<div class="main_bottom_box">
<div class="custom" >
<h3>Services</h3>
<ul>
<li>Family Law</li>
<li>Collaborative Law</li>
<li>Real Estate</li>
<li>Wills</li>
<li>Estate Planning</li>
<li>Estates</li>
</ul>
<p> </p>
</div>
<div class="custom" >
<h3>Test</h3>
<p>Testing the Right Box</p>
</div>
</div>
</div>
</div>
Should Be(Source):
<div class="main_top_box">
<div class="main_mid_box">
<div class="main_bottom_box">
<h3>Services</h3>
<ul>
<li>Family Law</li>
<li>Collaborative Law</li>
<li>Real Estate</li>
<li>Wills</li>
<li>Estate Planning</li>
<li>Estates</li>
</ul>
</div>
</div>
</div>
<div class="main_top_box">
<div class="main_mid_box">
<div class="main_bottom_box">
<h3>Test</h3>
<p>Testing the Right Box</p>
</div>
</div>
</div>
You can do this by these to methods
Either Change the order of display the module in the same position in the module manager.
Create separate module position for both the modules and assign them accordingly.

Resources