Skip to content

Instantly share code, notes, and snippets.

View faridv's full-sized avatar
😐
‌Dealing with challenges like this -> :|

Farid Rn faridv

😐
‌Dealing with challenges like this -> :|
View GitHub Profile
@faridv
faridv / serializeobject.js
Created July 27, 2017 08:34
jQuery plugin to serialize form as an object (also using underscore.js)
"use strict";
$.fn.serializeObject = function () {
var arr = this.serializeArray();
return _.reduce(arr, function (memo, f) {
var objField = _.reduceRight(f.name.replace(/\[/g, ".").replace(/\]/g, "").split("."), function (memo, p) {
var n = (/^[0-9]+$/.test(p)) ? [] : {};
n[p] = memo;
return n;
}, f.value);
@faridv
faridv / serializeobject.js
Last active July 27, 2017 08:34
jQuery plugin to serialize form as an object
// Serialize Object Plugin
"use strict";
$.fn.serializeObject = function () {
var o = {};
var a = this.serializeArray(); // serializeArray - serialize form as an array instead of default object
$.each(a, function () {
if (o[this.name] !== undefined) {
if (!o[this.name].push) {
o[this.name] = [o[this.name]];
}
@faridv
faridv / last-word.js
Created October 31, 2015 12:42 — forked from ramseyp/last-word.js
Select the last word in an element & wrap it with a span tag
jQuery(document).ready(function($){
$('h2.title').html(function(){
// separate the text by spaces
var text= $(this).text().split(' ');
// drop the last word and store it in a variable
var last = text.pop();
// join the text back and if it has more than 1 word add the span tag
// to the last word
return text.join(" ") + (text.length > 0 ? ' <span class="last">'+last+'</span>' : last);