Visualizzazione dei risultati da 1 a 3 su 3
  1. #1

    semplice WYSIWYG e libreria prototype

    Ciao!
    Vorrei riuscire a realizzare un semplice WYSIWYG.
    Ho bisogno del vostro aiuto

    Il primo step del mio piccolo progetto preve di creare un wysiwyg inizializzato con la frase "inserisci un testo"

    La prima cosa che devo fare è posizionare un iframe nella mia pagina web:
    codice:
    _addIframe: function(to) { //to = id tag
    		var ed = new Element('iframe');
    		ed.id = 'textEditor';
    		ed.setStyle({width:'100%',height:'100%'});
    		$(to).insert(ed);
                    $('textEditor').designMode="on";
    	},
    $('textEditor').designMode="on"; --> spero sia corretto...

    Ora devo inserire la stringa "inserisci un testo"
    codice:
    insert: function(str) { //str = 'inserisci un testo'
    		$('textEditor').innerHTML = str;
    	},
    non funziona!

    ora devo dare il focus all'iframe
    codice:
    ob: function() {
    		$('textEditor').focus();
    	},
    non funziona!

    Come posso risolvere?
    Devo capire come interagire con l'iframe, poi dovrei essere in grado di cavarmela da solo...

  2. #2
    Ok ho fatto qualche progresso, vi posto quello che ho fatto (potete provarlo).
    Qualcuno sa rispondere alle domande che ho scritto sotto forma di COMMENTI nel codice?
    Grazie!

    codice:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>prova</title>
    
    <script type="text/javascript" src="http://prototypejs.org/assets/2009/8/31/prototype.js"></script>
    
    <script type="text/javascript">
    
    Prototype.extendFrame = function(element) {
    	element = $(element);
    	for (var m in Element.Methods) {
    		if (Object.isFunction(Element.Methods[m])) {
    			element.contentWindow.Element.prototype[m] = Element.Methods[m].methodize();
    		}
    	}
    }
    
    var editor = Class.create();
    editor.prototype = {
    
    	initialize: function() {
    		this._ed = new Element('iframe');
    		this._ed.id = 'textEditor';
    		this._ed.setStyle({width:'100%',height:'100%'});
    		
    	},
    
    	_addIframe: function() {
    		$('content').insert(this._ed);
    		Prototype.extendFrame('textEditor');
    		alert("aaa"); // <-------------------------- SENZA QUESTO NON FUNZIONA!!!???
    		this._ed.contentDocument.designMode="on";
    		// ------------> NON FUNZIONA 'keypress' !!!???
    		Event.observe(this._ed.contentDocument.body, 'keypress', this.tastoPremuto);
    	},
    	
    	tastoPremuto: function(e) {
    		alert("---> "+e);
    	},
    	
    	getHTMLeditor: function() {
    		this._addIframe();
    		var p = new Element('p');
    		p.innerHTML = "inserisci testo";
    		$('textEditor').contentDocument.body.insert(p);
    		this._ed.focus();
    	}
    };
    
    
    function init() {
    	var edit = new editor();
    	edit.getHTMLeditor();
    }
    window.onload = init;
    </script>
    
    
    </head>
    <body>
    <div id="content"></div>
    </body>
    </html>

  3. #3

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.