Skip to content

Instantly share code, notes, and snippets.

View frentsel's full-sized avatar

Frentsel Alexandr frentsel

  • frentsel
  • Ukraine
View GitHub Profile
const CustomPromise = function(callback) {
const res = (fn, ...args) => fn && callOnce(fn, args);
const rej = (fn, ...args) => fn && callOnce(fn, args);
let callOnce = (fn, args) => {
fn.apply(null, args);
callOnce = () => { };
};
@frentsel
frentsel / jquery.fData.js
Last active July 27, 2018 12:04
Tiny jQuery plugin fData for works with form as a json object
$.fn.fData = function(_data) {
var $form = this;
if (!_data) {
return $form.serializeArray().reduce(function(obj, field) {
obj[field.name] = field.value;
return obj;
}, {});
}
@frentsel
frentsel / FileReader.js
Last active October 16, 2015 09:16
FileReader.js
<form enctype="multipart/form-data">
<input type="file" name="files" id="files" multiple onchange="File.set(this)">
</form>
var File = (function(){
var files = [],
set = function(obj){
for(var i in obj.files)
{
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
@frentsel
frentsel / super easy router.js
Last active November 29, 2015 13:54
router.js
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Router js</title>
</head>
<body>
<h1 id="title"><?=!empty($_GET['page']) ? strip_tags($_GET['page']) : 'Home';?></h1>
<ul>
<li><a onclick="Router.go('/'); return false;" href="/">Home</a></li>
@frentsel
frentsel / isMobile.js
Created September 14, 2015 15:25
isMobile.js
var isMobile = function(){
return /Mobi|Mini|Symbian|SAMSUNG|Nokia|BlackBerry|Series|Bada|SymbOS|PLAYSTATION/g
.test(navigator.userAgent.toString());
};
@frentsel
frentsel / Pattern Mediator.js
Last active February 10, 2017 05:56
Pattern Meditor
var player = {
play: function(music){
console.info('player plaing: ', music);
}
};
var search = {
items: {
a: 'ABBA',
b: 'Boney M',
@frentsel
frentsel / cookieClass.js
Created August 18, 2015 08:24
Cookie module
var _cookie = {
getCookie: function (name) {
var matches = document.cookie.match(new RegExp(
"(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)"
));
return matches ? decodeURIComponent(matches[1]) : undefined;
},
setCookie: function (name, value, options) {
options = options || {};
@frentsel
frentsel / Remove element from array.js
Last active August 29, 2015 14:27
Remove element from array
Array.prototype.remove = function(id){
return this.splice(id, 1);
}
var a = ["a","b","c","d"];
a.remove(2);
console.log(a);
// ["a", "b", "d"]
@frentsel
frentsel / Pattern module.js
Created August 5, 2015 07:51
Simple example of pattern "module" with import of extentions
var $scope = (function($){
var _this = {
name: 'Alex'
};
return {
get: function(prop){
return _this[prop];
},
set: function(prop, val){
return _this[prop] = val;