app/views/cytoplasm/fonts/index.html.erb in cytoplasm-0.1.5 vs app/views/cytoplasm/fonts/index.html.erb in cytoplasm-0.1.6

- old
+ new

@@ -2,173 +2,19 @@ <hr /> <% if @enabled["fontsquirrel"].any? or @enabled["googlewebfonts"].any? %> <h3>Enabled Fonts</h3> - <p>These fonts are loaded at runtime. Remember: <b>less is more!</b> Enabling lots of fonts can slow page loading times and clutter up layouts.</p> - - <% {"fontsquirrel" => "FontSquirrel","googlewebfonts" => "Google Web Fonts"}.each do |dir,name| %> - <% if @enabled[dir].any? %> - <h6><%=name%></h6> - <ul> - <% @enabled[dir].each do |fam,f| %> - <%=render :partial => 'font_li', :locals => {:fam => fam, :f => f, :dir => dir} %> - <% end %> - </ul> - <% end %> - <% end %> - + <p>The following fonts are being loaded into every page of your site. To use them, simply add a font-family CSS rule referencing the <b>CSS Name</b> to any element.</p> + <p><b>Remember: less is more!</b> Loading tons of fonts can severely affect page load times, and using more than a few at a time is widely considered poor design practice anyway. It is recommended that you simply disable any fonts that you aren't using.</p> + <%=render :partial => 'list', :object => @enabled %> <hr /> <% end %> <% if @installed["fontsquirrel"].any? or @installed["googlewebfonts"].any? %> <h3>Installed Fonts</h3> <p>This includes all fonts that are currently installed into this Cytoplasm project.</p> - - <% {"fontsquirrel" => "FontSquirrel","googlewebfonts" => "Google Web Fonts"}.each do |dir,name| %> - <% if @installed[dir].any? %> - <h6><%=name%></h6> - <ul> - <% @installed[dir].each do |fam,f| %> - <%=render :partial => 'font_li', :locals => {:fam => fam, :f => f, :dir => dir} %> - <% end %> - </ul> - <% end %> - <% end %> - + <%=render :partial => 'list', :object => @installed %> <hr /> <% end %> -<h3>Install New Fonts</h3> - -<p> - <input type="radio" name="fonts_directory" data-label="Font Squirrel API" value="fontsquirrel" data-exclude="true" checked="checked" class="cytoRadio" /> - <input type="radio" name="fonts_directory" data-label="Google Web Fonts" value="googlewebfonts" data-exclude="true" /> -</p> -<p><select name="fonts_family" id="fontfamilyselect" data-exclude="true" class="cytoSelect"></select></p> -<p><input type="checkbox" id="font_import_autoenable" data-exclude="true" checked="checked" /> Automatically enable this font after installing</p> -<p><button id="font_import_button" class="cytoButton large">Install Font Family</button></p> - -<script type="text/javascript"> -(function($){ - $.Cytoplasm("ready",function(){ - $.cytoAjax("/cytoplasm/fonts/fetch_all",function(data){ - var fds = $('input[name=fonts_directory]'); - var ffs = $('#fontfamilyselect'); - var iae = $('#font_import_autoenable'); - var ib = $('#font_import_button'); - - // Directory select - fds.cytoRadio("options",{ - events:{ - change:$.debounce(100,true,function(e){ - var fonts = {}; - var imported = {}; - switch ($(this).cytoRadio("value")) { - case "fontsquirrel": - $.each(data.fontsquirrel,function(fam,f){fonts[fam] = f.family_name;}); - if (data.imported.length>0) { - $.each(data.imported,function(fam,f){imported[fam] = fam;}); - iffs.cytoSelect("update",imported); - } - break; - case "googlewebfonts": - $.each(data.googlewebfonts,function(fam,f){fonts[fam] = fam;}); - break; - default:return false; - } - ffs.cytoSelect("update",fonts); - }) - } - }); - - // Family select - ffs.cytoSelect("options",{ - events:{ - change:function(cy,e){ - var dir = fds.cytoRadio("value"); - var f = data[dir][$(this).cytoSelect("value")]; - if (f!=null) switch (dir) { - case "fontsquirrel": - // Check if font has already been imported - if (!$.isEmptyObject(data.imported[dir]) && data.imported[dir][f.family_urlname] != null) ib.addClass('active').html("Font Family Installed"); - else ib.removeClass('active').html("Install Font Family"); - break; - case "googlewebfonts": - console.log(data.imported[dir][f.family]); - if (!$.isEmptyObject(data.imported[dir]) && data.imported[dir][f.family] != null) ib.addClass('active').html("Font Family Installed"); - else ib.removeClass('active').html("Install Font Family"); - break; - } - } - } - }); - - // Font Import Button - ib.css({"margin-top":10}).click(function(e){ - e.preventDefault(); - var dir = fds.cytoRadio("value"); - var f = data[dir][ffs.cytoSelect("value")]; - var name = (dir=="fontsquirrel") ? f.family_name : f.family; - var urlname = (dir=="fontsquirrel") ? f.family_urlname : f.family; - if (!ib.hasClass('active')) { - // Import font - $.cytoAjax("/cytoplasm/fonts/import",{directory:dir,family:urlname},function(data){ - if (!iae.prop("checked")) $.cytoAjaxResponse('Font "'+name+'" has been installed successfully.<br /><a href="#" onClick="window.location.reload();">You must reload to apply these changes.</a>'); - else $.cytoAjax("/cytoplasm/fonts/enable",{family:urlname,directory:dir},function(data2){ - $.cytoAjaxResponse('Font "'+name+'" has been enabled successfully.<br /><a href="#" onClick="window.location.reload();">You must reload to apply these changes.</a>'); - }); - ib.addClass('active').html("Font Family Installed"); - }); - } else { - // Remove font - if (confirm("Are you sure you want to uninstall this font from your fonts library?")) $.cytoAjax("/cytoplasm/fonts/remove",{directory:dir,family:f},function(data){ - $.cytoAjaxResponse('Font "'+name+'" has been uninstalled successfully.<br /><a href="#" onClick="window.location.reload();">You must reload to apply these changes.</a>'); - ib.removeClass('active').html("Install Font Family"); - }); - } - }); - - }); - - }); -})(jQuery); -</script> - -<script type="text/javascript"> -(function($){ - $.Cytoplasm("ready",function(){ - $('.font_enable_disable').click(function(e){ - e.preventDefault(); - var $this = $(this); - var li = $this.parents("li"); - var fam = li.data('family'); - var dir = li.data('directory'); - - if ($this.html()=="Enable") { - $.cytoAjax("/cytoplasm/fonts/enable",{family:fam,directory:dir},function(data){ - $.cytoAjaxResponse('Font "'+fam+'" has been enabled successfully.<br /><a href="#" onClick="window.location.reload();">You must reload to apply these changes.</a>'); - $this.html("Disable"); - }); - } else if ($this.html()=="Disable") { - $.cytoAjax("/cytoplasm/fonts/disable",{family:li.data('family'),directory:dir},function(data){ - $.cytoAjaxResponse('Font "'+fam+'" has been disabled successfully.<br /><a href="#" onClick="window.location.reload();">You must reload to apply these changes.</a>'); - $this.html("Enable"); - }); - } else return false; - }); - - $('.font_uninstall').click(function(e){ - e.preventDefault(); - var $this = $(this); - var li = $this.parents("li"); - var fam = li.data('family'); - var dir = li.data('directory'); - - if (confirm('Are you sure you want to uninstall this font?')) $.cytoAjax("/cytoplasm/fonts/remove",{family:fam,directory:dir},function(data){ - $.cytoAjaxResponse('Font "'+fam+'" has been uninstalled successfully.<br /><a href="#" onClick="window.location.reload();">You must reload to apply these changes.</a>'); - li.hide(400); - }); - }); - }); -})(jQuery); -</script> +<%=render :partial => 'installer'%> \ No newline at end of file