Convert jQuery plugin to plain javascript
€250-750 EUR
Pago na entrega
Hi,
I need some quick help with a jQuery + javascript task:
Essential: I want to convert the attached jQuery plugin—as well as its initialization on an HTML page—into plain javascript. I am not using jQuery for anything else on the page, so I want to reduce the weight of the code base by being able to not use jQuery at all.
Optional: If it can speed up running the script, then I need the script to be adjusted to simply check for 3 specific fonts, that should be defined in an array in the script: "Lucida Sans", "Lucida Grande", "Lucida Sans Unicode", rather than checking all the fonts in the font-family (which I believe it does now).
Optional: If there is any other way to optimize the time it takes for the script to run (before the page is shown), that would be appreciated as well.
Can someone help with this?
Thank you,
// ### The jQuery Plugin ###
// See documentation on [login to view URL]
/*
* Font UnStack 0.1
*
* Developed by Phil Oye
* Copyright (c) 2009 Phil Oye, [login to view URL]
*
* Licensed under the MIT license:
* [login to view URL]
*
*/
(function($) {
$.[login to view URL] = function(opts) {
$.[login to view URL](opts,this);
return this;
};
$.fontunstack = {
options: {
prefix: "set_in_"
},
init: function(opts, elems){
var elems = elems || "body";
$.extend([login to view URL], opts);
if( [login to view URL] == "") {
[login to view URL] = "set_in_";
}
var stack = $(elems).css('font-family');
// If a css-style font-family declaration (string) passed in, convert to array
if (typeof stack == "string") {
stack = [login to view URL](/[^'",;\s][^'",;]*/g) || [];
}
[login to view URL](stack, elems);
},
analyzeStack: function(stack, elems) {
var generics = ["monospace", "sans-serif", "serif", "cursive", "fantasy"];
var baseline = generics[0];
var num_fonts = [login to view URL];
var last_resort = stack[num_fonts -1];
// If author hasn't included a generic (tsk, tsk), let's add one
if ($.inArray(last_resort, generics)) {
[login to view URL](baseline);
num_fonts++;
}
// If the generic is the same as our baseline, let's use another.
if (last_resort == baseline) {
baseline = generics[1];
};
// At this point we're sure there is a generic fallback font, so we'll only iterate though the non-generics.
for (var i=0; i<num_fonts -1; i++) {
font = stack[i];
if ($.[login to view URL](font, baseline)) {
// Remove any class that has our prefix to prevent doubles.
var re = new RegExp("\\b" + [login to view URL] + ".*?\\b","g");
$(elems).get(0).className = $(elems).get(0).[login to view URL](re, "");
// This should convert UTF8 to lowercase ANSI, removing all punctuation/spaces, but regexp scares me.
safe_font_name = encodeURIComponent( [login to view URL]( /[\s\-.!~*'()"]/g, "").toLowerCase() );
$(elems).addClass([login to view URL] + safe_font_name);
break; //We only want to find one installed font per stack.
}
}
},
testFont: function(requested_font, baseline_font) {
var span = $('<span id="font_tester" style="font-family:' + baseline_font + '; font-size:144px;position:absolute;left:-10000px;top:-10000px;visibility:hidden;">mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmml</span>');
$("body").prepend(span);
var baseline_width = [login to view URL]();
[login to view URL]("font-family", requested_font + "," + baseline_font );
var requested_width = [login to view URL]();
[login to view URL]();
// If the dimensions change, the font is installed
return (requested_width != baseline_width);
}
};
})(jQuery);
// ### The initialization ###
$(document).ready(function() {
$("body").fontunstack();
})
ID do Projeto: #12718070
Sobre o projeto
6 freelancers estão ofertando em média €553 nesse trabalho
I can do it in few hours thanks ------------------------------------------------------------------------------------------------------
we have Very good experience developer we will finished your task as soon as possible
Hello, Greetings of the day With a tremendous experience of 3 years after serving the industry in various domains, Mobile App Development Company has achieved many milestones on it success path. Our expertise not Mais