En cours

Convert jQuery plugin to plain javascript

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 [url removed, login to view]

/*

* Font UnStack 0.1

*

* Developed by Phil Oye

* Copyright (c) 2009 Phil Oye, [url removed, login to view]

*

* Licensed under the MIT license:

* [url removed, login to view]

*

*/

(function($) {

$.[url removed, login to view] = function(opts) {

$.[url removed, login to view](opts,this);

return this;

};

$.fontunstack = {

options: {

prefix: "set_in_"

},

init: function(opts, elems){

var elems = elems || "body";

$.extend([url removed, login to view], opts);

if( [url removed, login to view] == "") {

[url removed, login to view] = "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 = [url removed, login to view](/[^'",;\s][^'",;]*/g) || [];

}

[url removed, login to view](stack, elems);

},

analyzeStack: function(stack, elems) {

var generics = ["monospace", "sans-serif", "serif", "cursive", "fantasy"];

var baseline = generics[0];

var num_fonts = [url removed, login to view];

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)) {

[url removed, login to view](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 ($.[url removed, login to view](font, baseline)) {

// Remove any class that has our prefix to prevent doubles.

var re = new RegExp("\\b" + [url removed, login to view] + ".*?\\b","g");

$(elems).get(0).className = $(elems).get(0).[url removed, login to view](re, "");

// This should convert UTF8 to lowercase ANSI, removing all punctuation/spaces, but regexp scares me.

safe_font_name = encodeURIComponent( [url removed, login to view]( /[\s\-.!~*'()"]/g, "").toLowerCase() );

$(elems).addClass([url removed, login to view] + 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 = [url removed, login to view]();

[url removed, login to view]("font-family", requested_font + "," + baseline_font );

var requested_width = [url removed, login to view]();

[url removed, login to view]();

// If the dimensions change, the font is installed

return (requested_width != baseline_width);

}

};

})(jQuery);

// ### The initialization ###

$(document).ready(function() {

$("body").fontunstack();

})

Compétences : Javascript, jQuery / Prototype

Voir plus : jmodal plugin jquery, wordpress javascript pop plugin, invoking javascript firefox plugin, yahoo javascript video plugin, zoom plugin jquery, pro tools tdmrtas plugin vst convert, javascript checking resolution jquery, wordpress javascript popup plugin, javascript text editor jquery, javascript screen height jquery, firefox cut paste javascript page plugin, image javascript popup plugin, javascript photo album jquery, javascript font resize jquery, javascript editor plugin

Concernant l'employeur :
( 1 commentaire ) Copenhagen, Denmark

N° du projet : #12718070

Décerné à :

261 € EUR en 10 jours
(134 Commentaires)
6.2

7 freelance ont fait une offre moyenne de 511 € pour ce travail

romanapanovich

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

333 € EUR en 1 jour
(8 Commentaires)
4.0
mmadi

Dear Client, Greetings from Flowgica technologies, I have experience with these skills. We do have similar experience doing something similar to yours therefore I am looking forward to discuss and move ahead. Our late Plus

525 € EUR en 12 jours
(5 Commentaires)
3.5
erskywebsolution

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

666 € EUR en 3 jours
(8 Commentaires)
2.5
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 Plus

638 € EUR en 10 jours
(0 Commentaires)
0.0
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 Plus

722 € EUR en 20 jours
(0 Commentaires)
0.0
rajubera3

Hi, Greetings from Aponiar Solution Private Limited. ([url removed, login to view]) I take the privilege to introduce myself as a Sr. Full Stack Developer with 5 years of experience. I have a good amount of exposure in workin Plus

433 € EUR en 10 jours
(0 Commentaires)
0.0