Skip to content

Instantly share code, notes, and snippets.

View AlphaNerd's full-sized avatar
💭
Nerding as always

J.Coleman AlphaNerd

💭
Nerding as always
View GitHub Profile
@AlphaNerd
AlphaNerd / gist:48f6b1ff0f894d1ba5d3
Created April 1, 2015 19:17
Basic translation script for SimpleWeather.js - Translates to French once weather.currently is passed in to function.
var daysCast = 1;
jQuery.simpleWeather({
woeid: '2357536', //2357536
location: 'Shediac,NB',
unit: 'c',
success: function(weather) {
html = '<div id="an-todayImage"><img src="'+weather.forecast[0].image+'"/></div>';
html += '<div id="an-todayTemp" class="uk-width-small-1-2"><h1>'+weather.temp+'&deg;'+weather.units.temp+'</h1></div>';
html += '<div><ul style="padding-top:15px;padding-left:15px!important;"><li style="display:inline;margin-right:10px;"><b>'+weather.city+', '+weather.region+'</b><br></li>';
html += '<li style="display:inline;margin-right:10px;" class="currently">'+checkWXLang(weather.currently)+'</li>';
@AlphaNerd
AlphaNerd / Title Splitter
Created May 27, 2015 14:16
Basic jQuery function to split Joomla tittles into multiple <span>. Used for multi-colored titles in Joomla where first word is different color than rest. Simply supply selector, and adjust phrase split.
jQuery('.home #bottom_in h3').each(function(i,val){
var titleWords = val.innerHTML.split(" ");
var first = titleWords[0] + " ";
var second = "";
if (titleWords.length > 2){
for (i=1;i<titleWords.length;i++){
second += titleWords[i]+" ";
}
}else{
second = titleWords[1];
@AlphaNerd
AlphaNerd / gist:c43d1312ddde781edb25
Created May 27, 2015 18:14
Split phrase with jQuery and make first word different color. Then strip middle characters from date using substring().
///// ---------- DATE Split Color & Remove Middle Characters ---------- //////
jQuery('.mod_events_latest_date').each(function(i,val){
var wordArray = val.innerHTML.split(" ");
var string = wordArray[0];
var a = string.substring(0,1);
var b = string.substring(string.length-1,string.length);
var first = a += b;
var second = "";
if (wordArray.length > 2){
for (i=1;i<wordArray.length;i++){
@AlphaNerd
AlphaNerd / Header Image Swap
Created June 1, 2015 14:48
Basic header image swap script. Select target graphic and destination using CSS selectors.
var target = ".target div img";
var dest = "#header_img";
var link = jQuery(target).attr("src");
console.log(link);
jQuery(dest).css("backgroundImage","url('+link+')");
@AlphaNerd
AlphaNerd / CSS
Created June 1, 2015 14:51
Basic Google Map API integration into site. Developed to work with FlexiContent location data. Extract coordinates from GoogleMaps image link, extracting Lat and Long into an array, and then init map.
#map_canvas {
width: 400px;
height: 400px;
margin: 0 auto;
}
.info {
display:none;
}
@AlphaNerd
AlphaNerd / CSS
Created June 9, 2015 14:29
Canada OpenGov Dataset Consumption Example - Plot GPS coordinates on Google Maps.
body{
background:#fff;
}
#map{
height: 300px;
}
#legend{
width:100%;
padding:5px;
text-align:left;
@AlphaNerd
AlphaNerd / CSS
Created June 15, 2015 13:29
Basic JSON data api pull for creating mockup user lists.
.user-box{
margin:5px;
display:inline-block;
}
.user-image{
max-width:100px;
max-height:100px;
border-radius:100px;
overflow:hidden;
margin:5px;
@AlphaNerd
AlphaNerd / Disqus_Multi-language_Threads.js
Created July 28, 2015 13:56
Disqus API Mod: Force Joomla to pull one Disqus thread for both English and French associated content. Swaps DisqusEmnbed.js [src attr] after initial load.
setTimeout(function(){ //// Timeout required to grab iFrame info after Disqus load
var newURL = jQuery(".moduletable-lang a").attr("href");
var curURL = decodeURIComponent(jQuery("iframe").attr("src"));
var newTitle = "1211-new-brunswick-lagging-behind-other-parts-of-canada-on-wilderness-protection-cpaws-report";
if (jQuery("body").hasClass("fr-fr")){
createNewURL(newURL,newTitle,curURL); /// custome function to build new uri
}
},750);
function createNewURL(newURL,newTitle,curURL){
@AlphaNerd
AlphaNerd / HTML
Created November 18, 2015 01:46
Google Sheets JSON pull
<div id="results"></div>
@AlphaNerd
AlphaNerd / fetchData.php
Created January 17, 2016 03:03
Connect to Joomla Database from custom PHP file and respond with JSON data
<?php
define( '_JEXEC', 1 );
define('JPATH_BASE', '../../../');
require_once ( JPATH_BASE .'/includes/defines.php' );
require_once ( JPATH_BASE .'/includes/framework.php' );
$database = &JFactory::getDBO();
$sql = "SELECT * FROM `b7j6z_content` WHERE `state` = '1'"; // Select data from DB
$database->setQuery( $sql );
$result=$database->loadAssocList();