Permalink
Browse files

Performance improved and IE7 bug fixed

  • Loading branch information...
1 parent 6b59277 commit 6237c031cbc4d13a377392beb1698217080a83b2 @raulb raulb committed Mar 7, 2012
Showing with 21 additions and 16 deletions.
  1. +10 −15 heroku.js
  2. +2 −1 index.html
  3. +9 −0 jquery.replacetext.min.js
View
@@ -1,27 +1,22 @@
// Replace each {{app-name}} with the real name application
jQuery(document).ready(function($) {
-
- var nameApp = '';
-
+
// *** Getting the app name with the current url
// We get the hostName
var hostName = window.location.hostname;
// And we parse it with his real application name
- nameApp = hostName.substr('0',hostName.indexOf(".herokuapp.com"));
+ var nameApp = hostName.substr('0',hostName.indexOf(".herokuapp.com"));
- // // We could define it from HTML
+ // We could define it from HTML
if (nameApp == '') nameApp = "your-app";
- // // We look into the DOM per each element with {{app-name}}
- $('*:contains("{{app-name}}")').each(function() {
- // jQuery :contains selector return every node in its tree. We just want the real container (= just 1 child)
- if($(this).children().length < 1) {
-
- // We replace {{app-name}} for your new Application name and we assigned into itself
- // $(this).html($(this).html().replace("{{app-name}}",nameApp));
- $('this').html($(this).html().replace("{{app-name}}",nameApp));
- }
- });
+ // To change <title> with IE we have to use document property
+ if ($('title:contains("{{app-name}}")')) {
+ var title = document.title.replace("{{app-name}}",nameApp);
+ document.title = title;
+ }
+
+ $("body *").replaceText("{{app-name}}",nameApp);
});
View
@@ -11,7 +11,8 @@
<link href="http://twitter.github.com/bootstrap/assets/css/bootstrap-responsive.css" rel="stylesheet">
<script src="http://heroku.github.com/template-app-bootstrap/jquery-1.7.1.min.js"></script>
-
+ <script src="http://heroku.github.com/template-app-bootstrap/jquery.replacetext.min.js"></script>
+
<!--
IMPORTANT:
This is Heroku specific styling. Remove to customize.
@@ -0,0 +1,9 @@
+/*
+ * jQuery replaceText - v1.1 - 11/21/2009
+ * http://benalman.com/projects/jquery-replacetext-plugin/
+ *
+ * Copyright (c) 2009 "Cowboy" Ben Alman
+ * Dual licensed under the MIT and GPL licenses.
+ * http://benalman.com/about/license/
+ */
+(function($){$.fn.replaceText=function(b,a,c){return this.each(function(){var f=this.firstChild,g,e,d=[];if(f){do{if(f.nodeType===3){g=f.nodeValue;e=g.replace(b,a);if(e!==g){if(!c&&/</.test(e)){$(f).before(e);d.push(f)}else{f.nodeValue=e}}}}while(f=f.nextSibling)}d.length&&$(d).remove()})}})(jQuery);

0 comments on commit 6237c03

Please sign in to comment.