soumya mukherjee's Profile

Member since Oct 23, 2008, follows 1 people, 0 public groups, 158 public bookmarks (158 total).

More »
Tags

Recent Tags:
Top Tags:

More »
Recent Bookmarks and Annotations

  • Finding HTML elements using Javascript nextSibling and previousSibling · The Watchmaker Project on 2009-11-30
    • Finding HTML elements using Javascript nextSibling and previousSibling



      Jun 13 2006


      Updated 13/06: See below for update on IE compatibility.



      Quite often when writing Javascript functions you will want to get a reference to the element immediately before or after the one you’re working with; for example, when validating a form you may want to toggle the display of a <span> containing an error message that appears immediately before the input being validated.



      The built-in Javascript properties nextSibling and previousSibling will return a reference to the element after/before your chosen element respectively, but they have a major drawback when it comes to whitespace in your code – any spaces or line-breaks in the source code will be interpreted as DOM nodes, and your nextSibling/previousSibling call will return a blank text node instead of the object you were expecting.



      To get around this, I’ve extended the Object type and added two new methods, named nextObject() and previousObject(). They perform exactly the same function as nextSibling and previousSibling, but will only return the next/previous HTML element, ignoring text nodes altogether:

  • Triple Helix Studios - 30-CSS-Tips-and-Tricks on 2009-11-24




    • <!-- START TITLE -->

      CSS Compression Using PHP Function


      <!-- END TITLE -->




      <!-- START POST CONTENT -->

      I stumbled upon this trick not too long ago when I was looking for ways to maximize the efficiency of my websites, and reduce the footprint a little. When I am developing css, my preference is to keep the code in a readable format, so I prefer something like:

      p  { float:left;
      display:block;
      font-size: 2em !important;
      background: #FFF url('/dev/../images/bg.png') no-repeat 0 0;
      padding: 10px;
      width: 300px !important;
      margin: 0px;
      border: 1px solid #000;
      }

      Yeah, I know this method probably immediately kicks from the ranks of the CSS jedi, but I find that my workflow goes much smoother when the code is more readable. The way I see it, formatting it like this is like code indenting, and even if making it more readable saves me a fraction of a second per read, then it probably saves me 10-20 seconds a day! That is almost 2 full minutes a week!

      Anyway, when you build it out this way, and wind up with hundreds of css classes on a site, it does tend to generate a lot of whitespace in the files, which of course can add crucial kilobytes to your page footprint. So, in my travels I ran across the following php script:

      header('Content-type: text/css');
      ob_start("compress");
      function compress($buffer) {
          $buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer);
          $buffer = str_replace(array("\r\n", "\r", "\n", "\t", ' ', ' ', ' '), '', $buffer);
           return $buffer;
      }

      include ('layout.css')

      ob_end_flush();

      This is known as the Reinhold Weber method, and what this basically does is remove all of your CSS comments and whitespace for all of the files that you specify upon request of the file itself. All you need to do is ensure that this script is added to a master css file, and then include that file in your web template header.

      I do understand that this does add some server overhead per request based on execution of the php,  but if I can write the CSS however I want, comment it how I like to, etc. and have the rendered version be super stripped down, then for me that is perfect. 

       There are a couple of caveats here, though. You will need to make sure that you can include PHP code in CSS and that it will be parsed, so you will need to either make sure that your provider handles this, or if you have access to the .htaccess file on your site, you can include this to allow php to see css:

       ######### Begin - Handle PHP in CSS files ##########
      AddType text/css .css
      AddHandler application/x-httpd-php .css
      ########## End - Handle PHP in CSS files ##########

      You may also run into problems with  the mime type for CSS files then, so you will need to add the following to the top of the CSS files that you don't include in the script:

       header('Content-type: text/css');

       That is pretty much it - good luck.



  • Triple Helix Studios - Joomla Tricks for Multiple Templates | Blog on 2009-11-24
    • While I do think that Joomla is probably the best open source CMS out there, it is not without some serious drawbacks. I won't go into them much now (cough multiple access levels... cough), but one area that I think is pretty mediocre is in how they handle using multiple templates, or subtemplates.

      When I was looking for a way to have the floating lightbox blog entries that are found on the home page, the challenge that I had was in forcing the popups to not open the main site template in the popup window, which Joomla forces by default, but rather give me a separate window that I could style with different rules. 



      In previous versions of the Joomla CMS (1.0.x) you could do this by simply pointing your links to index2.php, which was meant to be used as a print template. From there, you could include a different set of styles in the header and have it do what you wanted. Joomla 1.5  has changed that around a bit. One hack that I wound up using, is that if you pass the url parameter:

      ?tmpl=component

      the page will open up using just the component view, which in this case is com_content (the default content component view). This is basically the same thing as the old print view in Joomla 1.0. This gives you a blank version of your same content template that you can make changes to. 

      The caveat here is that if you wanted to make any structural changes, then it would mean that you would have to actually modify the core engine that generates the com_content component, right? The problem there is that if there is an update to the engine, your changes would be wiped out. Luckily, Joomla 1.5 also includes a fantastic addition in content overrides. Basically, all you have to do is create a file called component.php in your custom template folder, and when Joomla calls any page with the tmpl=component switch, it will load this page instead of the index.php page. In the component.php page, you can treat it basically the same as the index.php page, and style it however you want. 

  • Adding custom columns/fields to Joomla article, section and user | ProDevTips - dev notes and tutorials on 2009-11-24
    • Run


      ALTER TABLE `jos_content` ADD `article_image` VARCHAR255 ) NOT NULL

      in for instance phpMyAdmin.


      Edit administrator/components/com_content/models/article.xml add:


      <param name="article_image" type="text" default="" label="Image" description="" />

      in the first params section for instance below the access entry.


      Add


      var $article_image = null;

      to libraries/joomla/database/table/content.php


      Add


      $form->set('article_image'$row->article_image);

      to editContent() in administrator/components/com_content/controller.php



      <script type="text/javascript"><!--
      google_ad_client = "pub-4780703337538969";
      google_alternate_color = "dedcdc";
      google_ad_width = 234;
      google_ad_height = 60;
      google_ad_format = "234x60_as";
      google_ad_type = "text_image";
      google_color_border = "dedcdc";
      google_color_link = "993333";
      google_color_bg = "dedcdc";
      google_color_text = "000000";
      google_color_url = "003366";
      //-->
      </script>

      <script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript">
      </script><script>google_protectAndRun("ads_core.google_render_ad", google_handleError, google_render_ad);</script>

      The result is that you now have a new field called article_image that can be used in various ways to display a separate image that is not a part of the article, similar to what you have per default for categories and sections.


      On an unrelated side note, if custom CSS classes are added to /templates/system/css/editor.css they will appear for selection in tinyMCE. You also need to include it in your template’s index.php, like so:


      <link href="templates/system/css/editor.css" rel="stylesheet" type="text/css"/>

      That however screwed up my CSS, until I simply commented out everything above STYLES FOR JOOMLA! EDITOR. The end of my editor.css now looks like this:


      /* 
      . . . 
      div.caption       { padding: 0 10px 0 10px; } 
      div.caption img   { border: 1px solid #CCC; } 
      div.caption p     { font-size: .90em; color: #666; text-align: center; } 
      */
       
      /* STYLES FOR JOOMLA! EDITOR */ 
      hr#system-readmore  { borderred dashed 1pxcolorred; } 
      hr.system-pagebreak { bordergray dashed 1pxcolorgray; } 
      .float_left{ float:left; } 
      .float_right{ float:right; }

      Update: To add fields to the jos_users table in a dirty and quick way as opposed to the proper way:



      <script type="text/javascript"><!--
      google_ad_client = "pub-4780703337538969";
      google_alternate_color = "dedcdc";
      google_ad_width = 234;
      google_ad_height = 60;
      google_ad_format = "234x60_as";
      google_ad_type = "text_image";
      google_color_border = "dedcdc";
      google_color_link = "993333";
      google_color_bg = "dedcdc";
      google_color_text = "000000";
      google_color_url = "003366";
      //-->
      </script>

      <script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript">
      </script><script>google_protectAndRun("ads_core.google_render_ad", google_handleError, google_render_ad);</script>

      1.) Add the fields to the jos_users table, for instance firstname.

      2.) Add the variables to libraries/joomla/user/user.php and libraries/joomla/database/table/user.php, it has to look like this at the top for instance: var $firstname = null;

      3.) Add the input fields to the registration form.

      4.) Optionally: In my case I had to override the name field (doesn’t make sense in having a firstname, lastname and name field). In that case I simply added a line to fill the name with firstname and lastname before validation happens (in the register controller, I think the method in question is called register_save()).


      Update: I just added a new column to the sections, the point of the new field is to keep track of whether or not we are to show galleries tagged to the section in question when we are in our totally custom blog layout. It was somewhat easier than to the articles, begin with running the following SQL:


      ALTER TABLE `jos_sections` ADD `show_galleries` TINYINT1 ) NOT NULL

      Then add the following HTML to administrator/components/com_sections/admin.sections.html.php add at line 275:


      <tr> 
          <td class="key"> 
              <?php echo 'Show Galleries' ?>
          </td> 
          <td colspan="2"> 
              <?php echo $lists['show_galleries']; ?> 
          </td> 
      </tr>

      Add the following PHP to administrator/components/com_sections/admin.sections.php add at line 264:


      $lists['show_galleries'] = JHTML::_('select.booleanlist',  'show_galleries''class="inputbox"'$row->show_galleries );

      Finally, just like with the articles, add this PHP to libraries/joomla/database/table/section.php:


      var $show_galleries     = null;

      Done!


  • Joomla! • View topic - Lightbox Content PopUp on 2009-11-24
    • Posted: Tue Sep 08, 2009 12:17 pm 




















      Joined: Tue Sep 19, 2006 9:12 am
      Posts: 91
      Location: Hampshire, UK



    • Third-Party Affiliate Programs: Roll Your Own Instead on 2009-10-29
    • Htaccess Mod Rewrite Examples, 301 Redirects, Dynamic URL Rewrites on 2009-10-29
      • 01 Redirects are often referred to as 'Redirect Permanent' so as the name implies 301’s are used to permanently redirect one web page to another - and are recommended by Google as the best met
    • Detect IE - JavaScript - Snipplr on 2009-09-09
        • Detect IE







          Published in: JavaScript 





          Returns true if the browser is Internet Explorer, false otherwise.





          Embed | Plain TextExpand <!-- / <a href="javascript:wraplines();">Wrap</a> -->



          1. function isIE()
          2. {
          3. return /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent);
          4. }
        • Detect IE







          Published in: JavaScript 





          Returns true if the browser is Internet Explorer, false otherwise.





          Embed | Plain TextExpand <!-- / <a href="javascript:wraplines();">Wrap</a> -->



          1. function isIE()
          2. {
          3. return /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent);
          4. }
    • Jaipur - Wikipedia, the free encyclopedia on 2009-08-23
    • Spirituality & Practice: Resources for Spiritual Journeys on 2009-08-23
      • The Living Spiritual Teachers Project spotlights people from different traditions we think you should meet on your spiritual journey. It already includes profiles of more than 90 teachers, and we are adding more all the time. The latest additions both teach writing as well as write with their own di
    • Diigo is about better ways to research, share and collaborate on information. Learn more »

      Join Diigo
      User avatar
      Joomla! Intern
      Joomla! Intern
      Offline




      Perhaps using "&tmpl=component" on the end of your url might help? This seems to strip off the site template and design etc and just give you the stylesheets and component content. Hope you find what you're looking for.