here is the link which i want to use for template design http://interactjs.io/
i can drag the module height from one container into second container and can drag position by using interact.js functionality by using jquery and php... record should be update ib database on drop... see screen below for more detail
see screenshot for more help
need solution with jquery and PHP...interact.js is compulsory :)
HTML:
<div class="containerdiv" style="float:left">
<div id="drag-450-180" class="draggable js-drag">180</div>
<div id="drag-900-180" class="draggable js-drag">180</div>
<div id="drag-450-240" class="draggable js-drag">240 </div>
<div id="drag-900-240" class="draggable js-drag">240 </div>
<div id="drag-450-360" class="draggable js-drag">360 </div>
<div id="drag-900-360" class="draggable js-drag">360 </div>
<div id="drag-450-480" class="draggable js-drag">360 </div>
<div id="drag-900-480" class="draggable js-drag">360 </div>
</div>
<div class="dropzone-wrapper">
<div id="drop1" class="dropzone js-drop">Dropzone</div>
</div>
interact('.js-drag')
.draggable({
restrict: {
restriction: "parent",
endOnly: true,
elementRect: { top: 0, left: 0, bottom: 1, right: 1 }
},
overlap: 'pointer',
inertia: true,
checker: function (dragEvent, // related dragmove or dragend
event, // Touch, Pointer or Mouse Event
dropped, // bool default checker result
dropzone, // dropzone Interactable
dropElement, // dropzone elemnt
draggable, // draggable Interactable
draggableElement) {// draggable element
// only allow drops into empty dropzone elements
return dropped && !dropElement.hasChildNodes();
}
})
.on('dragstart', function (event) {
event.interaction.x = parseInt(event.target.getAttribute('data-x'), 10) || 0;
event.interaction.y = parseInt(event.target.getAttribute('data-y'), 10) || 0;
})
.on('dragmove', function (event) {
event.interaction.x += event.dx;
event.interaction.y += event.dy;
if (transformProp) {
event.target.style[transformProp] =
'translate(' + event.interaction.x + 'px, ' + event.interaction.y + 'px)';
}
else {
event.target.style.left = event.interaction.x + 'px';
event.target.style.top = event.interaction.y + 'px';
}
})
.on('dragend', function (event) {
// event.target.setAttribute('data-x', event.interaction.x);
// event.target.setAttribute('data-y', event.interaction.y);
event.target.setAttribute('data-x', 0);
event.target.setAttribute('data-y', 0);
event.target.removeAttribute('style');
});
interact('.js-drag2')
.draggable({
restrict: {
restriction: "parent",
endOnly: true,
elementRect: { top: 0, left: 0, bottom: 1, right: 1 }
} ,
inertia: true,
overlap: 0.01,
checker: function (dragEvent, // related dragmove or dragend
event, // Touch, Pointer or Mouse Event
dropped, // bool default checker result
dropzone, // dropzone Interactable
dropElement, // dropzone elemnt
draggable, // draggable Interactable
draggableElement) {// draggable element
// only allow drops into empty dropzone elements
return dropped && !dropElement.hasChildNodes();
}
})
.on('dragstart', function (event) {
event.interaction.x = parseInt(event.target.getAttribute('data-x'), 10) || 0;
event.interaction.y = parseInt(event.target.getAttribute('data-y'), 10) || 0;
})
.on('dragmove', function (event) {
event.interaction.x += event.dx;
event.interaction.y += event.dy;
if (transformProp) {
event.target.style[transformProp] =
'translate(' + event.interaction.x + 'px, ' + event.interaction.y + 'px)';
}
else {
event.target.style.left = event.interaction.x + 'px';
event.target.style.top = event.interaction.y + 'px';
}
})
.on('dragend', function (event) {
event.target.setAttribute('data-x', event.interaction.x);
event.target.setAttribute('data-y', event.interaction.y);
});
Related
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Yelp Search API Example</title>
<style type="text/css">
html, body {width: 100%; height: 100%; font-family: arial;}
body {margin:0;padding 0;overflow: hidden;}
#mapContainer {padding-top: 50px;}
#map, #mapContainer {width:100%; height: 100%;}
#top {position:absolute; top:0; left:0; width: 100%; height: 50px; line-height: 50px;}
#spinner { visibility: hidden; margin-left:3px;}
#poweredby, #searchbox {line-height: 50px;}
#searchbox {text-align: center;}
#poweredby { float: right; margin-right: 3px;}
#poweredby img { vertical-align: baseline;}
.marker {font-size: 11px;}
.marker .businessimage { float: left;}
.marker .ratingsimage {vertical-align:middle; margin-top:0px;}
.marker .businessinfo { margin-left: 110px;}
</style>
<script src="http://maps.google.com/maps?file=api&v=2&key=[AIzaSyByEg0pBD4dGr3gZCk863XZZ0ZBkqhDhR4]"
type="text/javascript"></script>
<script type="text/javascript">
var YWSID = "aSVpoAZwxvtcwsscdWjBBw"; // common required parameter (api key)
var map = null;
var icon = null;
/*
* Creates the map object and calls setCenterAndBounds
* to instantiate it.
*/
function load() {
map = new GMap2(document.getElementById("map"));
GEvent.addListener(map, "load", function() {updateMap();});
map.setCenter(new GLatLng(40.296448,-79.478141),13);
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
map.setMapType(G_HYBRID_MAP);
if (window.attachEvent) window.attachEvent("onresize", function() { map.checkResize()} );
else if (window.addEventListener) window.addEventListener("resize", function() { map.checkResize()}, false);
// setup our marker icon
icon = new GIcon();
icon.image = "images/marker_star.png";
icon.shadow = "images/marker_shadow.png";
icon.iconSize = new GSize(20, 29);
icon.shadowSize = new GSize(38, 29);
icon.iconAnchor = new GPoint(15, 29);
icon.infoWindowAnchor = new GPoint(15, 3);
}
/*
* Construct the URL to call for the API request
*/
function constructYelpURL() {
var mapBounds = map.getBounds();
var URL = "http://api.yelp.com/" +
"business_review_search?"+
"callback=" + "handleResults" +
"&term=" + document.getElementById("term").value +
"&num_biz_requested=10" +
"&tl_lat=" + mapBounds.getSouthWest().lat() +
"&tl_long=" + mapBounds.getSouthWest().lng() +
"&br_lat=" + mapBounds.getNorthEast().lat() +
"&br_long=" + mapBounds.getNorthEast().lng() +
"&ywsid=" + YWSID;
return encodeURI(URL);
}
/*
* Called on the form submission: updates the map by
* placing markers on it at the appropriate places
*/
function updateMap() {
// turn on spinner animation
document.getElementById("spinner").style.visibility = 'visible';
var yelpRequestURL = constructYelpURL();
/* clear existing markers */
map.clearOverlays();
/* do the api request */
var script = document.createElement('script');
script.src = yelpRequestURL;
script.type = 'text/javascript';
var head = document.getElementsByTagName('head').item(0);
head.appendChild(script);
return false;
}
/*
* If a sucessful API response is received, place
* markers on the map. If not, display an error.
*/
function handleResults(data) {
// turn off spinner animation
document.getElementById("spinner").style.visibility = 'hidden';
if(data.message.text == "OK") {
if (data.businesses.length == 0) {
alert("Error: No businesses were found near that location");
return;
}
for(var i=0; i<data.businesses.length; i++) {
biz = data.businesses[i];
createMarker(biz, new GLatLng(biz.latitude, biz.longitude), i);
}
}
else {
alert("Error: " + data.message.text);
}
}
/*
* Formats and returns the Info Window HTML
* (displayed in a balloon when a marker is clicked)
*/
function generateInfoWindowHtml(biz) {
var text = '<div class="marker">';
// image and rating
text += '<img class="businessimage" src="'+biz.photo_url+'"/>';
// div start
text += '<div class="businessinfo">';
// name/url
text += ''+biz.name+'<br/>';
// stars
text += '<img class="ratingsimage" src="'+biz.rating_img_url_small+'"/> based on ';
// reviews
text += biz.review_count + ' reviews<br/><br />';
// categories
text += formatCategories(biz.categories);
// neighborhoods
if(biz.neighborhoods.length)
text += formatNeighborhoods(biz.neighborhoods);
// address
text += biz.address1 + '<br/>';
// address2
if(biz.address2.length)
text += biz.address2+ '<br/>';
// city, state and zip
text += biz.city + ', ' + biz.state + ' ' + biz.zip + '<br/>';
// phone number
if(biz.phone.length)
text += formatPhoneNumber(biz.phone);
// Read the reviews
text += '<br/>Read the reviews ยป<br/>';
// div end
text += '</div></div>'
return text;
}
/*
* Formats the categories HTML
*/
function formatCategories(cats) {
var s = 'Categories: ';
for(var i=0; i<cats.length; i++) {
s+= cats[i].name;
if(i != cats.length-1) s += ', ';
}
s += '<br/>';
return s;
}
/*
* Formats the neighborhoods HTML
*/
function formatNeighborhoods(neighborhoods) {
s = 'Neighborhoods: ';
for(var i=0; i<neighborhoods.length; i++) {
s += '' + neighborhoods[i].name + '';
if (i != neighborhoods.length-1) s += ', ';
}
s += '<br/>';
return s;
}
/*
* Formats the phone number HTML
*/
function formatPhoneNumber(num) {
if(num.length != 10) return '';
return '(' + num.slice(0,3) + ') ' + num.slice(3,6) + '-' + num.slice(6,10) + '<br/>';
}
/*
* Creates a marker for the given business and point
*/
function createMarker(biz, point, markerNum) {
var infoWindowHtml = generateInfoWindowHtml(biz)
var marker = new GMarker(point, icon);
map.addOverlay(marker);
GEvent.addListener(marker, "click", function() {
marker.openInfoWindowHtml(infoWindowHtml, {maxWidth:400});
});
// automatically open first marker
if (markerNum == 0)
marker.openInfoWindowHtml(infoWindowHtml, {maxWidth:400});
}
//]]>
</script>
</head>
<body onload="load()">
<div id="top">
<div id="poweredby">Powered by <img src="http://static.px.yelp.com/i/map/miniMapLogo.png" border="0" /></div>
<div id="searchbox">
<form>
Search for <input type="text" id="term" name="term" value="flannery-cars-greensburg"/> <input type="button" value="Search" onclick="return updateMap();"/>
<img id="spinner" src="images/spinner.gif" />
<span class="error" id="errorMessage" />
</form>
</div>
</div>
<div id="mapContainer"><div id="map"></div></div>
</body>
</html>
Website
http://www.724-streamline-marketing.com/testing2.html
I am trying to gather metrics for reviews, rating, map location from the yelp api, I am unsure why it will not stay.
Any help would be grateful or even point me in the right direction on using a 3rd party app to create yelp data
Your problem is simple,
<script src="http://maps.google.com/maps?file=api&v=2&key=[AIzaSyByEg0pBD4dGr3gZCk863XZZ0ZBkqhDhR4]"
Get rid of the brackets [] surrounding the key.
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
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.
I am using a jQuery plugin called Stepy, which is based of the FormToWizard plugin, to allow users to complete a 10-step form.
Using the next/back attributes, I've added a function to post data between steps so the user can save their work and come back at a later day if they'd like.
One of my steps allows the user to add items to a form within an iframe (to post data to a separate table). I'd like it to function so that when the user moves between steps, the items in the iframe post to their separate table as well. Is there a way to submit the form within the iframe between steps (i.e. submit iframe sub-form when main form submits)?
I am using PHP and MySQL.
Any help you could provide would be amazing!
Javascript:
$(function() {
$('#custom').stepy({
backLabel: 'Back',
block: true,
errorImage: true,
nextLabel: 'Next',
titleClick: true,
validate: false,
legend: false,
back: function(index) {
$.post('../../process.php')
}
next: function(index) {
$.post('../../process.php')
}
});
});
HTML:
<html>
<body>
<form id="custom" name="custom">
<fieldset title="Thread 1">
<legend>description one</legend>
<label>Question A:</label>
<input type="text" id="question_a" name="question_a" class="required">
<label>Question B:</label>
<input type="text" id="question_b" name="question_b">
</fieldset>
<fieldset title="Thread 2">
<legend>description two</legend>
<iframe src="../../list_form.php" width="100%" height="300"></iframe>
</fieldset>
<fieldset title="Thread 3">
<legend>description three</legend>
<label>Question C:</label>
<input type="text" id="question_c" name="question_c" class="required">
</fieldset>
<input type="submit" class="finish" value="Finish!">
</form>
</body>
</html>
iframe
<html>
<body>
<form id="sub_form" name="sub_form">
<label>Question 1:</label>
<input type="text" id="question_1" name="question_1">
<label>Question 2:</label>
<input type="text" id="question_2" name="question_2">
</form>
</body>
</html>
stepy.js
;(function($) {
var methods = {
init: function(options) {
return this.each(function() {
var opt = $.extend({}, $.fn.stepy.defaults, options),
$this = $(this).data('options', opt),
id = $this.attr('id');
if (id === undefined) {
id = 'stepy-' + $this.index();
$this.attr('id', id);
}
var $titlesWrapper = $('<ul/>', { id: id + '-titles', 'class': 'stepy-titles' });
if (opt.titleTarget) {
$(opt.titleTarget).html($titlesWrapper);
} else {
$titlesWrapper.insertBefore($this);
}
if (opt.validate) {
$this.append('<div class="stepy-error"/>');
}
var $steps = $this.children('fieldset'),
$step = undefined,
$legend = undefined,
description = '',
title = '';
$steps.each(function(index) {
$step = $(this);
$step
.addClass('step')
.attr('id', id + '-step-' + index)
.append('<p id="' + id + '-buttons-' + index + '" class="' + id + '-buttons"/>');
$legend = $step.children('legend');
if (!opt.legend) {
$legend.hide();
}
description = '';
if (opt.description) {
if ($legend.length) {
description = '<span>' + $legend.html() + '</span>';
} else {
$.error(id + ': the legend element of the step ' + (index + 1) + ' is required to set the description!');
}
}
title = $step.attr('title');
title = (title != '') ? '<div>' + title + '</div>': '--';
$titlesWrapper.append('<li id="' + id + '-title-' + index + '">' + title + description + '</li>');
if (index == 0) {
if ($steps.length > 1) {
methods.createNextButton.call($this, index);
}
} else {
methods.createBackButton.call($this, index);
$step.hide();
if (index < $steps.length - 1) {
methods.createNextButton.call($this, index);
}
}
});
var $titles = $titlesWrapper.children();
$titles.first().addClass('current-step');
var $finish = $this.children('.finish');
if (opt.finishButton) {
if ($finish.length) {
var isForm = $this.is('form'),
onSubmit = undefined;
if (opt.finish && isForm) {
onSubmit = $this.attr('onsubmit');
$this.attr('onsubmit', 'return false;');
}
$finish.click(function(evt) {
if (opt.finish && !methods.execute.call($this, opt.finish, $steps.length - 1)) {
evt.preventDefault();
} else {
if (isForm) {
if (onSubmit) {
$this.attr('onsubmit', onSubmit);
} else {
$this.removeAttr('onsubmit');
}
var isSubmit = $finish.attr('type') == 'submit';
if (!isSubmit && (!opt.validate || methods.validate.call($this, $steps.length - 1))) {
$this.submit();
}
}
}
});
$finish.appendTo($this.find('p:last'));
} else {
$.error(id + ': element with class name "finish" missing!');
}
}
if (opt.titleClick) {
$titles.click(function() {
var array = $titles.filter('.current-step').attr('id').split('-'), // TODO: try keep the number in an attribute.
current = parseInt(array[array.length - 1], 10),
clicked = $(this).index();
if (clicked > current) {
if (opt.next && !methods.execute.call($this, opt.next, clicked)) {
return false;
}
} else if (clicked < current) {
if (opt.back && !methods.execute.call($this, opt.back, clicked)) {
return false;
}
}
if (clicked != current) {
methods.step.call($this, (clicked) + 1);
}
});
} else {
$titles.css('cursor', 'default');
}
$steps.delegate('input[type="text"], input[type="password"]', 'keypress', function(evt) {
var key = (evt.keyCode ? evt.keyCode : evt.which);
if (key == 13) {
evt.preventDefault();
var $buttons = $(this).parent().children('.' + id + '-buttons');
if ($buttons.length) {
var $next = $buttons.children('.button right-aligned');
if ($next.length) {
$next.click();
} else {
var $finish = $buttons.children('.finish');
if ($finish.length) {
$finish.click();
}
}
}
}
});
$steps.first().find(':input:visible:enabled').first().select().focus();
});
}, createBackButton: function(index) {
var $this = this,
id = this.attr('id'),
opt = this.data('options');
$('<a/>', { id: id + '-back-' + index, href: 'javascript:void(0);', 'class': 'button left-aligned', html: opt.backLabel }).click(function() {
if (!opt.back || methods.execute.call($this, opt.back, index - 1)) {
methods.step.call($this, (index - 1) + 1);
}
}).appendTo($('#' + id + '-buttons-' + index));
}, createNextButton: function(index) {
var $this = this,
id = this.attr('id'),
opt = this.data('options');
$('<a/>', { id: id + '-next-' + index, href: 'javascript:void(0);', 'class': 'button right-aligned', html: opt.nextLabel }).click(function() {
if (!opt.next || methods.execute.call($this, opt.next, index + 1)) {
methods.step.call($this, (index + 1) + 1);
}
}).appendTo($('#' + id + '-buttons-' + index));
}, execute: function(callback, index) {
var isValid = callback.call(this, index + 1);
return isValid || isValid === undefined;
}, step: function(index) {
index--;
var $steps = this.children('fieldset');
if (index > $steps.length - 1) {
index = $steps.length - 1;
}
var opt = this.data('options');
max = index;
if (opt.validate) {
var isValid = true;
for (var i = 0; i < index; i++) {
isValid &= methods.validate.call(this, i);
if (opt.block && !isValid) {
max = i;
break;
}
}
}
$steps.hide().eq(max).show();
var $titles = $('#' + this.attr('id') + '-titles').children();
$titles.removeClass('current-step').eq(max).addClass('current-step');
if (this.is('form')) {
var $fields = undefined;
if (max == index) {
$fields = $steps.eq(max).find(':input:enabled:visible');
} else {
$fields = $steps.eq(max).find('.error').select().focus();
}
$fields.first().select().focus();
}
if (opt.select) {
opt.select.call(this, max + 1);
}
return this;
}, validate: function(index) {
if (!this.is('form')) {
return true;
}
var $step = this.children('fieldset').eq(index),
isValid = true,
$title = $('#' + this.attr('id') + '-titles').children().eq(index),
opt = this.data('options'),
$this = this;
$($step.find(':input:enabled').get().reverse()).each(function() {
var fieldIsValid = $this.validate().element($(this));
if (fieldIsValid === undefined) {
fieldIsValid = true;
}
isValid &= fieldIsValid;
if (isValid) {
if (opt.errorImage) {
$title.removeClass('error-image');
}
} else {
if (opt.errorImage) {
$title.addClass('error-image');
}
$this.validate().focusInvalid();
}
});
return isValid;
}
};
$.fn.stepy = function(method) {
if (methods[method]) {
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
} else if (typeof method === 'object' || !method) {
return methods.init.apply(this, arguments);
} else {
$.error('Method ' + method + ' does not exist!');
}
};
$.fn.stepy.defaults = {
back: undefined,
backLabel: '< Back',
block: false,
description: true,
errorImage: false,
finish: undefined,
finishButton: true,
legend: true,
next: undefined,
nextLabel: 'Next >',
titleClick: false,
titleTarget: undefined,
validate: false,
select: undefined
};
})(jQuery);
If you want to append Text\HTML or any other data to your iframe (which calling to a page on the same domain!) you may use:
jQuery("#iframe_id").contents().find('body').append('<div>Hello World</div>');
Full Example:
Full Example
If your iframe is on another domain you will have to use window.postMessage, which you may read about on Mozilla's docs:
Mozilla's docs
OR to take a look about my blog post about this subject.
Hope I helped,
I'm trying to assign three different colours to three different articles on a single page using a:hover in Wordpress.
This is the site http://paragrams.wpshower.com/
At present all the articles turn pale yellow on a:hover. I'm trying to create different colours for each article (for example, first article to be yellow, the second article red, third blue and so on).
Below is the php & CSS for the a:hover at present. I assume I need to wrap each thumb id in a different div and specify the colour in the CSS?
PHP:
<ul class="mcol">
<?php if(have_posts()) : ?><?php while(have_posts()) : the_post(); ?>
<li class="article">
<?php
if ( has_post_thumbnail() ) { ?>
<?php
$imgsrcparam = array(
'alt' => trim(strip_tags( $post- >post_excerpt )),
'title' => trim(strip_tags( $post- >post_title )),
);
$thumbID = get_the_post_thumbnail( $post->ID, 'background', $imgsrcparam ); ?>
<div><?php echo "$thumbID"; ?></div>
<?php } ?>
<h2><?php the_title(); ?></h2>
and CSS:
.li_container {
background-attachment: scroll;
background-image: url(images/main-bg.gif);
background-repeat: repeat-y;
background-position: left top;
}
.li_container .article:hover {
background-color:#57bfeb;
}
This is the js:
# * Splits a <ul>/<ol>-list into equal-sized columns.
# *
# * Requirements:
# * <ul>
# * <li>"ul" or "ol" element must be styled with margin</li>
# * </ul>
# *
# * #see http://www.codeasily.com/jquery/multi-column-list-with-jquery
# */
jQuery.fn.makeacolumnlists = function(settings){
settings = jQuery.extend({
cols: 3, // set number of columns
colWidth: 0, // set width for each column or leave 0 for auto width
equalHeight: 'li', // can be false, 'ul', 'ol', 'li'
startN: 1 // first number on your ordered list
}, settings);
if(jQuery('> li', this)) {
this.each(function(y) {
var y=jQuery('.li_container').size(),
height = 0,
maxHeight = 0,
t = jQuery(this),
classN = t.attr('class'),
listsize = jQuery('> li', this).size(),
percol = Math.ceil(listsize/settings.cols),
contW = t.width(),
bl = ( isNaN(parseInt(t.css('borderLeftWidth'),10)) ? 0 : parseInt(t.css('borderLeftWidth'),10) ),
br = ( isNaN(parseInt(t.css('borderRightWidth'),10)) ? 0 : parseInt(t.css('borderRightWidth'),10) ),
pl = parseInt(t.css('paddingLeft'),10),
pr = parseInt(t.css('paddingRight'),10),
ml = parseInt(t.css('marginLeft'),10),
mr = parseInt(t.css('marginRight'),10),
col_Width = Math.floor((contW - (settings.cols-1)*(bl+br+pl+pr+ml+mr))/settings.cols);
if (settings.colWidth) {
col_Width = settings.colWidth;
}
var colnum=1,
percol2=percol;
jQuery(this).addClass('li_cont1').wrap('<div id="li_container' + (++y) + '" class="li_container"></div>');
for (var i=0; i<=listsize; i++) {
if (colnum > settings.cols) colnum = 1;
var eq = jQuery('> li:eq('+i+')',this);
eq.addClass('li_col'+colnum);
colnum++;
//if(i>=percol2) { percol2+=percol; colnum++; }
//var eq = jQuery('> li:eq('+i+')',this);
//eq.addClass('li_col'+ colnum);
//if(jQuery(this).is('ol')){eq.attr('value', ''+(i+settings.startN))+'';}
}
jQuery(this).css({cssFloat:'left', width:''+col_Width+'px'});
for (colnum=2; colnum<=settings.cols; colnum++) {
if(jQuery(this).is('ol')) {
jQuery('li.li_col'+ colnum, this).appendTo('#li_container' + y).wrapAll('<ol class="li_cont'+colnum +' ' + classN + '" style="float:left; width: '+col_Width+'px;"></ol>');
} else {
jQuery('li.li_col'+ colnum, this).appendTo('#li_container' + y).wrapAll('<ul class="li_cont'+colnum +' ' + classN + '" style="float:left; width: '+col_Width+'px;"></ul>');
}
}
if (settings.equalHeight=='li') {
for (colnum=1; colnum<=settings.cols; colnum++) {
jQuery('#li_container'+ y +' li').each(function() {
var e = jQuery(this);
var border_top = ( isNaN(parseInt(e.css('borderTopWidth'),10)) ? 0 : parseInt(e.css('borderTopWidth'),10) );
var border_bottom = ( isNaN(parseInt(e.css('borderBottomWidth'),10)) ? 0 : parseInt(e.css('borderBottomWidth'),10) );
height = e.height() + parseInt(e.css('paddingTop'), 10) + parseInt(e.css('paddingBottom'), 10) + border_top + border_bottom;
maxHeight = (height > maxHeight) ? height : maxHeight;
});
}
for (colnum=1; colnum<=settings.cols; colnum++) {
var eh = jQuery('#li_container'+ y +' li');
var border_top = ( isNaN(parseInt(eh.css('borderTopWidth'),10)) ? 0 : parseInt(eh.css('borderTopWidth'),10) );
var border_bottom = ( isNaN(parseInt(eh.css('borderBottomWidth'),10)) ? 0 : parseInt(eh.css('borderBottomWidth'),10) );
mh = maxHeight - (parseInt(eh.css('paddingTop'), 10) + parseInt(eh.css('paddingBottom'), 10) + border_top + border_bottom );
eh.height(mh);
}
} else
if (settings.equalHeight=='ul' || settings.equalHeight=='ol') {
for (colnum=1; colnum<=settings.cols; colnum++) {
jQuery('#li_container'+ y +' .li_cont'+colnum).each(function() {
var e = jQuery(this);
var border_top = ( isNaN(parseInt(e.css('borderTopWidth'),10)) ? 0 : parseInt(e.css('borderTopWidth'),10) );
var border_bottom = ( isNaN(parseInt(e.css('borderBottomWidth'),10)) ? 0 : parseInt(e.css('borderBottomWidth'),10) );
height = e.height() + parseInt(e.css('paddingTop'), 10) + parseInt(e.css('paddingBottom'), 10) + border_top + border_bottom;
maxHeight = (height > maxHeight) ? height : maxHeight;
});
}
for (colnum=1; colnum<=settings.cols; colnum++) {
var eh = jQuery('#li_container'+ y +' .li_cont'+colnum);
var border_top = ( isNaN(parseInt(eh.css('borderTopWidth'),10)) ? 0 : parseInt(eh.css('borderTopWidth'),10) );
var border_bottom = ( isNaN(parseInt(eh.css('borderBottomWidth'),10)) ? 0 : parseInt(eh.css('borderBottomWidth'),10) );
mh = maxHeight - (parseInt(eh.css('paddingTop'), 10) + parseInt(eh.css('paddingBottom'), 10) + border_top + border_bottom );
/*eh.height(mh);*/
}
}
jQuery('#li_container' + y).append('<div style="clear:both; overflow:hidden; height:0px;"></div>');
});
}
}
jQuery.fn.uncolumnlists = function(){
jQuery('.li_cont1').each(function(i) {
var onecolSize = jQuery('#li_container' + (++i) + ' .li_cont1 > li').size();
if(jQuery('#li_container' + i + ' .li_cont1').is('ul')) {
jQuery('#li_container' + i + ' > ul > li').appendTo('#li_container' + i + ' ul:first');
for (var j=1; j<=onecolSize; j++) {
jQuery('#li_container' + i + ' ul:first li').removeAttr('class').removeAttr('style');
}
jQuery('#li_container' + i + ' ul:first').removeAttr('style').removeClass('li_cont1').insertBefore('#li_container' + i);
} else {
jQuery('#li_container' + i + ' > ol > li').appendTo('#li_container' + i + ' ol:first');
for (var j=1; j<=onecolSize; j++) {
jQuery('#li_container' + i + ' ol:first li').removeAttr('class').removeAttr('style');
}
jQuery('#li_container' + i + ' ol:first').removeAttr('style').removeClass('li_cont1').insertBefore('#li_container' + i);
}
jQuery('#li_container' + i).remove();
});
}
You wouldn't need to do anything fancy with divs; just give each li tag a unique class, and specify those class colors in css.
From your code, you could change the line
<li class="article">
to
<?php
switch($post->ID) {
case 1:
$class = 'yellow'; break;
case 2:
$class = 'blue'; break;
case 3:
$class = 'green'; break;
}
?>
<li class="article <?php echo $class; ?>">
This will effectively output class='article yellow' for the first article, class='article blue' for the second, etc. You can then make this all work by changing the css as follows:
.li_container .article.yellow:hover { background-color:#57bfeb; }
.li_container .article.green:hover { background-color:green; }
.li_container .article.blue:hover { background-color:blue; }
If you want to get fancy, you could also change switch($post->ID) to switch(mod($post->ID,3)) to do lots of color changing.
eykanal has a good solution. Just to throw out another option, you could use jquery and just dynamically add the classes based on the article positions in the dom. Something like:
Add this inside the head element of your page:
<script type="text/javascript"src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$('.mcol li.article:nth-child(1)').addClass('yellow')
$('.mcol li.article:nth-child(2)').addClass('red')
$('.mcol li.article:nth-child(3)').addClass('blue')
});
</script>
You would then add something like this to your css file:
.yellow:hover { background-color: yellow; }
.red:hover { background-color: red; }
.blue:hover { background-color: blue; }
Change the colors to the hex codes of your choice of course.
Have Fun!
What i'd personally do is add an incrementing class using PHP, like so..
<ul class="mcol">
<?php if(have_posts()) : $i = 0; while(have_posts()) : the_post(); $i++; ?>
<li class="article <?php echo "item-$i";?>">
You then get something like..
<li class="article item-1">content</li>
<li class="article item-2">content</li>
<li class="article item-3">content</li>
Then toggle a class on hover to..
$(document).ready(function(){
$('li.article').hover(function(){
$(this).toggleClass('active-item');
});
});
That then gives you one class that covers all list items, one unique to each item shown, and one that is only attached to the element on hover..
li.article { /* CSS for all list items */ }
li.article.active-item { /* CSS for all any item active */ }
li.item-1 { /* CSS for the first item */ }
li.item-2 { /* CSS for the second item */ }
li.active-item.item-1 { /* CSS for the first item when hovered */ }
li.active-item.item-2 { /* CSS for the secpnd item when hovered */ }
NOTE: It doesn't hurt to make your CSS selectors more specific, adding an ID infront of those(say, the parent list ID) will help ensure you get less conflict with other competing styles.
I hope that's helpful.. ;)