Skip to content

Instantly share code, notes, and snippets.

View ali-master's full-sized avatar
🎯
Focusing on Something new!

Ali Torki ali-master

🎯
Focusing on Something new!
View GitHub Profile
@ali-master
ali-master / timeSpanUpdater.md
Last active December 28, 2016 11:00
TimeSpanUpdater[timeago] with jQuery

TimeSpanUpdater[timeago] with jQuery

function TimeSpanUpdater(id, interval) {
    var updater = function () {
        var _this = this;
        this.interval = interval ? interval : 20000;
        this.registeredItemsArr = [];
        this.registerItem = function (element) {
            if (element && element.attr('data-timespan')) {
@ali-master
ali-master / processText.md
Last active December 27, 2016 00:15
Process Text for find and create an anchor link for each of texts link

Process Text for find and create an anchor link for each of texts link

var processText = function (text) {
    var txt = (text || '').replace(/(http(s)?:\/\/[^\s]+)/gi, '<a class="link" href="$1" target="_blank">$1</a>').replace(/\r\n/g, '<br />').replace(/\n/g, '<br />');
    return txt;
};

### Usage
processText(document.body)
@ali-master
ali-master / playNewMessageSound.md
Created December 27, 2016 00:15
Play new Message Sound

Play new Message Sound

function playNewMessageSound(src) {
	if(!src || typeof src !== "string") return;

    var audio = document.createElement('audio');
    if (audio) {
        audio.src = src;
 audio.autoplay = true;
@ali-master
ali-master / isEventSupported.md
Created December 28, 2016 13:06
Detecting Browser Event Support

Detecting Browser Event Support

var isEventSupported = function (eventName) {
    var TAGNAMES = { 'select': 'input', 'change': 'input', 'submit': 'form', 'reset': 'form', 'error': 'img', 'load': 'img', 'abort': 'img' }
    var el = document.createElement(TAGNAMES[eventName] || 'div');
    eventName = 'on' + eventName;
    var isSupported = (eventName in el);
    if (!isSupported) {
        el.setAttribute(eventName, 'return');
 isSupported = typeof el[eventName] == 'function';
@ali-master
ali-master / browserInfo.md
Last active January 4, 2017 09:38
Information About Client web Browser

Information About Client web Browser

var browserInfo = function () {
    var ua = navigator.userAgent.toLowerCase();
    var matchs = ua.match(/(opera)\/([\d\.]+)/i) || ua.match(/(msie) ([\d\.]+)/i) || ua.match(/(firefox)\/([\d\.]+)/i) || ua.match(/(chrome)\/([\d\.]+)/i) || ua.match(/(safari)\/([\d\.]+)/i) || [];
    return {
        name: matchs[1] || 'unknown',
        version: matchs[2] || 'unknown',
 isTouch: 'ontouchend' in document
@ali-master
ali-master / jquery.preparetransition.js
Created December 28, 2016 13:56 — forked from jlong/jquery.preparetransition.js
A new version of $(el).prepareTransition() that uses a timer instead of the poorly implemented TransitionEnd event to ensure that the 'is-transitioning' class is removed.
/**
* prepareTransition
*
* jQuery Plugin for ensuring transitions with display:none or visibility:hidden
* are in the right state until the end of the transition
*
* By John W. Long (http://wiseheartdesign.com)
* April 18, 2013
*
* Based on the prepareTransition plugin by Jonathan Snook (http://snook.ca). This version
@ali-master
ali-master / getBackgroundColor.md
Created December 29, 2016 01:10
Get Background-Color of Elements with jQuery

Get Background-Color of Elements with jQuery

(function($){
    $.fn.getBackgroundColor = function() {
        var self = $(this);
        var bgColor = "";
        while(self.prop("tagName").toLowerCase() != "html") {
            bgColor = self.css("background-color");
 if(bgColor != "rgba(0, 0, 0, 0)" &amp;&amp; bgColor != "transparent") {
@ali-master
ali-master / addCSS.md
Created December 31, 2016 16:50
Add CSS File To DOM

Add CSS File To DOM

function addCss(data) {
    (function (e) {
        e.setAttribute("rel",  "stylesheet");
        e.setAttribute("type", "text/css");
        e.setAttribute("id",   data.id);
        e.setAttribute("media", "all");
 e.setAttribute("href", data.src);
@ali-master
ali-master / addJS.md
Created December 31, 2016 16:52
Add JS File To DOM

Add JS File To DOM

function addJS(data) {
    (function (e) {
        e.setAttribute("src", data.src);
        e.setAttribute("id", data.id);
        
        document.getElementsByTagName("body")[0].appendChild(e);
 })(document.createElement("script"));
@ali-master
ali-master / uniqArray.md
Created January 4, 2017 09:35
JavaScript Array Unique Item

JavaScript Array Unique Item

// ES6
const uniq = (userArray) => {
  const unique = {};
  userArray.forEach((unusedValue, index) => { unique[userArray[index]] = true; });
  return Object.keys(unique);
};