UNPKG

javascript-magic

Version:

Include Ray's JS Library

95 lines (75 loc) 2.01 kB
/*! * jQuery.Raymond * Copyright (c) 2015 Raymond Lewis Jones - me<a>raymondlewisjones<d>com | https://www.raymondlewisjones.com * Licensed under MIT * @projectDescription Ray's vMax jQuery Plugin. * @author Raymond Jones * @version 1.0.0 */ ;(function(plugin) { // AMD Support if (typeof define === 'function' && define.amd) { define(['jquery'], plugin); } else { plugin(jQuery); } }(function($) { window.sortvmax = function (a,b) { if (a.breakpoint < b.breakpoint) return -1; if (a.breakpoint > b.breakpoint) return 1; return 0; }; $.fn.vmax = function () { var width = $(window).width (); var height = $(window).height (); var max = height; if (width >= height) max = width; $("*[data-vmax]").each (function (i) { var target = $(this); var vmax = $(this).attr ("data-vmax"); vmax = vmax.split ("|"); var vmaxs = []; for (var ii=0;ii<vmax.length;ii++) { var temp = vmax [ii].split (","); var tmp = new Object; if (temp.length < 2) { tmp.breakpoint = 999999999; tmp.points = temp [0]; } else { tmp.breakpoint = temp [0]; tmp.points = temp [1]; } vmaxs.push (tmp); } vmaxs.sort (window.sortvmax); var pixels = 0; var points = 0; for (var ii=0;ii<vmaxs.length;ii++) { var temp = vmaxs [ii]; if (width <= temp.breakpoint) { pixels = (max * (temp.points * 1)) / 100; points = Math.round (((pixels * 6) / 8)); target.css ("font-size", points + "pt"); } } if (pixels == 0) { pixels = (max * (vmaxs [vmaxs.length - 1].points * 1)) / 100; points = Math.round (((pixels * 6) / 8)); target.css ("font-size", points + "pt"); } }); }; var $ray_vmax = $.ray_vmax = function () { return $.fn.vmax(); } $(function () { $.fn.vmax (); $(window).resize (function () { $.fn.vmax (); }); }); return $ray_vmax; }));