Changeset 3250 for libcaca


Ignore:
Timestamp:
Nov 3, 2008, 10:48:16 PM (11 years ago)
Author:
bsittler
Message:

use some javascript to show inline previews using <iframe/> for some
of the formats (so far, html, html3, bbfr, and svg)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/caca-php/examples/www/export.php

    r3249 r3250  
    3939<title>libcaca export test program</title>
    4040<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
     41<script type="text/javascript">
     42/*<![CDATA[*/
     43update_preview = function (select)
     44{
     45        var iframe_map = {
     46                'html': true,
     47                'html3': true,
     48                'bbfr': true,
     49                'svg': true
     50        };
     51        var e;
     52        try
     53        {
     54                var format = select.options[select.selectedIndex].value;
     55                var newLocation = 'about:blank';
     56                if (iframe_map[format])
     57                {
     58                        newLocation = self.location.pathname + '?format=' + encodeURIComponent(format);
     59                }
     60                self.frames[0].location = newLocation;
     61        }
     62        catch (e)
     63        {
     64                alert('e' + e);
     65        }
     66        return true;
     67};
     68/*]]>*/
     69</script>
    4170</head>
    42 <body>
    43 
    44 <form action="#" enctype="multipart/form-data" method="post">
     71<body onload="update_preview(document.forms.exportform.elements.format);">
     72
     73<form id="exportform" name="exportform" action="#" enctype="multipart/form-data" method="post">
    4574<label for="file">File:</label>
    4675<input name="file" type="file" /> <em>(optional)</em>
     
    4877<input type="submit" value="Export" />
    4978<label for="format">as</label>
    50 <select name="format" id="format">
     79<select name="format" id="format" onchange="update_preview(this);">
    5180<?php
    5281        foreach($exports as $format => $name)
     
    5988</select>
    6089</form>
     90<?php
     91$export_php = isset($_SERVER['SCRIPT_NAME'])
     92                ?
     93                $_SERVER['SCRIPT_NAME']
     94                :
     95                'export.php';
     96?><iframe name="preview" id="preview" src="<?= htmlspecialchars($export_php) ?>?format=html" width="820" height="620" style="margin: 0; padding: 0; border: none; width: 100%"></iframe>
    6197</body>
    6298</html>
Note: See TracChangeset for help on using the changeset viewer.