Skip to content

Instantly share code, notes, and snippets.

View Kcko's full-sized avatar
🦜
fly like a bird ...

Kcko

🦜
fly like a bird ...
View GitHub Profile
@Kcko
Kcko / JS: Sort a list alphabetically
Created January 29, 2014 18:34
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) {
@Kcko
Kcko / JS: Clone table header to footer
Created January 29, 2014 18:37
Clone table header to footer
@Kcko
Kcko / JS: Input limiter
Created January 29, 2014 18:49
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);
@Kcko
Kcko / PHP: Date validation (datetime)
Created January 31, 2014 13:45
Validation date & time
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
@Kcko
Kcko / UTF-8 BOOM check
Last active August 29, 2015 13:56
Kontrola BOOMu na začátku souboru
echo "\xEF\xBB\xBF"; // UTF-8 BOM
@Kcko
Kcko / Downlad file via iframe (no refresh page)
Last active August 29, 2015 13:56
Download via Iframe // wo refresh
<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>
@Kcko
Kcko / jquery-conditional-load
Created April 4, 2014 07:55
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>
@Kcko
Kcko / ajax-done-fail
Created April 4, 2014 07:59
Ajax - with done || fail
$.ajax({ ... }).then(successHandler, failureHandler);
// OR
var jqxhr = $.ajax({ ... });
jqxhr.done(successHandler);
jqxhr.fail(failureHandler);
@Kcko
Kcko / Complete ajax
Created April 4, 2014 08:00
Complete ajax
var jqxhr = $.ajax({
url: url,
type: "GET", // default is GET but you can use other verbs based on your needs.
cache: true, // default is true, but false for dataType 'script' and 'jsonp', so set it on need basis.
data: {}, // add your request parameters in the data object.
dataType: "json", // specify the dataType for future reference
jsonp: "callback", // only specify this to match the name of callback parameter your API is expecting for JSONP requests.
statusCode: { // if you want to handle specific error codes, use the status code mapping settings.
404: handler404,
500: handler500
@Kcko
Kcko / jquery multiple on
Created April 4, 2014 08:02
jquery - multiple on
$("#myLink")
.addClass("bold")
.on("click", myClickHandler)
.on("mouseover", myMouseOverHandler)
.show();