Skip to content

Instantly share code, notes, and snippets.

View mis8680's full-sized avatar
πŸ‘¨β€πŸ‘¨β€πŸ‘§β€πŸ‘¦
Dad of 1 boy & 1 chihuahua

Insu Mun mis8680

πŸ‘¨β€πŸ‘¨β€πŸ‘§β€πŸ‘¦
Dad of 1 boy & 1 chihuahua
View GitHub Profile
@mis8680
mis8680 / vuejs-form-handler.js
Last active January 11, 2017 21:51
A form handler for vuejs using axios.
class Form {
constructor(data) {
this.data = data;
for(let field in data) {
this[field] = data[field];
}
this.errors = new Errors();
}

BEM

Know your element (__) from your modifier (--). Both blocks and elements can have modifiers. (.b--m, .b__e--m).

In react lingo, BEM's "B" (for "Block") is a component.

Elements can nest deep in html, but the selector doesn't represent this deep nesting. (no .a__b__c, instead just .a__c - which can be in .a__b).

The idea The idea with BEM is to keep a flat hierarchy (don't nest selectors) with simple selectors - only one class per selector, and no IDs or element tags. By not nesting we have a low and consistent specificity of all html elements, which makes it possible to have modifications of styles without using !important.

class Errors {
constructor() {
this.errors = {};
}
has(field) {
return this.errors.hasOwnProperty(field);
}
any() {
@mis8680
mis8680 / vuejs-event-handler.js
Created January 11, 2017 17:08
To handle a communication between components
window.Event = new class {
constructor() {
this.vue = new Vue();
}
fire(evnet, data = null) {
this.vue.$emit(event, data);
}
listen(event, calllback) {
@mis8680
mis8680 / responsive.css
Created December 22, 2015 19:10
Responsive effect css
// Move main container position to original
-webkit-transform: translate(0,0);
-moz-transform: translate(0,0);
-ms-transform: translate(0,0);
-o-transform: translate(0,0);
transition: all 0.2s ease;
// Move main container 300px for mobile version
-webkit-transform: translate(300px, 0);
-moz-transform: translate(300px, 0);
@mis8680
mis8680 / admin_bar_fix.php
Created December 11, 2015 21:47
WordPress adds CSS for the admin bar with _admin_bar_bump_cb() found in wp-includes/admin-bar.php. This puts margin-top: 28px on <html> which can mess up position: absolute elements.
<?php
function admin_bar_fix() {
if(!is_admin() && is_admin_bar_showing()) {
remove_action('wp_head', '_admin_bar_bump_cb');
$output = '<style type="text/css">'."\n\t";
$output .= 'body.admin-bar { padding-top: 28px; }'."\n";
$output .= '</style>'."\n";
echo $output;
}
}
@mis8680
mis8680 / functions.php
Created October 9, 2015 18:27
Various common WordPress editor styles
/**
* @param array $config
*
* @return array
*/
function tiny_mce_before_init(array $config)
{
$styleFormats = [
// Utility classes like "float right"
[
# Apache Server Configs v2.14.0 | MIT License
# https://github.com/h5bp/server-configs-apache
# (!) Using `.htaccess` files slows down Apache, therefore, if you have
# access to the main server configuration file (which is usually called
# `httpd.conf`), you should add this logic there.
#
# https://httpd.apache.org/docs/current/howto/htaccess.html.
# ######################################################################
@mis8680
mis8680 / .htaccess
Last active August 29, 2015 14:16
.htaccess Error 500 in Apache 2.4 because of FilterProvider
# HTML, TXT, CSS, JavaScript, JSON, XML, HTC:
<IfModule filter_module.c>
<IfModule version.c>
<IfVersion >= 2.4>
FilterDeclare COMPRESS
FilterProvider COMPRESS DEFLATE "%{CONTENT_TYPE} =~ m#^text/(html|css|plain|xml|x-component)#i"
FilterProvider COMPRESS DEFLATE "%{CONTENT_TYPE} =~ m#^application/(javascript|json|xml|xhtml+xml|rss+xml|atom+xml|vnd.ms-fontobject|x-font-ttf)#i"
FilterProvider COMPRESS DEFLATE "%{CONTENT_TYPE} =~ m#^image/(svg+xml|x-icon)#i"
FilterProvider COMPRESS DEFLATE "%{CONTENT_TYPE} = 'font/opentype'"
FilterChain COMPRESS
@mis8680
mis8680 / Booter.php
Created March 3, 2015 21:36
Laraval Corcel booter file for wordpress.
use Corcel;
class Booter
{
public static function boot()
{
self::setupEloquentDatabase();
}
protected static function setupEloquentDatabase()
{