www.webdeveloper.com
Recent Articles
  • Finding Slow Running Queries in ASE 15
  • A More Advanced Pie Chart for Analysis Services Data
  • Adobe AIR Programming Unleashed: Working with Windows
  • Performance Testing SQL Server 2008's Change Data Capture Functionality
  • The ABC's of PHP: Introduction to PHP
  • How to Migrate from BasicFiles to SecureFiles Storage
  • Why the Twitter Haters Are Wrong
  • User Personalization with PHP: Beginning the Application
  • Whats in an Oracle Schema?
  • Lighting Enhancement in Photoshop
  •  

    Go Back   WebDeveloper.com > Client-Side Development > JavaScript

    JavaScript JavaScript (not Java) Discussion and technical support, including AJAX and frameworks (JQuery, MooTools, Prototype...)

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1  
    Old 06-05-2005, 06:29 PM
    fozerator fozerator is offline
    Web Programmer
     
    Join Date: May 2005
    Posts: 31
    heredoc strings in javascript

    Hello everyone... I'm wondering if it's possible to use a heredoc type string syntax in javascript. I know I can do this:

    Code:
    var style = '.calendar {'
    		+ '	font-size:9px;'
    		+ '	font-family:verdana, arial;'	
    		+ '	background-color:red;'
    		+ '	width:196px;'
    		+ '}';
    But is there any way to do this?

    Code:
    var style = ' .calendar {
    			font-size:9px;
    			font-family:bitstream, verdana, arial;	
    			background-color:red;
    			width:196px;
    		}';
    Breaking up the string in the first method just takes a lot of time when I'm pasting a stylesheet... Just wondering if there was an easier way to do it...

    -James
    Reply With Quote
      #2  
    Old 06-05-2005, 06:42 PM
    acorbelli acorbelli is offline
    Urban Underwear
     
    Join Date: Mar 2005
    Location: CA
    Posts: 323
    To do it you need to put in a backslash to let the browser know it's continuing the string to the next line...

    Code:
    var style = ' .calendar { \
    			font-size:9px; \
    			font-family:bitstream, verdana, arial; \
    			background-color:red; \
    			width:196px; \
    		}';
    Hope that helps!
    __________________
    -Anthony
    Reply With Quote
      #3  
    Old 06-05-2005, 06:43 PM
    fozerator fozerator is offline
    Web Programmer
     
    Join Date: May 2005
    Posts: 31
    Thanks anthony. That makes things a LOT easier for me .

    -James
    Reply With Quote
      #4  
    Old 06-06-2005, 12:01 AM
    fredmv's Avatar
    fredmv fredmv is offline
    Moderator
     
    Join Date: Jul 2003
    Location: Boston Area, Massachusetts
    Posts: 3,499
    The escapes work nicely. Another option would be to simply have it all on one line within the variable, but I suppose you care about the formatting (which, certiainly, isn't a bad thing -- code neatness is much preferred). Another thing you could do, though rather messy, would be to do something like this:
    Code:
    <textarea id="code" style="display: none">.calendar {
    		font-size:9px;
    		font-family:bitstream, verdana, arial;
    		background-color:red;
    		width:196px;
    }</textarea>
    Then, simply:
    Code:
    var style = document.getElementById('code').value;
    Reply With Quote
      #5  
    Old 06-06-2005, 12:09 AM
    Vladdy's Avatar
    Vladdy Vladdy is offline
    Helper, not pleaser
     
    Join Date: Nov 2002
    Location: Nashua, NH
    Posts: 3,222
    Just out of curiousity... any good reason to put the style information in the JS code?
    __________________
    Vladdy

    Working web site is not the one that looks the same in a few graphical browsers, but the one that adequately delivers its content to any device accessing it.
    Reply With Quote
      #6  
    Old 06-06-2005, 08:23 AM
    fozerator fozerator is offline
    Web Programmer
     
    Join Date: May 2005
    Posts: 31
    Nope. At least not a very good reason...

    I made a calendar script that prints a variety of different calendars with different options. A few that I looked at had all of the colors hard-coded, which I really didn't like. I like to be able to add formatting options pretty quick, and CSS is a good way to do it (I learned js for programming this and some AJAX stuff, and I'm almost done with both )

    And, as far as putting the style in the JS, I decided that if I were to give the script away, it would be easier to have it all in one file... If the user doesn't like it, they can definitely move it into a seperate file, but for simplicity I decided to put it in the .js file and just add the style element to the head of the document when the script is imported....

    I'm sure there are even better ways to do it, but this is my second js program, and I'm just glad it works.

    Thanks for the help everyone,

    -James
    Reply With Quote
      #7  
    Old 06-06-2005, 08:27 AM
    Vladdy's Avatar
    Vladdy Vladdy is offline
    Helper, not pleaser
     
    Join Date: Nov 2002
    Location: Nashua, NH
    Posts: 3,222
    It is much easier to put styles in a CSS file where they belong. It will also make much easier to change them without worrying about possible JS errors when you miss a slash. Then you put both of them in a zip along with an installation/user manual.
    __________________
    Vladdy

    Working web site is not the one that looks the same in a few graphical browsers, but the one that adequately delivers its content to any device accessing it.
    Reply With Quote
    Reply

    Bookmarks


    Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
     
    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is Off
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 10:12 PM.



    Acceptable Use Policy

    internet.comMediabistrojusttechjobs.comGraphics.com

    WebMediaBrands Corporate Info


    Advertise | Newsletters | Feedback | Submit News

    Legal Notices | Licensing | Permissions | Privacy Policy

    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.