Parent Directory | Revision Log
W3C validated with one exception: HTML4 spec lists Target attribute for A elements as deprecated, but HTML 5 doesn't;
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Barcode Generator</title> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/redmond/jquery-ui.css" type="text/css" /> <link rel="stylesheet" href="barcodegen.css" type="text/css" media="screen" /> <link rel="stylesheet" href="barcodegen_print.css" type="text/css" media="print" /> <script type="text/javascript" src="https://www.google.com/jsapi"></script> <script type="text/javascript" src="https://apis.google.com/js/plusone.js">{parsetags: 'explicit'}</script> <script type="text/javascript"><!-- google.load("jquery", "1.7"); google.load("jqueryui", "1.8"); var barcodes = {}; var bcCount = 0; KEY_TAB = 9; KEY_ENTER = 13 KEY_ESC = 27; google.setOnLoadCallback(function() { barcodeGen("Welcome to Ian's HTML5 Bar-code Generator!", "#barcode0"); $("#singleInput").keydown(function(e){ if(e.keyCode === KEY_ENTER){ var val=$(this).val(); if(val.length){ bcCount++; $("#bcDivContainer").prepend('<div id="barcode' + bcCount + '" class="bcDivUnbound"><pre class="comment unused">Click here to add a comment.</pre></div>'); barcodeGen(val, "#barcode" + bcCount); bindBcDivs(); this.select(); } } }); function bindBcDivs(){ //Comment editing binds $(".bcDivUnbound .comment").click(function(){ editedComment = $(this); editorTextarea = $("#commentEditorDialog textarea"); editorTextarea.val(editedComment.text()); $("#commentEditorDialog").dialog("option", "buttons", { "Save": function(){ if( editorTextarea.val().trim().length ){ editedComment.html(editorTextarea.val()); editedComment.removeClass("unused"); } else { editedComment.html("Click here to add a comment."); editedComment.addClass("unused"); } $(this).dialog("close"); }, "Cancel": function(){ $(this).dialog("close"); } } ).dialog("option", "title", "Edit Bar-code Comment").dialog("open"); }); //bcDiv create delete buttons $(".bcDivUnbound").prepend('<div class="btnDelete">Delete</div>'); $(".bcDivUnbound .btnDelete").button({ icons: {primary:'ui-icon-closethick'}, text: false }).click(function(){$(this).parent().remove()}).addClass("displayNone"); $(".bcDivUnbound").mouseover(function() { $(this).children(".btnDelete").removeClass("displayNone"); }).mouseout(function() { $(this).children(".btnDelete").addClass("displayNone"); }); //Remove unbound class flag $(".bcDivUnbound").addClass("bcDiv").removeClass("bcDivUnbound"); } //Highlight all text when #singleInput box receives focus $("#singleInput").focus(function(){this.select();}); //Create dialogs $("#dlgAbout").dialog({ autoOpen: false, modal: true, resizable: false, width: 640, title: "About"}); $("#dlgAbout").append("<p>Powered by <b>jQuery " + $().jquery + "</b> and <b>jQuery UI " + $.ui.version + "</b><br/>Loaded through <b>Google APIs</b>.</p>"); $("#dlgLicense").dialog({ autoOpen: false, modal: true, resizable: false, width: 640, title: "This code is usable under the terms of the BSD License"}); //Set up toolbar $("#toolbar").append('<div id="btnBulk">Bulk Input</div>'); $("#toolbar").append('<div id=btnDeleteAll>Delete All</div>'); $("#btnDeleteAll").button({ icons: {primary:'ui-icon-trash'}, text: false }).click(function(){$(".bcDiv").remove()}); $("#toolbar").append('<div id=btnPrint>Print</div>'); $("#btnPrint").button({ icons: {primary:'ui-icon-print'}, text: false }).click(function(){window.print()}); $("#toolbar").append('<div id=btnAbout>About</div>'); $("#btnAbout").button({ icons: {primary:'ui-icon-info'}, text: false }).click(function(){$("#dlgAbout").dialog("open");}); $("#toolbar").append('<div id=btnLicense>License</div>'); $("#btnLicense").button({ icons: {primary:'ui-icon-script'}, text: false }).click(function(){$("#dlgLicense").dialog("open");}); //Toolbar social buttons $("#toolbar").append('<div class="g-plusone" data-href="http://ian.cammarata.us/barcodegen.html"></div>'); //Set up modal dialog for comment editor/bulk generator $("#commentEditorDialog").dialog({ modal: true, minWidth: 500, minHeight: 500, closeOnEscape: true, }).dialog({height: 501 }).dialog("close").children("textarea").keydown(function(e){ if(e.keyCode === KEY_TAB){ //Thanks to Ken Thompson for the below code (http://stackoverflow.com/questions/9950894/adding-tabs-to-textareas-using-javascript) start = this.selectionStart; end = this.selectionEnd; $this = $(this); $this.val($this.val().substring(0, start) + "\t" + $this.val().substring(end)); this.selectionStart = this.selectionEnd = start + 1; return false; //End Thanks } }); //Bulk Generator button $("#btnBulk").button({ icons: {primary:'ui-icon-clipboard'}, text: false }).click(function(){ inputArea = $("#commentEditorDialog textarea"); inputArea.val("-Enter bar-codes here, one per line.\n-Use tabs to bulk input comments after barcode text.\n-Type [n] to create new lines in comments.\n\nex: this is a barcode this is[n]a label[n]with 3 lines"); $("#commentEditorDialog").dialog("option", "buttons", { "Generate": function(){ //Generate button clicked bulkData = inputArea.val().split("\n"); for( line in bulkData ){ bcData = bulkData[line].split("\t")[0]; commentData = bulkData[line].split("\t")[1]; if( bcData.length ){ bcCount++; if( commentData!=undefined ) $("#bcDivContainer").prepend('<div id="barcode' + bcCount + '" class="bcDivUnbound"><pre class="comment">' + commentData.replace(/\[n\]/g,"\n") + '</pre></div>'); else $("#bcDivContainer").prepend('<div id="barcode' + bcCount + '" class="bcDivUnbound"><pre class="comment unused">Click here to add a comment.</pre></div>'); barcodeGen(bcData, "#barcode" + bcCount); } } bindBcDivs(); $(this).dialog("close"); }, "Cancel": function(){ $(this).dialog("close"); } } ).dialog("option", "title", "Bulk Bar-code Input").dialog("open"); inputArea.select(); }); bindBcDivs(); function barcodeGen(val, targetBcDiv){ // Append Quiet Zone var binData="", sum=0, inPos=0, outPos=0, checkSumChar; binData += barcodes["Code128B"].charset["Quiet Zone"].bin; // Append Start char and add to sum binData += barcodes["Code128B"].charset.Start.bin; sum += ( barcodes["Code128B"].charset.Start.val * ( outPos + 1 ) ); // Loop through val, append each char and add to sum while( inPos < val.length ){ if( val[inPos] == "[" && val.substr(inPos+1).match( /[\[\]]/g ) ){ //alert(val.substr(inPos+1).match( /[\[\]]/g )); if( val[inPos + 1] == "[" ){ binData += barcodes["Code128B"].charset["["].bin; sum += ( barcodes["Code128B"].charset["["].val * ( outPos + 1 ) ); inPos += 1; } else if( closeBrack = val.substr(inPos+1).indexOf("]") ){ //alert("Found closing Bracket at " + closeBrack); //alert(val.substr(inPos+1,closeBrack)); specialChar = val.substr(inPos+1,closeBrack); if( barcodes["Code128B"].charset.hasOwnProperty(specialChar) ){ binData += barcodes["Code128B"].charset[specialChar].bin; sum += ( barcodes["Code128B"].charset[specialChar].val * ( outPos + 1 ) ); } inPos += closeBrack + 1; } } else{ //if( val[inPos] == "]" ) alert("Found a ]"); binData += barcodes["Code128B"].charset[val[inPos]].bin; sum += ( barcodes["Code128B"].charset[val[inPos]].val * ( outPos + 1 ) ); } inPos += 1; outPos += 1; } // Append checksum char to barcode for ( var prop in barcodes["Code128B"].charset ){ if( barcodes["Code128B"].charset[prop].val == sum % 103 ){ checkSumChar = prop; binData += barcodes["Code128B"].charset[prop].bin; break; } } // Debug Output //$("body").append( "binData = " + binData + "</br>" ); //$("body").append( "sum = " + sum + "; checksum = " + sum % 103 + "; checkSumChar = " + checkSumChar + "; inPos = " + inPos + "; binData.length = " + binData.length + "</br></br>" ); // Append Stop char and Quiet Zone binData += barcodes["Code128B"].charset.Stop.bin; binData += barcodes["Code128B"].charset["Quiet Zone"].bin; // Estimate msg width and determine canvas width newVal = val.replace( "[[", "[" ); txtWidth = newVal.length * 9.5; bcWidth = binData.length; //$("body").append( "txtWidth = " + txtWidth + "; bcWidth = " + bcWidth + "<br/>" ); canvasWidth = txtWidth > bcWidth ? txtWidth : bcWidth; // Create a fresh properly sized canvas $(targetBcDiv).append("<canvas class='barcode' width='" + canvasWidth + "' height='60'>Sorry, your browser doesn't support the HTML 5 canvas.</canvas>"); // Draw the barcode var canvas = $(targetBcDiv + " .barcode")[0]; if (canvas.getContext){ var ctx = canvas.getContext('2d'); cWidth = $(canvas).width(); cHeight = $(canvas).height(); binPos = 0; ctx.fillStyle = "white"; ctx.fillRect(0,0,cWidth,cHeight); ctx.fillStyle = "black"; while( binPos < binData.length ){ if( binData[binPos] == "1" ) ctx.fillRect( binPos, 6, 1, cHeight - 25 ); binPos += 1; } ctx.font = "12pt Courier New"; ctx.textAlign = "center"; ctx.fillText( newVal, cWidth / 2, cHeight - 5 ); } } gapi.plusone.go(); }); --></script> <script type="text/javascript" src="code128b.js"></script> </head> <body> <div id="dlgAbout"> <p>BarcodeGen v0.3</p><hr/> <p>This utility currently only generates Code128B bar-codes.</p> <p>Special characters can be entered by placing them inside brackets.<br/>ex: [FNC 3]</p> <p>Available special characters for Code128B are:<br/> FNC 1, FNC 2, FNC 3, FNC 4, Code A, Code C, Shift A</p> <hr/><p>Created by Ian Cammarata <a href="http://ian.cammarata.us" target="_blank">http://ian.cammarata.us</a></p> </div> <div id="toolbar"> <input type="text" id="singleInput" size="50" value="" /> </div> <div id="bcDivContainer"> <div id="barcode0" class="bcDivUnbound"> <pre class="comment">Welcome to Ian's HTML5 Bar-code Generator!</pre> </div> <script type="text/javascript"><!-- google_ad_client = "ca-pub-4313409995163092"; /* BarcodeGen */ google_ad_slot = "1349349680"; google_ad_width = 728; google_ad_height = 90; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script> </div> <div id="dlgLicense" > <pre>Copyright (c) 2011-2012, Ian Cammarata All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. All advertising materials mentioning features or use of this software must display the following acknowledgement: This product includes software developed by Ian Cammarata. 4. Neither the name of Ian Cammarata nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY Ian Cammarata ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Ian Cammarata BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</pre></div> <div style="display: none;" id="commentEditorDialog"><textarea rows="17" cols="60"></textarea></div> </body> </html>
Contact | ViewVC Help |
Powered by ViewVC 1.0.4 |