Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 19th, 2012  |  syntax: None  |  size: 11.10 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. /*
  2.  * Release: 1.3.1 2009-04-26
  3.  */
  4. /*
  5.  * Copyright (c) Andr?e Hansson (peolanha AT gmail DOT com)
  6.  * MIT License - http://www.opensource.org/licenses/mit-license.php
  7.  * Idea loosely based on JASH, http://billyreisinger.com/jash/
  8.  *
  9.  * Website: http://gridder.andreehansson.se/
  10.  *
  11.  * Changelog:
  12.  * - New GUI! The new GUI should be less obtrusive and has been repositioned.
  13.  *   It is also featuring a slight delay on inputs so that you'll have a chance
  14.  *   to change the settings before it is re-rendering the grid
  15.  * - Due to a lot of inquries regarding affiliation with jQuery the filenames has
  16.  *   been changed, I'm very sorry for the inconvenience!
  17.  * - CSS issues with the GUI should also be fixed in more websites, please report
  18.  *   in any issue you stumble upon
  19.  * - A small bug in IE that made the paragraph lines not position correctly has been
  20.  *   fixed
  21.  * - A dropdown box has replaced the columns input box, 960 Gridder calculates the
  22.  *   proper number of columns that can be used with the specified grid width
  23.  * - The 960 Gridder is now displaying perfectly (into the very pixels) in all
  24.  *   A-grade browsers (according to browsershots.org)
  25.  * - An option to invert the gutters has been added, set this to 'true' if
  26.  *   you want to use it, OR use the shortcut CTRL+ALT+A
  27.  * - Some other minor changes...
  28.  */
  29. function Grid() {
  30.         var c = this;
  31.         c.settingsDef = {urlBase:"http://gridder.andreehansson.se/releases/1.3.1/", gColor:"#EEEEEE", gColumns:12, gOpacity:0.45, gWidth:10, pColor:"#C0C0C0", pHeight:15, pOffset:0, pOpacity:0.55, center:true, invert:false, gEnabled:true, pEnabled:true, size:960, fixFlash:true, setupEnabled:true, pressedKeys:[], delayTimer:""};
  32.         c.settings = (typeof(window.gOverride) === "undefined") ? {} : window.gOverride;
  33.         for (var a in c.settingsDef) {
  34.                 if (typeof(c.settings[a]) === "undefined") {
  35.                         c.settings[a] = c.settingsDef[a];
  36.                 }
  37.         }
  38.         if (typeof(window.jQuery) === "undefined" || jQuery().jquery.match(/^1\.3/) === null) {
  39.                 window.jQuery = undefined;
  40.                 var b = document.createElement("script");
  41.                 b.type = "text/javascript";
  42.                 b.src = c.settings.urlBase + "jquery.js";
  43.                 document.body.appendChild(b);
  44.         }
  45.         c._createEntity = function (e, d) {
  46.                 jQuery('<div class="g-' + e + '">&nbsp;</div>').appendTo("#g-grid").css(d);
  47.         };
  48.         c._setVariable = function (d, e) {
  49.                 d = d.replace(/g-setup-/, "");
  50.                 if (isNaN(parseInt(e, 10)) || parseInt(e, 10) === 0) {
  51.                         c.settings[d] = e;
  52.                 } else {
  53.                         c.settings[d] = parseInt(e, 10);
  54.                 }
  55.                 if (e === true) {
  56.                         jQuery("#g-setup-" + d).attr("checked", "checked");
  57.                 } else {
  58.                         if (e === false) {
  59.                                 jQuery("#g-setup-" + d).removeAttr("checked");
  60.                         } else {
  61.                                 jQuery("#g-setup-" + d).val(e);
  62.                         }
  63.                 }
  64.         };
  65.         c.setupWindow = function () {
  66.                 jQuery('<style type"text/css">#g-setup{position:absolute;top:150px;left:-310px;padding:6px;margin:0;list-style:none;width:320px!important;background-color:#d1cfe6;border:2px solid #a19bd1;z-index:2100;}#g-setup *{background:transparent!important;border:0!important;color:#58517c!important;font-family:Verdana,Geneva,sans-serif!important;font-size:10px!important;font-weight:normal!important;letter-spacing:normal!important;line-height:1!important;list-style-type:none!important;margin:0!important;padding:0!important;text-decoration:none!important;text-indent:0!important;text-transform:none!important;word-spacing:0!important;z-index:2100!important;}#g-setup .head{font-weight:bold!important;text-align:center;border-bottom:1px solid #7cb267!important;}#g-setup ul{width:150px;float:left!important;}#g-setup li{clear:left;padding:5px!important;}* html #g-setup li{clear:none!important;padding:4px!important;}#g-setup span{float:left!important;width:50px;padding:1px 4px 0 0!important;text-align:right!important;line-height:1.5!important;}#g-setup input,#g-setup select{float:left!important;width:70px;border:1px solid #a19bd1!important;background-color:#e7e6ee!important;padding:2px!important;}#g-setup select{width:77px;padding:0!important;}#g-setup-misc{margin-top:5px!important;clear:left;float:none!important;width:300px!important;border-top:1px solid #7cb267!important;}#g-setup-misc span{line-height:1.1!important;width:200px;}#g-setup-misc input{width:15px;padding:0!important;height:15px;}#g-setup-tab{width:26px;overflow:hidden;position:absolute;top:0;left:100%;margin-left:-26px!important;z-index:2100!important;}#g-setup-tab img{left:0;position:relative;}#g-grid{left:0;position:absolute;z-index:500;top:0;pointer-events:none;}#g-grid .g-vertical,#g-grid .g-horizontal{position:absolute;z-index:1000;pointer-events:none;}*:first-child+html #g-grid .g-horizontal,*:first-child+html #g-grid .g-vertical{margin-left:-1px;}#g-grid .g-horizontal{min-height:1px;height:1px;font-size:0;line-height:0;}</style>').appendTo("head");
  67.                 c.settings.height = jQuery(document).height();
  68.                 if (c.settings.setupEnabled) {
  69.                         jQuery('<div id="g-setup"><ul><li class="head">Vertical</li><li><span>Color</span><input id="g-setup-gColor" /></li><li><span>Opacity</span><input id="g-setup-gOpacity" /></li><li><span>Width</span><input id="g-setup-gWidth" /></li><li><span>Columns</span><select id="g-setup-gColumns"></select></li></ul><ul><li class="head">Horizontal</li><li><span>Color</span><input id="g-setup-pColor" /></li><li><span>Opacity</span><input id="g-setup-pOpacity" /></li><li><span>Height</span><input id="g-setup-pHeight" /></li><li><span>Offset</span><input id="g-setup-pOffset" /></li></ul><ul id="g-setup-misc"><li><span>Enable vertical (gutters)</span><input id="g-setup-gEnabled" type="checkbox" /></li><li><span>Enable horizontal (paragraphs)</span><input id="g-setup-pEnabled" type="checkbox" /></li><li><span>Invert vertical</span><input id="g-setup-invert" type="checkbox" /></li><li><span>Center grid</span><input id="g-setup-center" type="checkbox" /></li></ul><div style="clear: left;"></div><div id="g-setup-tab"><a href="javascript:;"><img src="http://gridder.andreehansson.se/releases/1.3.1/logo-sprite.png" alt="" /></a></div></div>').appendTo("body");
  70.                         for (var d = 2; d < 48; d++) {
  71.                                 if (Math.round((c.settings.size / d)) === (c.settings.size / d)) {
  72.                                         jQuery('<option value="' + d + '">' + d + "</option>").appendTo("#g-setup-gColumns");
  73.                                 }
  74.                         }
  75.                         for (var d in c.settings) {
  76.                                 if (jQuery("#g-setup-" + d).length !== 0) {
  77.                                         if (jQuery("#g-setup-" + d).parent().parent().is("#g-setup-misc") && c.settings[d]) {
  78.                                                 jQuery("#g-setup-" + d).attr("checked", "checked");
  79.                                         } else {
  80.                                                 jQuery("#g-setup-" + d).val(c.settings[d]);
  81.                                         }
  82.                                 }
  83.                         }
  84.                         jQuery("#g-setup").css("top", jQuery(window).scrollTop() + 150);
  85.                         jQuery("#g-setup-tab a").click(function () {
  86.                                 c.toggleSetupWindow();
  87.                         });
  88.                         jQuery("#g-setup input").keyup(function () {
  89.                                 var e = this;
  90.                                 clearTimeout(c.settings.delayTimer);
  91.                                 c.settings.delayTimer = setTimeout(function () {
  92.                                         c.setVariable(jQuery(e).attr("id"), jQuery(e).val());
  93.                                 }, 700);
  94.                         });
  95.                         jQuery("#g-setup-gColumns").change(function () {
  96.                                 c.setVariable("gColumns", $(this).val());
  97.                         });
  98.                         jQuery("#g-setup-misc input").click(function () {
  99.                                 c.setVariable(jQuery(this).attr("id"), jQuery(this).attr("checked"));
  100.                         });
  101.                         jQuery().keydown(function (f) {
  102.                                 if (jQuery.inArray(f.which, c.settings.pressedKeys) === -1) {
  103.                                         c.settings.pressedKeys.push(f.which);
  104.                                 }
  105.                         });
  106.                         jQuery(window).scroll(function () {
  107.                                 jQuery("#g-setup").css("top", jQuery().scrollTop() + 150);
  108.                         });
  109.                 }
  110.                 jQuery().keyup(function (g) {
  111.                         if (jQuery.inArray(17, c.settings.pressedKeys) !== -1 && jQuery.inArray(18,
  112.                                 c.settings.pressedKeys) !== -1) {
  113.                                 if (jQuery.inArray(90, c.settings.pressedKeys) !== -1) {
  114.                                         c.setVariable("gEnabled", !c.settings.gEnabled);
  115.                                 } else {
  116.                                         if (jQuery.inArray(88, c.settings.pressedKeys) !== -1) {
  117.                                                 c.setVariable("pEnabled", !c.settings.pEnabled);
  118.                                         } else {
  119.                                                 if (jQuery.inArray(65, c.settings.pressedKeys) !== -1) {
  120.                                                         c.setVariable("invert", !c.settings.invert);
  121.                                                 } else {
  122.                                                         if (jQuery.inArray(67, c.settings.pressedKeys) !== -1) {
  123.                                                                 c.setVariable({gEnabled:!c.settings.gEnabled, pEnabled:!c.settings.pEnabled});
  124.                                                         }
  125.                                                 }
  126.                                         }
  127.                                 }
  128.                         }
  129.                         var f = jQuery.inArray(g.which, c.settings.pressedKeys);
  130.                         c.settings.pressedKeys.splice(f, f);
  131.                 });
  132.         };
  133.         c.setVariable = function () {
  134.                 if (typeof(arguments[0]) === "object") {
  135.                         for (var d in arguments[0]) {
  136.                                 c._setVariable(d, arguments[0][d]);
  137.                         }
  138.                 } else {
  139.                         c._setVariable(arguments[0], arguments[1]);
  140.                 }
  141.                 c.createGrid();
  142.         };
  143.         c.toggleSetupWindow = function () {
  144.                 var d = jQuery("#g-setup-tab img");
  145.                 d.css("left", d.position().left === 0 ? -26 : 0);
  146.                 if (parseInt(jQuery("#g-setup").css("left"), 10) === 0) {
  147.                         jQuery("#g-setup").animate({left:-310}, 200);
  148.                 } else {
  149.                         jQuery("#g-setup").animate({left:0}, 200);
  150.                 }
  151.         };
  152.         c.createGrid = function () {
  153.                 jQuery("embed").each(function () {
  154.                         if (c.settings.fixFlash) {
  155.                                 jQuery(this).attr("wmode", "transparent");
  156.                         } else {
  157.                                 jQuery(this).removeAttr("wmode");
  158.                         }
  159.                         var i = jQuery(this).wrap("<div></div>").parent().html();
  160.                         jQuery(this).parent().replaceWith(i);
  161.                         jQuery(this).remove();
  162.                 });
  163.                 jQuery("#g-grid").remove();
  164.                 jQuery('<div id="g-grid"></div>').appendTo("body").css("width", c.settings.size);
  165.                 if (c.settings.center) {
  166.                         jQuery("#g-grid").css({left:"50%", marginLeft:-((c.settings.size / 2) + c.settings.gWidth)});
  167.                 }
  168.                 if (c.settings.gEnabled && c.settings.gColumns > 0) {
  169.                         if (c.settings.invert) {
  170.                                 jQuery().css("overflow-x", "hidden");
  171.                                 var e = (jQuery(window).width() - c.settings.size) / 2;
  172.                                 c._createEntity("vertical",
  173.                                         {left:-e, width:e, height:c.settings.height, backgroundColor:c.settings.gColor, opacity:c.settings.gOpacity});
  174.                                 for (var g = 0; g < c.settings.gColumns; g++) {
  175.                                         var f = (c.settings.size / c.settings.gColumns) - (c.settings.gWidth * 2);
  176.                                         var h = (c.settings.gWidth * 2);
  177.                                         c._createEntity("vertical",
  178.                                                 {left:((f + h) * g) + h, width:f + "px", height:c.settings.height, backgroundColor:c.settings.gColor, opacity:c.settings.gOpacity});
  179.                                 }
  180.                                 if ((c.settings.height + 10) > jQuery(window).height()) {
  181.                                         e -= 10;
  182.                                 }
  183.                                 c._createEntity("vertical",
  184.                                         {left:"100%", marginLeft:20, width:e, height:c.settings.height, backgroundColor:c.settings.gColor, opacity:c.settings.gOpacity});
  185.                         } else {
  186.                                 for (var g = 0; g <= c.settings.gColumns; g++) {
  187.                                         c._createEntity("vertical",
  188.                                                 {left:((c.settings.size / c.settings.gColumns) * g), width:(c.settings.gWidth * 2), height:c.settings.height, backgroundColor:c.settings.gColor, opacity:c.settings.gOpacity});
  189.                                 }
  190.                         }
  191.                 }
  192.                 if (c.settings.pEnabled && c.settings.pHeight > 1) {
  193.                         var d = ((c.settings.height - c.settings.pOffset) / c.settings.pHeight);
  194.                         for (g = 0; g <= d; g++) {
  195.                                 c._createEntity("horizontal",
  196.                                         {top:((c.settings.height / d) * g) + c.settings.pOffset, left:"50%", marginLeft:-(c.settings.size / 2), width:(c.settings.size + (c.settings.gWidth * 2)), backgroundColor:c.settings.pColor, opacity:c.settings.pOpacity});
  197.                         }
  198.                 }
  199.         };
  200. }
  201. var checkJQuery = function () {
  202.         if (typeof(window.jQuery) === "undefined") {
  203.                 setTimeout(function () {
  204.                         checkJQuery();
  205.                 }, 10);
  206.         } else {
  207.                 window.grid.setupWindow();
  208.                 window.grid.createGrid();
  209.         }
  210. };
  211. if (typeof(window.grid) === "undefined") {
  212.         window.grid = new Grid();
  213.         checkJQuery();
  214. } else {
  215.         window.grid.toggleSetupWindow();
  216. }