View JS: Sort a list alphabetically
$(function() {
$.fn.sortList = function() {
var mylist = $(this);
var listitems = $('li', mylist).get();
listitems.sort(function(a, b) {
var compA = $(a).text().toUpperCase();
var compB = $(b).text().toUpperCase();
return (compA < compB) ? -1 : 1;
});
$.each(listitems, function(i, itm) {
View JS: Preload Images
$.preloadImages = function() {
for(var i = 0; i<arguments.length; i++) {
$("<img />").attr("src", arguments[i]);
}
}
$(document).ready(function() {
$.preloadImages("hoverimage1.jpg","hoverimage2.jpg");
});
View JS: Clone table header to footer
View JS: Input limiter
function($) {
$.fn.extend( {
limiter: function(limit, elem) {
$(this).on("keyup focus", function() {
setCount(this, elem);
});
function setCount(src, elem) {
var chars = src.value.length;
if (chars > limit) {
src.value = src.value.substr(0, limit);
View PHP: Date validation (datetime)
function validateDate($date, $format = 'Y-m-d H:i:s')
{
$d = DateTime::createFromFormat($format, $date);
return $d && $d->format($format) == $date;
}
var_dump(validateDate('2012-02-28 12:12:12')); # true
var_dump(validateDate('2012-02-30 12:12:12')); # false
var_dump(validateDate('2012-02-28', 'Y-m-d')); # true
var_dump(validateDate('28/02/2012', 'd/m/Y')); # true
View UTF-8 BOOM check
echo "\xEF\xBB\xBF"; // UTF-8 BOM
View Convert utf-8 to win1250 - csv export + czech diacritics
<?php
$out = iconv('utf-8', 'windows-1250//TRANSLIT', $out);
$filename = 'katalog-export___' . date('YmdHis') . '.csv';
header('Content-Encoding: windows-1250');
header('Content-type: text/csv; charset=windows-1250');
header('Content-Disposition: attachment; filename=' . $filename);
//echo "\xEF\xBB\xBF"; // UTF-8 BOM
View Downlad file via iframe (no refresh page)
<a href="" id="csv-export">export</a>
<iframe id="downloadIframe" src="" style="height: 0px; width: 0px; display: none;"></iframe>
<script>
$("#csv-export").click(function(e){
e.preventDefault();
oIFrm = document.getElementById('downloadIframe');
oIFrm.src = '' // URL to download file -- via php download headers;
});
</script>
View HTML skelet.html
<!doctype html>
<html lang="cs">
<head>
<meta charset="UTF-8" />
<title>Your Page</title>
</head>
<body>
<!--Your content here -->
View jquery-conditional-load
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="js/jquery-1.11.0.min.js" type="text/javascript"><\/script>')</script>