Skip to content

Instantly share code, notes, and snippets.

View crizise's full-sized avatar

Kolomiitsev Olexii crizise

  • Kharkiv, Ukraine
View GitHub Profile
@crizise
crizise / admin-testimonials.js
Created February 12, 2018 10:21 — forked from tomazzaman/admin-testimonials.js
How to create a testimonial widget with Backbone
var myWidgets = myWidgets || {};
// Model for a single testimonial
myWidgets.Testimonial = Backbone.Model.extend({
defaults: { 'quote': '', 'author': '' }
});
// Single view, responsible for rendering and manipulation of each single testimonial
myWidgets.TestimonialView = Backbone.View.extend( {
@crizise
crizise / gist:5a8d5745f6d913bfefb6a967d65f7cf8
Created November 30, 2017 08:59 — forked from ivandoric/gist:e4e46294c4d35eac0ec8
wordpress: create custom reset password page
<?php //Add all of this tu custom page template ?>
<?php
global $wpdb;
$error = '';
$success = '';
// check if we're in reset form
if( isset( $_POST['action'] ) && 'reset' == $_POST['action'] )
{
@crizise
crizise / validateFields.js
Created November 2, 2017 14:14
Functions to check is required form fields filled, if not return false and set input container error class
//Check for Required field and if it empty set to error state
function setInputToEdit(id){
var a = document.getElementById(id);
var b = a.parentNode.getElementsByClassName('error-msg');
a.parentNode.classList.add('error-input');
}
//Check is all requred fields have value on fieldset
function passForRequired(input){
var a = input.context.parentElement, // parent with inputs and selects
b = true,
@crizise
crizise / gmaps.php
Last active September 20, 2018 11:09
Enable async defer for Google Maps Library
//enable async defer for Google Maps Library
//google_map_api -- name of before registred script
<?php
add_filter( 'script_loader_tag', function ( $tag, $handle ) {
if ( 'google_map_api' !== $handle )
return $tag;
return str_replace( ' src', ' async defer src', $tag );
}, 10, 2 );
@crizise
crizise / formDataToJson.js
Last active November 1, 2017 21:53
Function serialize form data and return it in JSON Object
//@param input = id of form, string
//@return c = return JSON object
function formDataToJson(input){
//var a not used before
var a = document.getElementById(input),
b = $(input).serializeArray(),
c = {};
for (var i = 0 ; i < b.length; i++) {
c[b[i].name] = b[i].value;
@crizise
crizise / fbLload.html
Last active September 14, 2017 09:39
Facebook IFrame LazyLoading
/*
* FACEBOOK_URL - url from Facebook iframe snippert https://goo.gl/EUcaEn
*
*/
<iframe id="ifr" data-url="FACEBOOK_URL" width="100%" height="189" style="border:none;overflow:hidden"></iframe>
<script>
$(window).on('load', function() {
var a = $('#ifr');
if(a[0].src == ''){
setTimeout(function() {
@crizise
crizise / gmLload.js
Created September 8, 2017 15:55
Lazy load for Google Maps.
<!-- Google Maps -->
<script type="text/javascript">
$(window).on('load', function(){
setTimeout(function() {
var s = document.createElement('script');
s.type = 'text/javascript';
s.src = 'https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap';
s.setAttribute('async', 'defer');
document.getElementsByTagName('footer')[0].appendChild(s);
@crizise
crizise / getVideoId.js
Created September 5, 2017 15:40
Simple function to return the id of YouTube video.
// @input string, YouTube video url
// @return string, YouTube video ID
function getVideoId(input) {
return input.match(/(?:youtu\.be\/|youtube\.com(?:\/embed\/|\/v\/|\/watch\?v=|\/user\/\S+|\/ytscreeningroom\?v=|\/sandalsResorts#\w\/\w\/.*\/))([^\/&]{10,12})/)[1];
}
@crizise
crizise / camelCase.php
Last active September 5, 2017 15:44
Simple way to turn string into camelCase text. Founded here ---> https://goo.gl/fzEqta
/*
*$str - string to change
*
*
*/
function camelCase($str, array $noStrip = [])
{
// non-alpha and non-numeric characters become spaces
$str = preg_replace('/[^a-z0-9' . implode("", $noStrip) . ']+/i', ' ', $str);
$str = trim($str);
@crizise
crizise / scrollDirection.js
Last active October 9, 2017 12:23
Simple way to detect mouse wheel scroll direction. jQuery library required.
<script type="text/javascript">
$(window).on('mousewheel', function(e){
var delta = e.originalEvent.detail < 0 || e.originalEvent.wheelDelta > 0 ? 1 : -1;
if (delta < 0){
console.log('down');
} else{
console.log('up');
}
})
</script>