Skip to content

Instantly share code, notes, and snippets.

View zeshanshani's full-sized avatar
🎯
Focusing

Zeshan Ahmed zeshanshani

🎯
Focusing
View GitHub Profile
@zeshanshani
zeshanshani / getCursorPosition.js
Created January 17, 2017 06:20
Get the cursor position in an input field. Best to use in combination with 'keyup', 'keydown', 'focus', etc. events.
/**
* Get Cursor Position in Input Field
* @return integer Returns the cursor position.
*
* Source: Stackoverflow
* Source URI: http://stackoverflow.com/a/2897510/3107931
*
* Usage: $('input[type="text"]').getCursorPosition()
*/
$.fn.getCursorPosition = function() {
@zeshanshani
zeshanshani / AbsoluteAnchorLinksToOtherPages.js
Last active December 13, 2016 04:18
Adding Full Absolute URLs to the Anchor Links in the Navbar that are not on the same page. Works best with the parent menu and sub-menu links in the navbar. And for WordPress navbar especially.
/**
* Adding Full Absolute URLs to the Anchor Links in the Navbar that are not
* on the same page. Works best with the parent menu and sub-menu
* links in the navbar. And for WordPress navbar especially.
*
* Replace #parent_links_selector with the parent links selector
*/
jQuery(document).ready(function($) {
$('#parent_links_selector').each(function(i, el) {
@zeshanshani
zeshanshani / pure-css-cross.css
Created October 26, 2016 12:58
Pure CSS cross in both SCSS and CSS.
.element {
position: relative;
height: 22px;
height: 2.2rem;
width: 22px;
width: 2.2rem;
}
.element:before, .element:after {
content: '';
height: 1px;
@zeshanshani
zeshanshani / polylang_custom_language_switcher.css
Last active February 19, 2023 06:12
Custom Language Switcher for Polylang. Contains both the PHP function and SCSS styling. HTML markup is using BEM methodology. SCSS file is using my variables and mixins from here: https://gist.github.com/zeshanshani/c4d5ae43e6a9f661d012
/* Component: Languages */
.languages__item {
text-transform: uppercase;
color: #899099;
font-size: 13px;
font-size: 1.3rem;
line-height: 1.15;
}
.languages__item--current {
color: #212121;
@zeshanshani
zeshanshani / acf_options_multilingual.php
Last active October 10, 2023 11:25
Creates separate Advanced Custom Fields options pages for the specified languages.
<?php // Don't copy this line if you are inserting in a file that has it already.
/**
* ACF Options Page
*
* Instructions:
* Add more languages to the array below: $languages
*
* @author: Zeshan Ahmed <https://zeshanahmed.com/>
*/
@zeshanshani
zeshanshani / convertURLToLinks.js
Created October 7, 2016 04:54
Check if a string contains any URLs and wrap them all into HTML <a> tags.
@zeshanshani
zeshanshani / nav-menu-exporter-importer.php
Created September 1, 2016 09:04 — forked from hissy/nav-menu-exporter-importer.php
[WordPress Plugin] Nav Menu Exporter and Importer / Export and Import nav menus. Requires WordPress Importer plugin.
<?php
/*
Plugin Name: Nav Menu Exporter and Importer
Description: Export and Import nav menus. Requires WordPress Importer plugin
Author: hissy, megumi themes
Version: 0.1
Text Domain: nav-menu-exporter-importer
License: GPL version 2 or later - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*/
@zeshanshani
zeshanshani / runFunctionMultipleTimes.js
Created August 24, 2016 04:54
Run a function multiple times until the element is found on the page
function runUACLCLoop() {
setTimeout(function() {
// Check if something is found on the page.
if ( jQuery('.class_name').is(':visible') ) { // change it to another condition
// Run the same function again to create the loop.
runUACLCLoop();
// If nothing is found, then run the else statement.
@zeshanshani
zeshanshani / fetchGoogleNewsItems.js
Created August 18, 2016 05:54
Fetch Google News items of the specified term and display them in an element.
/**
* Converts XML to JSON
* Source: https://davidwalsh.name/convert-xml-json
*/
function xmlToJson(xml) {
// Create the return object
var obj = {};
if (xml.nodeType == 1) { // element
@zeshanshani
zeshanshani / scrollToNextSection.css
Last active July 4, 2016 08:36
Click on the arrow to scroll to the next section to the banner.
/* Additional Styling */
#bottom-arrow {
position: absolute;
width: 52px; /* Width of arrow image */
height: 32px; /* Height of arrow image */
left: 50%;
margin-left: -26px; /* Horizontally centered, should be half of the 'width' */
background: url(path/to/arrow/file.png) no-repeat center center;
z-index: 10;
text-indent: -9999px; /* To visually hide the text inside the button */