I've been wanting to play with git, so I created repositories for all my jquery plugins at github.com.
http://github.com/dsparling
For now, that would be:
jClock
datemaker
regexpCommon
git documentation:
http://git.or.cz/#documentation
http://www.sourcemage.org/Git_Guide
http://www.gitcasts.com/
Tech Tidbits - Ruby, Ruby On Rails, Merb, .Net, Javascript, jQuery, Ajax, CSS...and other random bits and pieces.
Showing posts with label jQuery. Show all posts
Showing posts with label jQuery. Show all posts
Tuesday, May 20, 2008
Wednesday, February 27, 2008
jQuery Sortable with Ajax, PHP, and MySQL
I needed to create a sortable list that would save the order position of data items. I've been using jQuery more and more and decided to go with the Interface Elements for jQuery.
I found a blog entry titled jQuery Sortable Ajax PHP Integration that was a good start. However, it didn't actually use MySQL to store the sorted data so I've gone ahead and added the database queries and updates.
First I created a simple table to store links (I'd like my client to order the links they enter through an admin interface).
Next is the PHP page that reads the link data from the table and displays the links based on the order_position column of the table.
index.php
This will make an Ajax call back to the server where PHP will update the database as you drag and sort the list data:
sortdata.php
A little CSS certainly wouldn't hurt things. Here's some I found on another tutorial:
I wouldn't call this production ready code, but all the pieces are in place if you'd like to use jQuery with Ajax, PHP, and MySQL for a sortable list. Don't forget, you'll need to get jQuery itself and the interface.js file as well. Another thing to consider is alerting the user if the update fails or takes a long time.
I found a blog entry titled jQuery Sortable Ajax PHP Integration that was a good start. However, it didn't actually use MySQL to store the sorted data so I've gone ahead and added the database queries and updates.
First I created a simple table to store links (I'd like my client to order the links they enter through an admin interface).
CREATE TABLE links (
id int(10) NOT NULL auto_increment,
link_url varchar(50) NOT NULL,
link_text varchar(50) NOT NULL,
order_position int(2),
primary key(id)
);
Next is the PHP page that reads the link data from the table and displays the links based on the order_position column of the table.
index.php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript" src="/js/jquery/jquery-1.2.3.min.js"></script>
<script type="text/javascript" src="interface.js"></script>
<script>
$(document).ready(
function() {
$("#sortme").Sortable({
accept : 'sortitem',
onchange : function (sorted) {
serial = $.SortSerialize('sortme');
$.ajax({
url: "sortdata.php",
type: "POST",
data: serial.hash,
// complete: function(){},
//success: function(feedback){ $('#data').html(feedback); }
// error: function(){}
});
}
});
}
);
</script>
</head>
<body>
<ul id="sortme">
<?php
// Connect to the database as necessary
$dbh = mysql_connect('127.0.0.1','username','password')
or die ("Unaable to connnect to MySQL");
$selected = mysql_select_db("sort_test",$dbh)
or die("Could not select sort_test");
$result = mysql_query('SELECT * FROM links ORDER BY order_position');
while ($row = mysql_fetch_array($result)) {
print '<li id="' . $row{'id'} . '" class="sortitem">' . $row{'link_text'} . "\n";
}
mysql_close($dbh);
?>
</ul>
</body>
</html>
This will make an Ajax call back to the server where PHP will update the database as you drag and sort the list data:
sortdata.php
<?php
$sortme = $_POST['sortme'];
// Connect to the database as necessary
$dbh = mysql_connect('127.0.0.1','username','password')
or die ("Unaable to connnect to MySQL");
$selected = mysql_select_db("sort_test",$dbh)
or die("Could not select sort_test");
for ($i = 0; $i < count($sortme); $i++) {
mysql_query("UPDATE links SET order_position=$i WHERE id=$sortme[$i]");
}
mysql_close($dbh);
?>
A little CSS certainly wouldn't hurt things. Here's some I found on another tutorial:
<style>
ul {
list-style: none;
}
li {
background: #727EA3;
color: #FFF;
width: 100px;
margin: 5px;
font-size: 10px;
font-family: Arial;
padding: 3px;
}
</style>
I wouldn't call this production ready code, but all the pieces are in place if you'd like to use jQuery with Ajax, PHP, and MySQL for a sortable list. Don't forget, you'll need to get jQuery itself and the interface.js file as well. Another thing to consider is alerting the user if the update fails or takes a long time.
Tuesday, February 19, 2008
jQuery
I've been using the jQuery Javascript library a lot lately and it's definitely become my favorite library. (I've written four plugins in the last couple months to boot)
Here are a few links to useful jQuery resources.
jQuery: The Write Less, Do More, JavaScript Library
jQuery UI: Widgets, Components, and Interaction
Plugins - jQuery JavaScript Library
jQuery Blog
Learning jQuery
Visual jQuery
IBM developerWorks: Simplify Ajax development with jQuery
Here are a few links to useful jQuery resources.
jQuery: The Write Less, Do More, JavaScript Library
jQuery UI: Widgets, Components, and Interaction
Plugins - jQuery JavaScript Library
jQuery Blog
Learning jQuery
Visual jQuery
IBM developerWorks: Simplify Ajax development with jQuery
Wednesday, January 23, 2008
jQuery: Cookie Plugin
I've become a big fan of jQuery and have contributed two small plugins myself, so when it came time to switch to a library for cookie manipulation with Javascript (time to replace all that nasty inline JS code) my first choice was jQuery.
Not to be disappointed, I found that Klaus Hartl has written a very slim and useful Cookie Plugin for jQuery.
Here's a small page test using the jQuery Cookie plugin:
My jQuery cookie demo using jquery.cookie.js
Not to be disappointed, I found that Klaus Hartl has written a very slim and useful Cookie Plugin for jQuery.
Here's a small page test using the jQuery Cookie plugin:
<html>
<head>
<title>jquery cookie</title>
<script type="text/javascript" src="jquery-1.2.1.min.js"></script>
<script type="text/javascript" src="jquery.cookie.js"></script>
<script type="text/javascript">
$(function($) {
function displayMessage(msg) {
$('#message').html(msg).css({color: 'green'});
}
displayMessage('jQuery cookie plugin test');
$('#setSessionCookie').click(function() {
$.cookie('test', 'Hmmm, cookie');
displayMessage("Cookie 'test' has been set.");
});
$('#setCookie').click(function() {
$.cookie('test', 'Hmmm, cookie', { expires: 7 });
displayMessage("Cookie 'test' has been set and will expire in 7 days.");
});
$('#getCookie').click(function() {
displayMessage("The value of the cookie named 'test' is: " + $.cookie('test'));
});
$('#deleteCookie').click(function() {
$.cookie('test', null);
displayMessage("Cookie 'test' has been deleted.");
});
$('#testCookiesEnabled').click(function() {
$.cookie('testcookiesenabled', null);
$.cookie('testcookiesenabled', 'enabled');
if ($.cookie('testcookiesenabled')) {
displayMessage("Cookie: "+ $.cookie('testcookiesenabled'));
} else {
displayMessage("Cookies disabled");
$.cookie('testcookiesenabled', null);
}
});
});
</script>
</head>
<body>
<p><span id="message" style="forecolor: red;"></span>
<p><input type="button" id="testCookiesEnabled" value="Cookies enabled?"/></p>
<p><input type="button" id="setSessionCookie" value="Set session cookie"/></p>
<p><input type="button" id="setCookie" value="Set cookie expires in 7 days"/></p>
<p><input type="button" id="getCookie" value="Show cookie value"/></p>
<p><input type="button" id="deleteCookie" value="Delete the cookie"/></p>
</body>
</html>
My jQuery cookie demo using jquery.cookie.js
Subscribe to:
Posts (Atom)
About Me
- Doug Sparling
- Developer (Ruby on Rails, iOS), musician/composer, Buddhist, HSP, Vegan, Aspie.
Labels
- .NET (8)
- accordion (1)
- ActiveRecord (1)
- ajax (2)
- APT (1)
- apt-get (1)
- ASP (1)
- ASP.NET .NET (5)
- Audio (1)
- aws (1)
- Bash (1)
- bdd (1)
- C# (1)
- cache_fu (1)
- caching (1)
- DocBook (1)
- DOM (1)
- Eclipse (1)
- Excel (1)
- Firefox (1)
- gem (5)
- Gems (5)
- git (1)
- GridView (2)
- Hibernate (1)
- iBATIS (1)
- Java (9)
- javascript (9)
- javascript css (1)
- jQuery (4)
- jsspec (1)
- mdb2 (2)
- Merb (2)
- mongrel (2)
- mp3 (2)
- Music (2)
- MySQL (2)
- nginx (1)
- openssl (1)
- osx (3)
- pdocast (1)
- pear (2)
- Perl (7)
- php (5)
- plugin (2)
- podcast (1)
- prototype (1)
- REST (1)
- RMagick MacOSX (1)
- rspec (1)
- ruby (14)
- ruby on rails (21)
- RubyGems Merb (1)
- s3 (1)
- screencasts (1)
- scriptaculous (1)
- scriptrunner ruby rails erlang (1)
- Sortable (1)
- subversion (1)
- testing (1)
- testing erlang tsung (1)
- tomcat (1)
- ubuntu (2)
- WebSphere (1)
- will_paginate (1)