Script (101)


JavaScript: Objects Inherit from Objects

JavaScript: Objects Inherit from Objects
Object() suggested by Douglas Crockford




Get Your Pdf button for Your Web Site

Get your pdf button and convert your html content in pdf document in a instant with jsPDF

// get jsPDF library - url
var jsPDF = "http://mrrio.github.io/jsPDF/dist/jspdf.debug.js"
// set css class for button
var pdfclass = ".pdf{-moz-box-shadow:inset 0 1px 0 0 #f5978e;-webkit-box-shadow:inset 0 1px 0 0 #f5978e;box-shadow:inset 0 1px 0 0 #f5978e;background-color:#f24537;-webkit-border-top-left-radius:16px;-moz-border-radius-topleft:16px;border-top-left-radius:16px;-webkit-border-top-right-radius:16px;-moz-border-radius-topright:16px;border-top-right-radius:16px;-webkit-border-bottom-right-radius:16px;-moz-border-radius-bottomright:16px;border-bottom-right-radius:16px;-webkit-border-bottom-left-radius:16px;-moz-border-radius-bottomleft:16px;border-bottom-left-radius:16px;text-indent:0;border:1px solid #d02718;display:inline-block;color:#fff;font-family:Arial;font-size:15px;font-weight:bold;font-style:normal;height:27px;line-height:27px;width:120px;text-decoration:none;text-align:center;text-shadow:1px 1px 0 #810e05}.pdf:hover{background-color:#c62d1f}.pdf:active{position:relative;top:1px}";
var head = document.head || document.getElementsByTagName('head')[0];
// create style button
var style = document.createElement('style');
var btnpdf = document.createElement("button");
style.type = 'text/css';
if (style.styleSheet){
  style.styleSheet.cssText = pdfclass;
} else {
  style.appendChild(document.createTextNode(pdfclass));
}
head.appendChild(style);
// append pdf library
var scriptjspdf =  document.createElement('script');
scriptjspdf.src = jsPDF;
head.appendChild(scriptjspdf);
btnpdf.setAttribute("id", "printpdf");
btnpdf.setAttribute("class", "pdf");
var textBtn = document.createTextNode("Save PDF");
btnpdf.appendChild(textBtn)
document.body.appendChild(btnpdf);
// now build your pdf function
function saveinPdf(){	
	var pdf = new jsPDF('p', 'pt', 'letter')
	, source = document.body
	, specialElementHandlers = {
		'#bypassme': function(element, renderer){
			return true
		}
	}

   margins = {
      top: 20,
      bottom: 20,
      left: 20,
      width: 210
    };
    pdf.fromHTML(
    	source 
    	, margins.left 
    	, margins.top 
    	, {
    		'width': margins.width 
    		, 'elementHandlers': specialElementHandlers
    	},
    	function (dispose) {
	    	try {
	    		var inputFilename = prompt("Enter file name to save html result in pdf");
		    		if(inputFilename == "") {
		    			alert('You must enter file name to save result in pdf, please')
		    		} else {
		    			pdf.save(inputFilename + '.pdf');
		    		}	    		
	    		} catch(e) {
	    			 txt="There was an error on save.\n\n";
	    			 txt+="Error description: " + e.message + "\n\n";
	    			 txt+="Click OK to continue.\n\n";
	    			 alert(txt);
	    		}
    		
        },
    	margins
    )	
}
document.getElementById("printpdf").addEventListener("click", saveinPdf, false);



Undoredo pure js

var undoStack = [], 
redoStack = [],
areaeditor,
undoBtn,
redoBtn;
function undoRedoButtonControl() {
    undoBtn.style.color = undoStack.length > 0 ? "black" : "gray";
    redoBtn.style.color = redoStack.length > 0 ? "black" : "gray";
}
function undo_push(a) {
    var b = undoStack.pop();
    undoStack.push(b);
    b !== a && undoStack.push(a);
    undoRedoButtonControl();
}

function redo_push(a) {
    redoStack.push(a);
    undoRedoButtonControl();
}

function undo_pop() {
    if (undoStack.length > 0) {
        redo_push(areaeditor.value);
        areaeditor.value = undoStack.pop();
        undoRedoButtonControl();       
    }
}

function redo_pop() {
    if (redoStack.length > 0) {
        undo_push(areaeditor.value);
        areaeditor.value = redoStack.pop();
        undoRedoButtonControl();        
    }
}
function process_keystrokes() {
    undo_push(areaeditor.value);
    areaeditor.focus();
}

function process_paste() {
    undo_push(areaeditor.value);    
    areaeditor.focus();
}



Google Chart Js Function


function GoogleChart(id, title, tcolor, tsize, type, bwidth, labels, legends, colors, bgfill, width, height, data)
		{
		   var types =
		   {
		      'line'    : 'lc',
		      'vbar'    : 'bvg',
		      'hbar'    : 'bhg',
		      'gometer' : 'gom',
		      'pie'     : 'p',
		      'pie3d'   : 'p3',
		      'venn'    : 'v',
		      'radar'   : 'r'
		   }

		   if (typeof type == undefined) type = 'pie'

		   var t1                     = escape(title)
		   var t2                     = types[type]
		   var tail                   = 'chtt='          + t1
		                              + '&cht='      + t2
		                              + '&chs='      + width  + 'x' + height
		                              + '&chbh='     + bwidth
		                              + '&chxt=x,y'
		                              + '&chd=t:'    + data

		   if (tcolor && tsize) tail += '&chts='     + tcolor + ',' + tsize
		   if (labels)          tail += '&chl='      + labels
		   if (legends)         tail += '&chdl='     + legends
		   if (colors)          tail += '&chco='     + colors
		   if (bgfill)          tail += '&chf=bg,s,' + bgfill

		   Htmlgraft(id, "")
		}
function Htmlgraft(id, value) {
   if (typeof value != undefined);
     document.getElementById(id).innerHTML = value;
   return document.getElementById(id).innerHTML;
}



Google cloud print Magento

Oggi voglio condividere con te il bottone Google Cloud Print un utile snippet da integrare nella piattaforma e-commerce magento che permette agli utenti di poter stampare la scheda dei prodotti ovunque si trovano con la propria stampante. Ecco la presentazione del prodotto offerto da Google clicca quì. Per scaricare il codice entra nella consueta pagina download del mio sito e clicca sul link GCP_magento per il dowonload, all’interno del file trovi tutte le indicazioni per la corretta integrazione in magento.