Change div text on resize of box (jQuery) - php

I'm currently using jQuery to animate the resizing of a banner.
There's a div button that does this upon clicking.
What I'm trying to do is get the button to change its text from "hide banner" to "show banner" depending
<div id="banner_animate" class="banner">
<div id="minimize" class="small_button">hide banner</div>
<script>
$("#minimize").click(function() {
var new_height = 200;
if ($("#banner_animate").height() == 200) new_height = 40;
$("#banner_animate").animate({
height: new_height + "px"
}, 500 );
});
$(function() {
$( document ).tooltip();
});
</script>
I'm pretty new to jQuery, so any help would be greatly appreciated!

in your $("#minimize").click you can use $(this).text():
$("#minimize").click(function() {
if ($(this).text() == 'hide banner') {
$("#banner_animate").animate({height: "40px"}, 500);
$(this).text('show banner');
} else {
$("#banner_animate").animate({height: "200px"}, 500);
$(this).text('hide banner');
}
});
http://api.jquery.com/text/

Try this:
$("#minimize").click(function () {
var new_height = 200;
if ($("#banner_animate").height() == 200) new_height = 40;
$("#banner_animate").animate({
height: new_height + "px"
}, 500);
$(this).text(function (_, oldText) {
return oldText === 'Hide banner' ? 'Show banner' : 'Hide banner';
});
});
Also, change the HTML to show banner at first like:
<div id="minimize" class="small_button">Show banner</div>
FIDDLE DEMO

$("#minimize").click(function() {
if($(this).html()=="hide banner"){
$(this).html("show");
}
else {
$(this).html("hide banner");
}
var new_height = 200;
if ($("#banner_animate").height() == 200) new_height = 40;
$("#banner_animate").animate({
height: new_height + "px"
}, 500 );
});
$(function() {
$( document ).tooltip();
});
Fiddle Demo

Related

WordPress Theme File Editor will not be modified

I run a store in WordPress.
You are about to add a unique link to the tab on the page.
WordPress can assign a #tag (custom ID) to each tab, but it wants to provide a link that is not this function.
wordpress : "https://www.mypage/#tab-name"
Custom jquery: "myslog://www.mypage/?tab='tab-name filename"
We successfully wrote and applied the code.
The code is functioning normally, and the modified code is not applied.
However, I can't edit it.
When you click File Update, the phrase "File edited successfully." appears.
Why can't I edit it?
functions.php
wp_enqueue_script( "mypage-theme-js", get_stylesheet_directory_uri() . "/js/theme-script.js", array(),'1.2');
js/theme-script.js
jQuery(document).ready(function() {
if (jQuery('.terms-conditions-content').length > 0) {
for (var i = 1; i <= jQuery('.terms-conditions-content .eael-tab-inline-icon li').length; i++) {
var select_val = jQuery('.terms-conditions-content .eael-tab-inline-icon li:nth-child(' + i + ')');
var text = jQuery(select_val).find('.eael-tab-title').text()
var result = text.replace(/\s+/g, '')
select_val.attr('id', result.toLowerCase());
}
var tabVal = '';
var sPageURL = window.location.search.substring(1);
var sURLVariables = sPageURL.split('&');
for (var i = 0; i < sURLVariables.length; i++) {
var sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] == 'tab') {
var tabVal = sParameterName[1];
}
}
console.log(tabVal);
if(tabVal == 'warranty'){
setTimeout(function() {
jQuery("#warranty").click();
}, 1000);
}
if(tabVal == 'cloud-privacy-policy'){
console.log('Test');
setTimeout(function() {
jQuery("#cloudprivacypolicy").click();
}, 1000);
}
if(tabVal == 'cloud-terms-of-service'){
console.log('Test');
setTimeout(function() {
jQuery("#cloudtermsofservice").click();
}, 1000);
}
if(tabVal == 'terms-of-location-based-service'){
console.log('Test');
setTimeout(function() {
jQuery("#termsoflocation-basedservice").click();
}, 1000);
}
if(tabVal == 'information-we-collect-and-why'){
console.log('hi');
setTimeout(function() {
jQuery("#informationwecollectandwhy").click();
}, 1000);
}
}
enter image description here

How to get php echo data in jquery

How to get php echo data in jquery. i want dataDAY1 in jquery. i am using on progress bar. i use php and sql. i nedd total var total_goals and var goals_completed data from database
<div id="dataDAY1"><?php echo $row["ipoSize"]; ?></div>
<script>
$(document).ready(function(){
var total_goals = document.getElementById("dataDAY1")
// var total_goals = '$json_array';
var goals_completed = 3000;
var bar = new ProgressBar.Circle('#container', {
color: '#00b819',
strokeWidth: 4,
trailWidth: 4,
easing: 'easeInOut',
duration: 1400,
text: {
autoStyleContainer: false
},
from: { color: '#cecece', width: 4 },
to: { color: '#00b819', width: 4 },
step: function(state, circle) {
circle.path.setAttribute('stroke', state.color);
circle.path.setAttribute('stroke-width', state.width);
var value = Math.round(circle.value() * 100);
if (value === 0) {
circle.setText('');
} else {
circle.setText(value);
}
}
});
bar.text.style.fontFamily = '"Raleway", Helvetica, sans-serif';
bar.text.style.fontSize = '2rem';
bar.animate(goals_completed/total_goals); // Number from 0.0 to 1.0
});
</script>
try this...
for JQuery: var total_goals = $("dataDAY1").html();
for Javascript: var total_goals = document.getElementById("dataDAY1").innerHTML;
snippet:
var total_goals = $('#dataDAY1').html();
console.log(total_goals);
var total_goals_js = document.getElementById('dataDAY2').innerHTML;
console.log(total_goals_js);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="dataDAY1">Your Data From Php Variable</div>
<div id="dataDAY2">Your Data From Php Variable 2</div>
Try this:-
var total_goals= <?php echo json_encode($json_array); ?>;
console.log(total_goals);
You can use php in javascript. See below code
<script>
var total_goals = "<?php echo $row['ipoSize']; ?>";
</script>

Retrieving a value from a database and display in tooltip

I have created a tooltip using javascript and have an html page using that tooltip.
Here is my tooltip:
$(document).ready(function () {
//Tooltips
$(".tip_trigger").hover(function (e) {
tip = $(this).find('.tip');
var tipText = $(e.target).attr('ti');
tip.html(tipText);
tip.show(); //Show tooltip
}, function () {
tip.hide(); //Hide tooltip
}).mousemove(function (e) {
var mousex = e.pageX + 20; //Get X coodrinates
var mousey = e.pageY + 20; //Get Y coordinates
var tipWidth = tip.width(); //Find width of tooltip
var tipHeight = tip.height(); //Find height of tooltip
//Distance of element from the right edge of viewport
var tipVisX = $(window).width() - (mousex + tipWidth);
//Distance of element from the bottom of viewport
var tipVisY = $(window).height() - (mousey + tipHeight);
if (tipVisX < 20) { //If tooltip exceeds the X coordinate of viewport
mousex = e.pageX - tipWidth - 20;
} if (tipVisY < 20) { //If tooltip exceeds the Y coordinate of viewport
mousey = e.pageY - tipHeight - 20;
}
tip.css({ top: mousey, left: mousex });
});
});
Here is HTML:
<div class="container">
<h1><span>Simple Example</span></h1>
<map name="Koala" class="tip_trigger">
<area ti="This is the left eye" shape="rect" coords="373,365,404,402" href="#" />
<area ti="Right Eye" shape="rect" coords="641,405,681,448" href="#" />
<div class="tip"></div>
I want the database value to display where "ti" is... ex. ti="database value"
How can this be done? I will be using MySQL along with php. All help I will be very grateful for.
Create a help table in mysql:
CREATE TABLE `help` (
`helpID` varchar(100) NOT NULL,
`helpText` text NOT NULL,
UNIQUE KEY `helpID` (`helpID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
For a generic tooltip, on the page where you want the help tip, put this html:
<span id="productSKUHelp" class="helpTip questionMark"></span>
Since you want the tooltip to appear when your cursor is in a certain spot, you should be able to use your mousemove function and call showTip.
Add the following JQuery:
function showTip(thisTip){
var postdata = {
helpTip: thisTip.attr('id')
};
$.ajax({
type : "post",
url : "/getHelpRPC.php",
dataType: "html",
data : postdata,
success : function(data){
if(data.length > 0){
var origContent = thisTip.html();
thisTip.removeClass("questionMark").addClass('helpTipBox');
thisTip.html(data);
}else{
$('#helpTipBox').html("error");
}
},
error : function(xhr, textStatus, error){
console.log(xhr.statusText);
console.log(textStatus);
console.log(error);
}
});
}
$(document).on('mouseenter', '.helpTip', function(){
var thisTip = $(this);
helpTipTimer = setTimeout(function(){
showTip(thisTip);
},
1000);
})
$(document).on('click', '.helpTip', function(){
showTip($(this));
})
$(document).on('mouseleave', '.helpTip', function(){
clearTimeout(helpTipTimer);
$(this).html('').removeClass('helpTipBox').addClass('questionMark');
});
Add the following CSS:
.helpTip{
padding-left:3px;
z-index:900;
}
.questionMark:after{
color:maroon;
cursor:pointer;
content:"?";
top:2px;
position:relative;
padding:0 3px;
}
.helpTipBox{
padding:5px;
background-color:#97abcc;
position:absolute;
curson:text;
}
Create the getHelpRPC.php RPC:
<?php
$mysqli = new mysqli(DB_HOST, DB_USER, DB_PASS, DB);
if($mysqli->connect_errno){
printf("Connect failed: %s %s %s\n", $mysqli->connect_error, __FILE__, __LINE__);
exit();
}
$helpID = $_POST['helpTip'];
if($helpID != ""){
$querystr = "SELECT helpText FROM help WHERE helpID ='" . $mysqli->real_escape_string($helpID) . "'";
$res = $mysqli->query($querystr);
$rowCount = $res->num_rows;
if($rowCount > 0){
$row = $res->fetch_object();
echo $row->helpText;
} else {
echo "error selecting help.";
}
}
Now all you need to do is create a unique id in the span and add the corresponding record to the table.

How To Save More fusion Charts On Server With Single Button

I am trying to save graphs on server side. i was succeeded up to save one graph. but i am unable to save more than one graph.
here i mentioned 2 graphs but nly one graph is going to save on server.
how it can be ?
my code is
<script type="text/javascript">
var totalCharts = 2;
function exportCharts(exportType)
{
for( var i = 0; i < totalCharts; i++ ) {
var num = i+1;
var id = "chart"+num+"Id";
exportchart(exportType,id);
}
}
function exportchart(exportType,id)
{
var chart = FusionCharts(id);
// Now, we proceed with exporting only if chart has finished rendering.
if (chart.hasRendered() != true)
{
alert("Please wait for the chart to finish rendering, before you can invoke exporting");
return;
}
// call exporting function
chart.exportChart( {exportFormat: exportType} );
}
</script>
<p align="center">
<input type="button" class="button" value="Export as PNG" onclick="exportCharts('PNG')" id="exportButtonPNG" />
</p>
<div >
<div id="average" style="text-align:center">Loading Chart... </div>
<div id="overall" style="text-align:center">Loading Chart... </div>
</div>
<script type="text/javascript" >
// Render the chart (See documentation for explanation of the codes below)
//echo renderChart("FusionCharts/MSColumn3D.swf", "", $strXML3, "average", 1100, 350);
var chart2 = new FusionCharts("FusionCharts/MSColumn3D.swf", "chart1Id", "600", "400", "0", "1");
chart2.setXMLUrl("average.xml");
chart2.render("average");
var chart1 = new FusionCharts("FusionCharts/MSColumn3D.swf", "chart2Id", "600", "400", "0", "1");
chart1.setXMLUrl("overall.xml");
chart1.render("overall");
</script>
<!-- Google Analytics Tracker Code Starts -->
<script type="text/javascript">
// analytics
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost
+ "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
if (typeof(_gat) == "object") {
var pageTracker = _gat._getTracker("UA-215295-3"); pageTracker._initData(); pageTracker._trackPageview();
}
</script>
How i can solve this?
You may need to chain the call to exportChart function of each chart you have.
var totalCharts = 2;
(function () {
var totalExported = 0,
exportType;
window.FC_Exported = function() {
exportchart();
};
window.exportchart = function(exportFormat) {
exportType = exportType || exportFormat || 'jpg';
totalExported++ ;
var chart = FusionCharts("chart" + totalExported + "Id");
if (totalExported > totalCharts) {
return;
}
if (chart.hasRendered() != true) {
alert("Please wait for the chart to finish rendering, before you can invoke exporting");
}
// call exporting function
chart.exportChart( {exportFormat: exportType} );
};
}());

Javascript - How to add a pause button in carousel?

I have found this script in Magento which is rotating images from a certain directory. This is working fine. But I need to add a "pause" button after the "1-6". I am not an expert on javascript so not sure how to do this. Can someone please help me with this?
The code:
<?php
$speed = 5000;//miliseconds
?>
<script type="text/javascript">
var timeoutID;
homeTileCount = 1;
$$('.home-tile-container img').each(function(e){
$(e).writeAttribute('id','home-tile-' + homeTileCount);
$(e).addClassName('home-tile');
homeTileCount++;
});
homeTileCount--;
var homeTileRemote = $$('.home-tile-remote')[0];
for (i=homeTileCount;i>=1;i--)
homeTileRemote.insert('<div id="home-tile-remote-'+i+'" class="overflow">'+i+'</div>');
function switchTile(n)
{
//console.log(n);
clearTimeout(timeoutID);
$$('.home-tile-container img').each(function(e){
e.removeClassName('home-tile-active');
});
$$('.home-tile-remote > div').each(function(e){
e.removeClassName('home-tile-remote-active');
});
$('home-tile-remote-'+n).addClassName('home-tile-remote-active');
$('home-tile-'+n).addClassName('home-tile-active');
next = n+1;
if (next > homeTileCount)
next = 1;
timeoutID = setTimeout('switchTile('+next+')', <?=$speed?>);
}
switchTile(1);
setTimeout('switchTile(2)', <?=$speed?>);
</script>
And this is how the carousel looks:
Maybe this:
<?php
$speed = 5000;//miliseconds
?>
<script type="text/javascript">
var paused=false;
var timeoutID;
homeTileCount = 1;
$$('.home-tile-container img').each(function(e){
$(e).writeAttribute('id','home-tile-' + homeTileCount);
$(e).addClassName('home-tile');
homeTileCount++;
});
homeTileCount--;
var homeTileRemote = $$('.home-tile-remote')[0];
for (i=homeTileCount;i>=1;i--)
homeTileRemote.insert('<div id="home-tile-remote-'+i+'" class="overflow">'+i+'</div>');
function switchTile(n)
{
if (!paused) {
//console.log(n);
clearTimeout(timeoutID);
$$('.home-tile-container img').each(function(e){
e.removeClassName('home-tile-active');
});
$$('.home-tile-remote > div').each(function(e){
e.removeClassName('home-tile-remote-active');
});
$('home-tile-remote-'+n).addClassName('home-tile-remote-active');
$('home-tile-'+n).addClassName('home-tile-active');
next = n+1;
if (next > homeTileCount)
next = 1;
timeoutID = setTimeout('switchTile('+next+')', <?=$speed?>);
}
}
switchTile(1);
setTimeout('switchTile(2)', <?=$speed?>);
</script>
<button type="button" onclick="paused=true;">Pause</button>

Categories