Skip to content

Instantly share code, notes, and snippets.

View Kelderic's full-sized avatar

Andy Mercer Kelderic

View GitHub Profile
@Kelderic
Kelderic / Date.prototype.toISOTimeString
Created January 24, 2019 13:02
Javascript has Date.toLocaleDateString and Date.toLocaleTimeString, but no toISOTimeString. This code adds in the missing functionality.
Date.prototype.toISOTimeString = function() {
// CREATE ISO STRING AND RETURN JUST THE TIMESTAMP PORTION
return this.toISOString().split('T')[1];
};
@Kelderic
Kelderic / Date.prototype.toISODateString
Created January 24, 2019 13:01
Javascript has Date.toLocaleDateString and Date.toLocaleTimeString, but no toISODateString. This code adds in the missing functionality.
Date.prototype.toISODateString = function() {
// CREATE ISO STRING AND RETURN JUST THE DATE PORTION
return this.toISOString().split('T')[0];
};
@Kelderic
Kelderic / getAncestorByTagName
Created August 4, 2017 13:10
Sometimes I'll create list items with nested child elements. A click's event.target may register on the nested element or the parent. This element prototype allows standardization of that.
HTMLElement.prototype.getAncestorByTagName = function( tagName ) {
var target = this;
while ( target.tagName.toLowerCase() != tagName && target.tagName.toLowerCase() != 'body' ) {
target = target.parentNode;
}
if ( target.tagName.toLowerCase() == 'body' ) {
return false;
} else {
return target;
}
// FORCE ALL TRAFFIC TO USE SSL
add_filter( 'admin_init' , 'prefix_add_force_ssl_setting' );
add_action('template_redirect', 'prefix_force_ssl');
function prefix_add_force_ssl_setting() {
register_setting( 'general', 'prefix_force_ssl', 'esc_attr' );
@Kelderic
Kelderic / azm_settings_page.php
Last active June 28, 2017 23:33
This is a helper class for creating settings pages, for plugins. Using this, you can just create one large array of data rather than having to manage all the functions and hooks that WordPress requires for a settings page.
<?php
if ( ! class_exists( 'AZM_Settings_Page' ) ) {
class AZM_Settings_Page {
/***********************************************************************/
/*************************** CONSTRUCTOR *****************************/
/***********************************************************************/
@Kelderic
Kelderic / foobarclass.js
Last active December 28, 2018 15:53
Javascript Class Skeleton
(function(window) {
window.FooBarClass = (function() {
/***************************************/
/************* INITIALIZE **************/
/***************************************/
var Class = function( params ) {
@Kelderic
Kelderic / HTMLElement.prototype.scrollHorizontally
Last active January 12, 2017 14:44
This is an element prototype that animates the element's horizontal scroll. By default, it scrolls the element all the way over to the right, and if an integer is passed in, it animates until the element's scrollLeft property equals that integer.
HTMLElement.prototype.scrollHorizontally = function( newScrollLeft ) {
var self = this;
newScrollLeft = newScrollLeft ? newScrollOffset : self.scrollWidth - self.offsetWidth
animate();
function animate(){
@Kelderic
Kelderic / custom_post_types.php
Last active August 8, 2023 13:39
This is set of helper classes to create and manage custom post types for WordPress. It gets added to a theme's logic folder, or libs or includes folders, and included in functions.php. Then the primary tracker class is initiated once, and used to create new CTPs.
<?php
/***********************************************************************/
/*************************** TRACKER CLASS ***************************/
/***********************************************************************/
if ( ! class_exists( 'Custom_Post_Types_Manager' ) ) {
class Custom_Post_Types_Manager {
@Kelderic
Kelderic / ajax.js
Last active January 23, 2019 16:08
Ajax Without jQuery
window.ajax = function( params ) {
var method = 'method' in params ? params['method'] : 'get';
var queryURL = 'queryURL' in params ? params['queryURL'] : '';
var data = 'data' in params ? params['data'] : '';
var dataArray = [];
var dataString = '';
var successCallback = 'success' in params ? params['success'] : function(params){console.log('Successfully completed AJAX request.')};