Convert jQuery plugin to plain javascript

In Progress Posted 7 years ago Paid on delivery
In Progress Paid on delivery

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();

})

JavaScript jQuery / Prototype

Project ID: #12718070

About the project

6 proposals Remote project Active 7 years ago

6 freelancers are bidding on average €553 for this job

romanapanovich

I can do it in few hours thanks ------------------------------------------------------------------------------------------------------

€333 EUR in 1 day
(13 Reviews)
4.8
erskywebsolution

we have Very good experience developer we will finished your task as soon as possible

€666 EUR in 3 days
(11 Reviews)
3.1
priyas171

Dear Project Owner, Greetings for the day! Thank you for reviewing my bid. I have gone through the details and will get it done quite comfortably. We have huge experience of working on JQuery and JavaS More

€722 EUR in 20 days
(5 Reviews)
3.3
webnetpiyush

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 More

€638 EUR in 10 days
(0 Reviews)
0.0