Skip to content

Instantly share code, notes, and snippets.

View ionurboz's full-sized avatar

Onur ionurboz

View GitHub Profile
@ionurboz
ionurboz / jQuery.UTF-8.js
Created May 3, 2018 22:51 — forked from lucasmezencio/jQuery.UTF-8.js
A way to manipulate UTF-8 strings in jQuery.
;(function($, undefined) {
$.extend({
toUTF8 : function(text) {
text = text.replace(/\r\n/g,"\n");
var output = [];
for (var n = 0 ; n < text.length ; n++) {
var c = text.charCodeAt(n);
@ionurboz
ionurboz / jQuery.limit.js
Created May 3, 2018 22:52 — forked from lucasmezencio/jQuery.limit.js
jQuery 'limit' plugin for textarea
;(function ($) {
$.fn.limit = function (options) {
var defaults = {
limit : 200,
result : false,
alertClass : false
}, options = $.extend(defaults, options);
return this.each(function () {
var characters = options.limit;
@ionurboz
ionurboz / turkish-capitalize-words.js
Created May 4, 2018 16:20 — forked from anova/turkish-capitalize-words.js
Capitalize, lowercase, uppercase for Turkish alphabet.
//http://stackoverflow.com/a/1026087/181295
String.prototype.turkishUpperCase = function () {
return this.replace(/ğ/g, 'Ğ')
.replace(/ü/g, 'Ü')
.replace(/ş/g, 'Ş')
.replace(/ı/g, 'I')
.replace(/i/g, 'İ')
.replace(/ö/g, 'Ö')
.replace(/ç/g, 'Ç')
.toUpperCase();
var string_to_slug = function (str)
{
str = str.replace(/^\s+|\s+$/g, ''); // trim
str = str.toLowerCase();
// remove accents, swap ñ for n, etc
var from = "àáäâèéëêìíïîıòóöôùúüûñçşğ·/_,:;";
var to = "aaaaeeeeiiiiioooouuuuncsg------";
for (var i=0, l=from.length ; i<l ; i++)
@ionurboz
ionurboz / bbcode.php
Created May 9, 2018 22:19 — forked from neo22s/bbcode.php
BBcode parser example
<?php
/**
* BBcode helper class
*
* @package BBcode
* @category Helper
* @author Chema <chema@garridodiaz.com>
* @copyright (c) 2012
* @license GPL v3
*/
@ionurboz
ionurboz / strToHtml.js
Created March 18, 2019 13:17
String to Html (Pure JS)
/**
* Convert a template string into HTML DOM nodes
* @param {String} str The template string
* @return {Node} The template HTML
*/
var stringToHTML = function (str) {
parser = parser || new DOMParser();
var doc = parser.parseFromString(str, 'text/html');
return doc.body;
};
@ionurboz
ionurboz / clone.js
Created March 18, 2019 13:19
Clone Object (Pure JS)
/**
* Return a clone of an object or array
* @param {Object|Array} obj The object or array to clone
* @return {Object|Array} An exact copy of the object or array
*/
var clone = function (obj) {
if (!obj) return;
return JSON.parse(JSON.stringify(obj));
};
@ionurboz
ionurboz / trueTypeOf.js
Created March 18, 2019 13:21
More accurately check the type of a JavaScript object
/**
* More accurately check the type of a JavaScript object
* @param {Object} obj The object
* @return {String} The object type
*/
var trueTypeOf = function (obj) {
return Object.prototype.toString.call(obj).slice(8, -1).toLowerCase();
};
@ionurboz
ionurboz / supports.js
Created March 18, 2019 13:22
Check feature support (Pure JS)
/**
* Check feature support
*/
var supports = function () {
if (!window.DOMParser) return false;
parser = parser || new DOMParser();
try {
parser.parseFromString('x', 'text/html');
} catch(err) {
return false;
@ionurboz
ionurboz / find.js
Created March 18, 2019 13:24
Find the first matching item in an array
/**
* Find the first matching item in an array
* @param {Array} arr The array to search in
* @param {Function} callback The callback to run to find a match
* @return {*} The matching item
*/
var find = function (arr, callback) {
var matches = arr.filter(callback);
if (matches.length < 1) return null;
return matches[0];