Skip to content

Instantly share code, notes, and snippets.

View davidtrushkov's full-sized avatar

David Trushkov davidtrushkov

View GitHub Profile
@davidtrushkov
davidtrushkov / gist:0f0707169771d68cc26851e5441a5058
Created June 28, 2016 03:26
Simple way to submit a form. For example in ( Laravel )
//$(document).ready(function(){ <--- Or you can use this
jQuery(function($) {
$("submit").click(function(){
var $form = $(this);
//var $target = $($form.attr('data-target'));
$.ajax({
type: $form.attr('method'),
url: $form.attr('action'),
data: $form.serialize(),
class Chat extends Model {
protected $table = "chat";
protected $appends = ['gamertag', 'slug'];
/**
@davidtrushkov
davidtrushkov / centering.css
Created September 27, 2016 01:06 — forked from gartenfeld/centering.css
Centering without Flexbox
// Add full screen wrapper
.box {
top: 50%;
left: 50%;
margin: 0;
position: absolute;
transform: translate(-50%, -50%);
}
@davidtrushkov
davidtrushkov / gist:a8bdb87227db23b147ddc22136ebc330
Created December 21, 2016 22:32
Make Bootstrap Carousel Dynamic - Laravel 5.3
<div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
@foreach( $trip->photos as $photo )
<li data-target="#carousel-example-generic" data-slide-to="{{ $loop->index }}" class="{{ $loop->first ? 'active' : '' }}"></li>
@endforeach
</ol>
<!-- Wrapper for slides -->
@davidtrushkov
davidtrushkov / gist:d51e5f8683fd16deaa75bfdbd89df0fd
Created February 6, 2017 17:21
Handling Long Words and URLs (Forcing Breaks, Hyphenation, Ellipsis, etc)
.dont-break-out {
/* These are technically the same, but use both */
overflow-wrap: break-word;
word-wrap: break-word;
-ms-word-break: break-all;
/* This is the dangerous one in WebKit, as it breaks things wherever */
word-break: break-all;
/* Instead use this non-standard one: */
@davidtrushkov
davidtrushkov / Dynamically add a active class to tabs
Created February 28, 2017 15:01
Dynamically add a active class to tabs with Javascript. I used this in WordPress.
<script>
$(".nav-link").on("click", function(){
$(".nav").find(".active").removeClass("active");
$(this).parent().addClass("active");
});
</script>
@davidtrushkov
davidtrushkov / Switch image container position in PHP - (WordPress) foreach loop
Created March 27, 2017 15:49
This is how you would switch the image container position in a PHP foreach loop using WordPress.
<div class="container-fluid no-padding hidden-xs">
<?php foreach (get_posts(['post_type' => 'home_project_section', 'posts_per_page'=>100]) as $key => $homeProjects) {
$thumb_id = get_post_thumbnail_id($homeProjects);
$thumb_url_array = wp_get_attachment_image_src($thumb_id, 'thumbnail-size', true);
$thumb_url = $thumb_url_array[0];
$website_url = '/projects/';
$url_to_project = $website_url . $homeProjects->post_name;
?>
<?php if($key % 2 == 0) { ?>
<div class="col-xs-12 no-padding">
@davidtrushkov
davidtrushkov / Vue JS + Laravel instant search
Last active May 3, 2017 14:55
Make a simple Vue JS and Laravel instant search
@davidtrushkov
davidtrushkov / Laravel 5.5 multiple select tagging system.
Created September 5, 2017 12:54
Add multiple select tagging in Laravel 5.5 with Select2. Can be reused with different models. Also keeps old data selected on reload and on edit.
// The taggable database table
public function up() {
Schema::create('stateables', function (Blueprint $table) { // In this case taggables
$table->increments('id');
$table->string('stateables_type'); // In this case taggable_type
$table->integer('stateables_id')->unsigned(); // In this case taggables_id
$table->integer('state_id')->unsigned(); // In this case tag_id
$table->timestamps();
});
@davidtrushkov
davidtrushkov / Chunk data in Vue JS
Created September 15, 2017 15:10
I show here how to chunk data into rows while looping through them using Vue JS
<template>
<div class="col-sm-12 no-padding">
<div v-if="this.myOffers.length > 0">
<div v-for="chunk in offerChunks">
<div class="row">
<div class="col-sm-4" v-for="offer in chunk">
<!--- Content here ---->
</div>
</div>
</div>