[Commits] r1645 - in sandbox/cmoullet/ux/Printer: examples ux/layout
commits at geoext.org
commits at geoext.org
Sun Jan 3 08:51:58 CET 2010
Author: cmoullet
Date: 2010-01-03 08:51:58 +0100 (Sun, 03 Jan 2010)
New Revision: 1645
Added:
sandbox/cmoullet/ux/Printer/ux/layout/ExtPrinter.js
Modified:
sandbox/cmoullet/ux/Printer/examples/PrinterExample.html
sandbox/cmoullet/ux/Printer/examples/PrinterExample.js
sandbox/cmoullet/ux/Printer/examples/PrinterExampleWMS.html
sandbox/cmoullet/ux/Printer/ux/layout/LayoutPrinter.js
sandbox/cmoullet/ux/Printer/ux/layout/a4_portrait.html
Log:
Modified: sandbox/cmoullet/ux/Printer/examples/PrinterExample.html
===================================================================
--- sandbox/cmoullet/ux/Printer/examples/PrinterExample.html 2010-01-01 17:40:40 UTC (rev 1644)
+++ sandbox/cmoullet/ux/Printer/examples/PrinterExample.html 2010-01-03 07:51:58 UTC (rev 1645)
@@ -8,6 +8,7 @@
<script type="text/javascript" src="../../../trunk/geoext/lib/GeoExt.js"></script>
<script type="text/javascript" src="../ux/layout/LayoutStore.js"></script>
<script type="text/javascript" src="../ux/layout/LayoutPrinter.js"></script>
+ <script type="text/javascript" src="../ux/layout/ExtPrinter.js"></script>
<script type="text/javascript" src="../ux/widgets/PrinterPanel.js"></script>
<script type="text/javascript" src="../ux/widgets/PrinterWindow.js"></script>
<script type="text/javascript" src="PrinterExample.js"></script>
Modified: sandbox/cmoullet/ux/Printer/examples/PrinterExample.js
===================================================================
--- sandbox/cmoullet/ux/Printer/examples/PrinterExample.js 2010-01-01 17:40:40 UTC (rev 1644)
+++ sandbox/cmoullet/ux/Printer/examples/PrinterExample.js 2010-01-03 07:51:58 UTC (rev 1645)
@@ -6,11 +6,13 @@
var layer;
+var map;
+
Ext.onReady(function() {
- var layer = new OpenLayers.Layer.OSM("OSM");
+ layer = new OpenLayers.Layer.OSM("OSM");
- var map = new OpenLayers.Map();
+ map = new OpenLayers.Map();
var center = new OpenLayers.LonLat(738481, 5863900);
Modified: sandbox/cmoullet/ux/Printer/examples/PrinterExampleWMS.html
===================================================================
--- sandbox/cmoullet/ux/Printer/examples/PrinterExampleWMS.html 2010-01-01 17:40:40 UTC (rev 1644)
+++ sandbox/cmoullet/ux/Printer/examples/PrinterExampleWMS.html 2010-01-03 07:51:58 UTC (rev 1645)
@@ -8,6 +8,7 @@
<script type="text/javascript" src="../../../trunk/geoext/lib/GeoExt.js"></script>
<script type="text/javascript" src="../ux/layout/LayoutStore.js"></script>
<script type="text/javascript" src="../ux/layout/LayoutPrinter.js"></script>
+ <script type="text/javascript" src="../ux/layout/ExtPrinter.js"></script>
<script type="text/javascript" src="../ux/widgets/PrinterPanel.js"></script>
<script type="text/javascript" src="../ux/widgets/PrinterWindow.js"></script>
<script type="text/javascript" src="PrinterExampleWMS.js"></script>
Added: sandbox/cmoullet/ux/Printer/ux/layout/ExtPrinter.js
===================================================================
--- sandbox/cmoullet/ux/Printer/ux/layout/ExtPrinter.js (rev 0)
+++ sandbox/cmoullet/ux/Printer/ux/layout/ExtPrinter.js 2010-01-03 07:51:58 UTC (rev 1645)
@@ -0,0 +1,102 @@
+/**
+ * @version 0.4
+ * @author nerdydude81
+ */
+Ext.namespace("GeoExt.ux.layout");
+
+Ext.override(Ext.Element, {
+ /**
+ * @cfg {string} printCSS The file path of a CSS file for printout.
+ */
+ printCSS: null
+ /**
+ * @cfg {Boolean} printStyle Copy the style attribute of this element to the print iframe.
+ */
+ , printStyle: false
+ /**
+ * @property {string} printTitle Page Title for printout.
+ */
+ , printTitle: document.title
+ /**
+ * Prints this element.
+ *
+ * @param config {object} (optional)
+ */
+ , print: function(config) {
+ Ext.apply(this, config);
+
+ var el = Ext.get(this.id).dom;
+ var c = document.getElementById('printcontainer');
+ var iFrame = document.getElementById('printframe');
+
+ var strTemplate = '<HTML><HEAD>{0}<TITLE>{1}</TITLE></HEAD><BODY onload="{2}"><DIV {3}>{4}</DIV></BODY></HTML>';
+ var strLinkTpl = '<link rel="stylesheet" type="text/css" href="{0}"/>'
+ var strAttr = '';
+ var strFormat;
+ var strHTML;
+
+ //Get rid of the old crap so we don't copy it
+ //to our iframe
+ if (iFrame != null) c.removeChild(iFrame);
+ if (c != null) el.removeChild(c);
+
+ //Copy attributes from this element.
+ for (var i = 0; i < el.attributes.length; i++) {
+ if (Ext.isEmpty(el.attributes[i].value) || el.attributes[i].value.toLowerCase() != 'null') {
+ strFormat = Ext.isEmpty(el.attributes[i].value)? '{0}="true" ': '{0}="{1}" ';
+ if (this.printStyle? this.printStyle: el.attributes[i].name.toLowerCase() != 'style')
+ strAttr += String.format(strFormat, el.attributes[i].name, el.attributes[i].value);
+ }
+ }
+
+ var strLink ='';
+ if(this.printCSS){
+ if(!Ext.isArray(this.printCSS))
+ this.printCSS = [this.printCSS];
+
+ for(var i=0; i<this.printCSS.length; i++) {
+ strLink += String.format(strLinkTpl, this.printCSS[i]);
+ }
+ }
+
+ //Build our HTML document for the iframe
+ strHTML = String.format(
+ strTemplate
+ , strLink
+ , this.printTitle
+ , Ext.isIE? 'document.execCommand(\'print\');': 'window.print();'
+ , strAttr
+ , el.innerHTML
+ );
+
+ //I coun't get FF to print a hidden iframe,
+ //so I encapsulated it in a hidden div.
+ c = document.createElement('div');
+ c.setAttribute('style','width:0px;height:0px;' + (Ext.isSafari? 'display:none;': 'visibility:hidden;'));
+ c.setAttribute('id', 'printcontainer');
+ el.appendChild(c);
+
+ //IE doesn't like style attributes anymore?
+ if (Ext.isIE)
+ c.style.display = 'none';
+
+ iFrame = document.createElement('iframe');
+ iFrame.setAttribute('id', 'printframe');
+ iFrame.setAttribute('name', 'printframe');
+ c.appendChild(iFrame);
+
+ //Write our new document to the iframe
+ iFrame.contentWindow.document.open();
+ iFrame.contentWindow.document.write(strHTML);
+ iFrame.contentWindow.document.close();
+ }
+});
+
+Ext.override(Ext.Component, {
+ printEl: function(config) {
+ this.el.print(Ext.isEmpty(config)? this.initialConfig: config);
+ }
+ , printBody: function(config) {
+ this.body.print(Ext.isEmpty(config)? this.initialConfig: config);
+ }
+});
\ No newline at end of file
Modified: sandbox/cmoullet/ux/Printer/ux/layout/LayoutPrinter.js
===================================================================
--- sandbox/cmoullet/ux/Printer/ux/layout/LayoutPrinter.js 2010-01-01 17:40:40 UTC (rev 1644)
+++ sandbox/cmoullet/ux/Printer/ux/layout/LayoutPrinter.js 2010-01-03 07:51:58 UTC (rev 1645)
@@ -21,7 +21,14 @@
} else {
pageUrl = "../ux/layout/" + page;
}
- GeoExt.ux.layout.LayoutPrinter.printWindow = window.open(pageUrl, "_blank", "menubar=0,scrollbars=0,location=0,status=1,width=" + GeoExt.ux.layout.getPageWidth(GeoExt.ux.layout.LayoutPrinter.layout) + ",height=" + GeoExt.ux.layout.getPageHeight(GeoExt.ux.layout.LayoutPrinter.layout) + "");
+ if (Ext.isIE) {
+ // appendChild problem: http://tamentis.com/doc/no_such_interface/
+ alert('IE not supported (http://tamentis.com/doc/no_such_interface/). Please use Firefox !');
+ //var mapPanel = GeoExt.MapPanel.guess();
+ //mapPanel.printEl();
+ } else {
+ GeoExt.ux.layout.LayoutPrinter.printWindow = window.open(pageUrl, "_blank", "menubar=0,scrollbars=0,location=0,status=1,width=" + GeoExt.ux.layout.getPageWidth(GeoExt.ux.layout.LayoutPrinter.layout) + ",height=" + GeoExt.ux.layout.getPageHeight(GeoExt.ux.layout.LayoutPrinter.layout) + "");
+ }
};
GeoExt.ux.layout.LayoutPrinter.Apply = function(childWindow) {
@@ -57,6 +64,7 @@
childWindow.map.setOptions(options);
for (var i = 0; i < GeoExt.ux.layout.LayoutPrinter.map.layers.length; i++) {
var layer = GeoExt.ux.layout.LayoutPrinter.map.layers[i];
+
// Clone the vector features
if (layer instanceof OpenLayers.Layer.Vector) {
var vectorLayer = new OpenLayers.Layer.Vector();
Modified: sandbox/cmoullet/ux/Printer/ux/layout/a4_portrait.html
===================================================================
--- sandbox/cmoullet/ux/Printer/ux/layout/a4_portrait.html 2010-01-01 17:40:40 UTC (rev 1644)
+++ sandbox/cmoullet/ux/Printer/ux/layout/a4_portrait.html 2010-01-03 07:51:58 UTC (rev 1645)
@@ -19,7 +19,7 @@
width: 770px;
height: 970px;
}
-
+
#copyright {
position: absolute;
bottom: 5px;
@@ -30,7 +30,7 @@
display: none;
}
</style>
- <script type="text/javascript" src="../../../../trunk/openlayers/lib/OpenLayers.js"></script>
+ <script type="text/javascript" src="http://openlayers.org/api/2.8/OpenLayers.js"></script>
<script type="text/javascript">
var map;
function init() {
More information about the Commits
mailing list