Skip to content

Instantly share code, notes, and snippets.

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

Roman Janko Kcko

🦜
fly like a bird ...
View GitHub Profile
@Kcko
Kcko / reverse-each.js
Created January 22, 2017 09:40
jQuery - reverse each
$(function(){
var reversedSet = $("li").get().reverse();
//Use get() to return an array of elements, and then reverse it
$(reversedSet).each(function(){
//Now we can plug our reversed set right into the each function. Could it be easier?
});
});
@Kcko
Kcko / jquery-widow.js
Created January 22, 2017 09:44
jQuery - remove widows
$(function(){
//Loop through each title
$("h3").each(function(){
var content = $(this).text().split(" ");
var widow = " "+content.pop();
$(this).html(content.join(" ")+widow);
});
});
@Kcko
Kcko / array-get.js
Created January 22, 2017 09:46
jQuery - Array of GET variables
var searchArray = document.location.search.substring(1).split("&");
//Take off the '?' and split into separate queries
//Now we'll loop through searchArray and create an associative array (object literal) called GET
var GET = [];
for (var searchTerm in searchArray){
searchTerm.split("="); //Divide the searchTerm into property and value
GET[searchTerm[0]] = searchTerm[1]; //Add property and value to the GET array
}
@Kcko
Kcko / chil-of-selector.js
Created January 22, 2017 09:49
jQuery - own methods
$(function(){
jQuery.extend(jQuery.expr[':'], {
'child-of' : function(a,b,c) {
return (jQuery(a).parents(c[3]).length > 0);
}
});
//'child-of' is now a valid selector:
$("li:child-of(ul.test)").css("background","#000");
});
// output headers so that the file is downloaded rather than displayed
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=data.csv');
// create a file pointer connected to the output stream
$output = fopen('php://output', 'w');
// output the column headings
fputcsv($output, array('Column 1', 'Column 2', 'Column 3'));
@Kcko
Kcko / capslock.js
Created January 24, 2017 13:48
Capslock.js - example how to write js native plugin
/*
CapsLock.js
An object allowing the status of the caps lock key to be determined
Created by Stephen Morley - http://code.stephenmorley.org/ - and released under
the terms of the CC0 1.0 Universal legal code:
http://creativecommons.org/publicdomain/zero/1.0/legalcode
@Kcko
Kcko / jquery-email-validation.js
Created January 29, 2017 19:42
jQuery e-mail plugin validation
(function ($) {
$.fn.validateEmail = function () {
return this.each(function () {
var $this = $(this);
$this.change(function () {
var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
if ($this.val() == "") {
$this.removeClass("badEmail").removeClass("goodEmail")
}else if(reg.test($this.val()) == false) {
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>Google Maps Multiple Markers</title>
<script src="http://maps.google.com/maps/api/js?sensor=false"
type="text/javascript"></script>
</head>
<body>
<div id="map" style="width: 500px; height: 400px;"></div>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Multiple Markers Google Maps</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?v=3.11&sensor=false" type="text/javascript"></script>
<script type="text/javascript">
// check DOM Ready
jQuery(function($) {
// Asynchronously Load the map API
var script = document.createElement('script');
script.src = "//maps.googleapis.com/maps/api/js?sensor=false&callback=initialize";
document.body.appendChild(script);
});
function initialize() {
var map;
var bounds = new google.maps.LatLngBounds();