Skip to content

Instantly share code, notes, and snippets.

View kharmabum's full-sized avatar
💭
🧀

Juan-Carlos Foust kharmabum

💭
🧀
View GitHub Profile
@kharmabum
kharmabum / ember-resources.md
Last active December 19, 2015 12:09
Ember Resources
@kharmabum
kharmabum / show-html.js
Created July 16, 2013 00:31
Animates the dimensional changes resulting from altering element contents. Taken from Discourse source.
// Animates the dimensional changes resulting from altering element contents
// Usage examples:
// $("#myElement").showHtml("new HTML contents");
// $("div").showHtml("new HTML contents", 400);
// $(".className").showHtml("new HTML contents", 400,
// function() {/* on completion */});
(function($)
{
$.fn.showHtml = function(html, speed, callback)
{
@kharmabum
kharmabum / resource-navigation.html
Created July 16, 2013 22:50
URL resource navigation
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<meta http-equiv="refresh" content="1;url=htmlapps/">
<script type="text/javascript">
window.location.href = "htmlapps/"
</script>
<title>Page Redirection</title>
</head>
@kharmabum
kharmabum / accordion_view.js
Last active December 20, 2015 03:29
Ember view for Bootstrap collapse component
define(['main/config'], function (config) {
App.AccordionItemView = Ember.View.extend({
classNames: ['accordion-group'],
parentId: null,
parentRef: function() {
var hasGroupControl = this.get('parentView.hasGroupControl');
return (hasGroupControl) ? "#" + this.get('parentId') : "";
}.property('parentId'),
internalId: null,
@kharmabum
kharmabum / uniqueId.js
Created July 24, 2013 21:46
guid in javascript
uniqueId = function() {
return 'xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r, v;
r = Math.random() * 16 | 0;
v = c === 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
};
@kharmabum
kharmabum / key_value_store.js
Created July 24, 2013 21:46
HTML5 LocalStorage
/**
A simple key value store that uses LocalStorage
@class KeyValueStore
@namespace Discourse
@module Discourse
**/
Discourse.KeyValueStore = {
initialized: false,
context: "",
@kharmabum
kharmabum / emailValid.js
Created July 24, 2013 21:48
validate email address in javascript
emailValid: function(email) {
// see: http://stackoverflow.com/questions/46155/validate-email-address-in-javascript
var re;
re = /^[a-zA-Z0-9!#$%&'*+\/=?\^_`{|}~\-]+(?:\.[a-zA-Z0-9!#$%&'\*+\/=?\^_`{|}~\-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9\-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9\-]*[a-zA-Z0-9])?$/;
return re.test(email);
}
@kharmabum
kharmabum / selectedText.js
Created July 24, 2013 21:49
Get selected text from the browswer window
selectedText: function() {
var html = '';
if (typeof window.getSelection !== "undefined") {
var sel = window.getSelection();
if (sel.rangeCount) {
var container = document.createElement("div");
for (var i = 0, len = sel.rangeCount; i < len; ++i) {
container.appendChild(sel.getRangeAt(i).cloneContents());
}
@kharmabum
kharmabum / search.js.handlebars
Created July 27, 2013 22:09
search text field + results view. Discourse App.
{{view Discourse.SearchTextField valueBinding="term" searchContextBinding="searchContext"}}
{{#unless loading}}
{{#unless noResults}}
{{#each resultType in content}}
<ul>
<li class='heading'>
{{resultType.name}}
{{#if resultType.more}}
<a href='#' class='filter' {{action moreOfType resultType.type bubbles=false}}>{{i18n show_more}}</a>
{{else}}