Created
November 5, 2011 05:55
-
-
Save walterdavis/1341161 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
ini_set('display_errors', 1); | |
error_reporting(E_ALL); | |
function humanize($string){ | |
return htmlspecialchars(ucwords(preg_replace('/_+/',' ',$string))); | |
} | |
define('MYACTIVERECORD_CONNECTION_STR', 'mysql://test:pass@localhost/test'); | |
require_once('lib/MyActiveRecord.php'); | |
class widgets extends MyActiveRecord{}; | |
$widgets = MyActiveRecord::FindAll('widgets', null, 'position ASC'); | |
?> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset=utf-8 /> | |
<title>Sortable List Demo</title> | |
<link rel="stylesheet" type="text/css" media="screen" href="css/style.css" /> | |
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/prototype/1.7/prototype.js"></script> | |
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/scriptaculous/1.9/scriptaculous.js"></script> | |
<script type="text/javascript" charset="utf-8"> | |
document.observe('dom:loaded', function(){ | |
Sortable.create('sort_me',{ | |
tag:'div', | |
onChange:function(elm){ | |
new Ajax.Request('save_sort_order.php',{ | |
parameters:Sortable.serialize('sort_me'), | |
onSuccess:function(){ | |
$('sort_me').highlight({restoreColor:'#ffffff'}); | |
} | |
}); | |
}, | |
constraint:false | |
}); | |
}); | |
</script> | |
<!--[if IE]> | |
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> | |
<![endif]--> | |
</head> | |
<body> | |
<div id="sort_me"> | |
<?php | |
$template = ' <div id="widget_%s" class="widget"> | |
<h1>%s</h1> | |
</div> | |
'; | |
foreach($widgets as $widget){ | |
printf($template, $widget->id, humanize($widget->name)); | |
} | |
?> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment