Skip to content

Instantly share code, notes, and snippets.

View siamkreative's full-sized avatar

Julien Vernet siamkreative

View GitHub Profile
@siamkreative
siamkreative / as_customisations.js
Created February 4, 2016 03:34
Example of customisations for Awesome Support: Adding custom fields and conditional logic
jQuery(document).ready(function ($) {
/**
* Get URL Parameters using jQuery
* http://stackoverflow.com/a/21903119
*/
var getUrlParameter = function getUrlParameter(sParam) {
var sPageURL = decodeURIComponent(window.location.search.substring(1)),
sURLVariables = sPageURL.split('&'),
sParameterName,
@siamkreative
siamkreative / pluginLoaded.js
Created March 4, 2016 04:36
Check if a jQuery plugin is loaded. If not, load it using the $.getScript() function.
jQuery(document).ready(function ($) {
'use strict';
function initModal() {
$('.popup-youtube, .popup-vimeo, .popup-gmaps').magnificPopup({
disableOn: 700,
type: 'iframe',
mainClass: 'mfp-fade',
removalDelay: 160,
@siamkreative
siamkreative / editorEmptyCheck.js
Created March 28, 2016 03:42
Check if a TinyMCE editor is empty in WordPress
jQuery(document).ready(function ($) {
// Check if TinyMCE is active
if (typeof tinyMCE != "undefined") {
$('form').on('submit', function () {
// Get content of active editor
var editorContent = tinyMCE.activeEditor.getContent();
if ((editorContent === '' || editorContent === null)) {
// Do stuff when TinyMCE is empty
}
.gmap {
position: relative;
padding-bottom: 50%; // This is the aspect ratio
height: 0;
overflow: hidden;
}
.gmap > .wp_gmaps_canvas {
position: absolute;
top: 0;
left: 0;
@siamkreative
siamkreative / formspree-ajax-contact-form.js
Created March 30, 2016 02:46
A plain JavaScript AJAX Contact Form that is designed to work with http://formspree.io/
/**
* AJAX Form
* http://stackoverflow.com/a/13038218/1414881
*/
var form = document.getElementById('contact_form');
// Append the form status
var formStatus = document.createElement('div');
formStatus.setAttribute('class', 'form-status alert');
jQuery(document).ready(function ($) {
var select = $('#taed-font-family');
var fontTypes = [];
var fontsOptions = '';
$.getJSON('/websafefonts.json', function (json) {
$.each(json.fonts, function (type, fontArr) {
fontTypes.push(type);
$.each(fontArr, function (index, font) {
fontsOptions += '<option value="' + font + '" class="fonttype" data-type="' + type + '">' + font + '</option>'
@siamkreative
siamkreative / as_custom_fields.php
Created May 27, 2016 07:39
Awesome Support - Register a custom field after the plugin is safely loaded
<?php
/**
* Register all custom fields after the plugin is safely loaded.
*/
add_action( 'plugins_loaded', 'wpas_user_custom_fields' );
function wpas_user_custom_fields() {
if ( function_exists( 'wpas_add_custom_field' ) ) {
wpas_add_custom_taxonomy( 'my_custom_services', array( 'title' => 'My Custom Services', 'label' => 'Service', 'label_plural' => 'Services' ) );
}
}
@siamkreative
siamkreative / wpbp-grid.php
Created June 15, 2016 02:47
Behance Portfolio for WordPress - 4 Columns Layout for Boostrap Themes http://codecanyon.net/item/behance-portfolio-for-wordpress/7123148?ref=themeavenue
<div id="<?php echo $project->get_field( 'id' ); ?>" class="col-sm-3 wpbp-mix <?php echo $fields; ?>" data-pubdate="<?php echo $project->get_field( 'published_on' ); ?>">
<figure>
<a class="wpbp-project-imglink ta-modal-launch" href="#wpbp-project-<?php echo $project->get_field( 'id' ); ?>"><img src="<?php echo $project_cover; ?>" alt="<?php echo $project->get_field( 'name' ); ?>" class="img-responsive"></a>
<figcaption>
<div class="wpbp-valign">
<div class="wpbp-valign-inner">
<div class="wpbp-project-title"><?php echo $project->get_field( 'name' ); ?></div>
<div class="wpbp-project-fields"><?php echo implode( ', ', $project->get_fields() ); ?></div>
<a class="wpbp-project-more ta-modal-launch" href="#wpbp-project-<?php echo $project->get_field( 'id' ); ?>"><?php echo $button_label; ?></a>
</div>
@siamkreative
siamkreative / sublime_key_bindings.json
Created June 21, 2016 05:22
Sublime Text 3 Key Bindings
[{
"keys": ["f12"],
"command": "chain",
"args": {
"commands": [
["reindent", {
"single_line": false,
"detect_indentation": false,
"tab_size": 4,
"translate_tabs_to_spaces": true
@siamkreative
siamkreative / README.md
Last active January 9, 2017 06:10
Boostrap 4 Navbar Fixed to top. Placement using JavaScript

What Is This?

This is for the fixed to top version of the Boostrap 4 navbar. Instead of setting the padding and top position in CSS, let's use JavaScript to get it dynamically.

How To Use?

It is best to use the pure JavaScript version. It will be executed earlier since it does not require jQuery to be loaded. The vanilla JavaScript version can be used in the <head> section.

If you are a performance concerned developer, your scripts are probably in the footer just before </body>. Therefore, there might be a slight delay before the jQuery snippet is executed. This can lead to elements jumping around...