Skip to main content

Home/ javascript/ Group items tagged document

Rss Feed Group items tagged

Javier Neira

6 Advanced JavaScript Techniques You Should Know - 3 views

  • function showStatistics(args) { document.write("<p><strong>Name:</strong> " + args.name + "<br />"); document.write("<strong>Team:</strong> " + args.team + "<br />"); if (typeof args.position === "string") { document.write("<strong>Position:</strong> " + args.position + "<br />"); } if (typeof args.average === "number") { document.write("<strong>Average:</strong> " + args.average + "<br />"); } if (typeof args.homeruns === "number") { document.write("<strong>Home Runs:</strong> " + args.homeruns + "<br />"); } if (typeof args.rbi === "number") { document.write("<strong>Runs Batted In:</strong> " + args.rbi + "</p>"); } } showStatistics({ name: "Mark Teixeira" }); showStatistics({ name: "Mark Teixeira", team: "New York Yankees" }); showStatistics({ name: "Mark Teixeira", team: "New York Yankees", position: "1st Base", average: .284, homeruns: 32, rbi: 101 });
  • Object-oriented JavaScript implements namespace-like principles due to the fact that properties and methods are declared inside of objects, thus there are less likely to be conflicts. A conflict could arise, however, through object names. And very likely, the conflict will occur "silently", thus you may not be alerted to the issue immediately.
  • if (typeof MY == "undefined") { MY = new Object(); MY.CUSTOM = new Object(); } MY.CUSTOM.namespace = function() { function showStatistics(args) { document.write("<p><strong>Name:</strong> " + args.name + "<br />"); document.write("<strong>Team:</strong> " + args.team + "<br />"); if (typeof args.position === "string") { document.write("<strong>Position:</strong> " + args.position + "<br />"); } if (typeof args.average === "number") { document.write("<strong>Average:</strong> " + args.average + "<br />"); } if (typeof args.homeruns === "number") { document.write("<strong>Home Runs:</strong> " + args.homeruns + "<br />"); } if (typeof args.rbi === "number") { document.write("<strong>Runs Batted In:</strong> " + args.rbi + "</p>"); } } showStatistics({ name: "Mark Teixeira", team: "New York Yankees", position: "1st Base", average: .284, homeruns: 32, rbi: 101 }); } MY.CUSTOM.namespace();
  • ...1 more annotation...
  • Rendering Readable HTML
  •  
    //2. Object Literals to Pass Optional Arguments function showStatistics(args) { document.write("Name: " + args.name + "
    "); document.write("Team: " + args.team + "
    "); if (typeof args.position === "string") { document.write("Position: " + args.position + "
    "); } if (typeof args.average === "number") { document.write("Average: " + args.average + "
    "); } if (typeof args.homeruns === "number") { document.write("Home Runs: " + args.homeruns + "
    "); } if (typeof args.rbi === "number") { document.write("Runs Batted In: " + args.rbi + ""); } } showStatistics({ name: "Mark Teixeira" }); showStatistics({ name: "Mark Teixeira", team: "New York Yankees" }); showStatistics({ name: "Mark Teixeira", team: "New York Yankees", position: "1st Base", average: .284, homeruns: 32, rbi: 101 }); //Using Namespaces to Prevent Conflicts if (typeof MY == "undefined") { MY = new Object(); MY.CUSTOM = new Object(); } MY.CUSTOM.namespace = function() { function showStatistics(args) { .................. } showStatistics({ name: "Mark Teixeira", team: "New York Yankees", position: "1st Base", average: .284, homeruns: 32, rbi: 101 }); } MY.CUSTOM.namespace();
yc c

Color Picker - Raphaël - 0 views

shared by yc c on 04 Mar 10 - Cached
  •  
    No images. No libraries*. Works even in IE6. // Color Picker by Raphaël - raphaeljs.com var icon = Raphael("picker", 23, 23).colorPickerIcon(11, 11, 10); icon.attr({cursor: "pointer"}).node.onclick = function () {    document.getElementById("benefits").style.visibility = "visible";    var out = document.getElementById("output");    out.style.visibility = "visible";                   // this is where colorpicker created    var cp = Raphael.colorpicker(document.body.offsetWidth / 2 - 150, 250, 300, "#eee", document.getElementById("picker2"));                   out.onkeyup = function () {        cp.color(this.value);    };    // assigning onchange event handler    cp.onchange = function (clr) {        out.value = clr;        document.body.style.background = clr;        document.body.style.color = Raphael.rgb2hsb(clr).b s it. Too easy                    icon.node.onclick = null;}; 
Javier Neira

Michael Sharman - chapter31 » Including js files from within js files - 1 views

  •  
    01.//this function includes all necessary js files for the application 02.function include(file) 03.{ 04. 05. var script = document.createElement('script'); 06. script.src = file; 07. script.type = 'text/javascript'; 08. script.defer = true; 09. 10. document.getElementsByTagName('head').item(0).appendChild(script); 11. 12.} 13. 14./* include any js files here */ 15.include('js/myFile1.js'); 16.include('js/myFile2.js');
Javier Neira

HtmlUnit - Welcome to HtmlUnit - 2 views

  •  
    HtmlUnit is a "GUI-Less browser for Java programs". It models HTML documents and provides an API that allows you to invoke pages, fill out forms, click links, etc... just like you do in your "normal" browser. It has fairly good JavaScript support (which is constantly improving) and is able to work even with quite complex AJAX libraries, simulating either Firefox or Internet Explorer depending on the configuration you want to use. It is typically used for testing purposes or to retrieve information from web sites. HtmlUnit is not a generic unit testing framework. It is specifically a way to simulate a browser for testing purposes and is intended to be used within another testing framework such as JUnit or TestNG. Refer to the document "Getting Started with HtmlUnit" for an introduction. HtmlUnit is used as the underlying "browser" by different Open Source tools like Canoo WebTest, JWebUnit, WebDriver, JSFUnit, Celerity, ... HtmlUnit was originally written by Mike Bowler of Gargoyle Software and is released under the Apache 2 license. Since then, it has received many contributions from other developers, and would not be where it is today without their assistance.
Mike Chelen

Data scraping with YQL and jQuery | kelvinluck.com - 0 views

  • need a list of all the US National Parks in XML format
  • grab the data from this list on Wikipedia
  • navigating a HTML DOM
  • ...9 more annotations...
  • jQuery to parse the data
  • XPath to your YQL
  • relevant table from the Wikipedia document
  • SELECT * FROM html WHERE url="http://en.wikipedia.org/wiki/List_of_United_States_National_Parks_by_state" AND xpath="//table[@class='wikitable sortable']"
  • XML or JSON
  • creating an XML document
  • AJAX call from jQuery and then loop over the JSON
  • documentation could maybe be clearer
  • CSS style selection engine as well as the XPath one
Ivan Pavlov

John Resig - DOM DocumentFragments - 0 views

  • var div = document.getElementsByTagName("div"); var fragment = document.createDocumentFragment(); for ( var e = 0; e < elems.length; e++ ) {         fragment.appendChild( elems[e] ); } for ( var i = 0; i < div.length; i++ ) {         div[i].appendChild( fragment.cloneNode(true) ); }
  • Setting some time stamps we can see our results pay off in spades: Browser Normal (ms) Fragment (ms) Firefox 3.0.1 90 47 Safari 3.1.2 156 44 Opera 9.51 208 95 IE 6 401 140 IE 7 230 61 IE 8b1 120 40
yc c

BrainJar.com: DOM Viewer - 0 views

  •  
    This JavaScript utility allows you to interactively browse the Document Object Model representation of a page. Its designed to help developers in finding the various objects, properties and values associated with elements and other objects in an web page.
yc c

JavaScript Shell - 0 views

  •  
    Features: You can enter statements and expressions at the same prompt. The result of each non-void statement or expression is shown. User-defined variables. b = document.body User-defined functions. function f() { return 5; } JavaScript error messages are shown in red. Previous statements and expressions are available through Up and Down arrow keys. Tab completion. Multiline input (Shift+Enter to insert a line break). If the shell is opened using a bookmarklet, JavaScript typed into the shell runs in the context of the original window. Works well in Firefox, mostly works in Opera 8 and in IE 6 for Windows. Suggested uses: Test short bits of JavaScript, bookmarklets, or user scripts. (For longer bits of JavaScript, try the JavaScript development enviornment too.) Explore DOM objects such as document.body using props (Alt+P) to figure out what is possible. Explore the DOM of a specific page using the bookmarklet version of the shell. Modify the DOM of a specific page using the bookmarklet version of the shell. Use the shell like you would use the home screen of a calculator such as a TI-83. Alt+M gives you easy access to math functions such as sin and pow.
yc c

YUI -- The Yahoo! User Interface Library - 0 views

  •  
    The YUI Library is a set of utilities and controls, written in JavaScript, for building richly interactive web applications using techniques such as DOM scripting, DHTML and AJAX. YUI is available under a BSD license and is free for all uses. The YUI project includes the YUI Library and two build-time tools: YUI Compressor (minification) and YUI Doc (documentation engine for JavaScript code).
yc c

Soba1.1 - a live HTML editor - 2 views

  •  
    just edit the html on the left pane, and you'll see how it rendered on the right pane as you typed.\nIt should be useful when you want to develop such as CSS or JavaScript which need to be tuned litlle by little.\nNote that the html document is automatically stored into a browser's cookie(up to approx.4kb).\nSo you can continue working on the html even after you closed the browser window.
yc c

Sizzle JavaScript Selector Library - 1 views

shared by yc c on 30 Jan 10 - Cached
  •  
    A pure-JavaScript CSS selector engine designed to be easily dropped in to a host library. Sizzle supports virtually all CSS 3 Selectors - this even includes some parts that are infrequently implemented such as escaped selectors (".foo\\+bar"), Unicode selectors, and results returned in document order. There are a few notable exceptions to the CSS 3 selector support (the reasoning for this decision can be found here): * :root * :target * :nth-last-child * :nth-of-type / :nth-last-of-type / :first-of-type / :last-of-type / :only-of-type * :lang() In addition to the CSS 3 Selectors Sizzle supports the following additional selectors or conventions.
yc c

html5media - Project Hosting on Google Code - 1 views

  •  
    HTML5 video and audio tags make embedding media into documents as easy as embedding an image. All it takes is a single or tag. Unfortunately, not all browsers natively support these HTML5 tags.
Julian Knight

JQuery Selectors - 0 views

  •  
    Online quick reference with examples and links to full documentation.
Ivan Pavlov

Meteora Javascript Widgets - 0 views

  • Demo SWF

    Meteora Description

    Meteora is set of cross-browser Widgets and Controls that allows you to quickly write rich and customizable web applications without having to waste time reading full pages of documentation or programming excessive javascript that is painful to debug in every browser.

Ivan Pavlov

Shadowbox.js Media Viewer - 0 views

  • Shadowbox is a cross-browser, cross-platform, cleanly-coded and fully-documented media viewer application written entirely in JavaScript. Using Shadowbox, website authors can display a wide assortment of media in all major browsers without navigating away from the linking page.
Ivan Pavlov

KevLinDev - Geometry - 0 views

  • SVG and JavaScript are used to find intersections and properties of a selected group of SVG elements. JavaScript objects used in this section are documented in the GUI section of this site.
Mike Chelen

EtherPad: Realtime Collaborative Text Editing - 0 views

  •  
    EtherPad lets multiple people work on the same text simultaneously.
1 - 20 of 28 Next ›
Showing 20 items per page