Changeset 630
- Timestamp:
- 01/04/07 11:56:20 (6 years ago)
- Location:
- trunk/plugins/InsertSnippet
- Files:
-
- 2 added
- 1 removed
- 3 modified
-
demosnippets.js (added)
-
insert-snippet.js (modified) (4 diffs)
-
popups/insertsnippet.html (modified) (4 diffs)
-
readme.html (added)
-
snippets.js (deleted)
-
snippets.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/plugins/InsertSnippet/insert-snippet.js
r442 r630 5 5 Insert HTML fragments or template variables 6 6 7 Usage:8 1. Choose the file that contains the snippets9 You can either use a JS array (standard config: ./snippets.js) or a combination of PHP/HTML10 where the PHP file reads the HTML file and converts it to a JS format. More convenient to maintain.11 Example: xinha_config.InsertSnippet.snippets = _editor_url+"plugins/InsertSnippet/snippets.php"12 or13 xinha_config.InsertSnippet.snippets = "/Path/to/my/snippets.php" (has to be absolute)14 2. Edit the selected file to contain your stuff15 3. You can then include your own css16 Example: xinha_config.InsertSnippet.css = ['../../../CSS/Screen.css']; (may be relative)17 4. You can use the plugin also to insert template variables (i.e. the id in curly brackets) instead of static HTML.18 Set xinha_config.InsertSnippet.showInsertVariable true to display a choice option in the dialog19 20 7 \*------------------------------------------*/ 21 8 … … 37 24 }); 38 25 cfg.addToolbarElement("insertsnippet", "insertimage", -1); 26 this.snippets = null; 27 var backend = cfg.InsertSnippet.snippets + '?'; 28 29 if(cfg.InsertSnippet.backend_data != null) 30 { 31 for ( var i in cfg.InsertSnippet.backend_data ) 32 { 33 backend += '&' + i + '=' + encodeURIComponent(cfg.InsertSnippet.backend_data[i]); 34 } 35 } 36 HTMLArea._getback(backend,function (getback) {eval(getback); self.snippets = snippets;}); 37 } 38 39 InsertSnippet.prototype.onUpdateToolbar = function() { 40 if (!this.snippets){ 41 this.editor._toolbarObjects.insertsnippet.state("enabled", false); 42 } 43 else InsertSnippet.prototype.onUpdateToolbar = null; 39 44 } 40 45 41 46 InsertSnippet._pluginInfo = { 42 47 name : "InsertSnippet", 43 version : "1. 1",48 version : "1.2", 44 49 developer : "Raimund Meyer", 45 50 developer_url : "http://rheinauf.de", 46 51 c_owner : "Raimund Meyer", 47 sponsor : " Raimund Meyer",48 sponsor_url : " http://ray-of-light.org/",52 sponsor : "", 53 sponsor_url : "", 49 54 license : "htmlArea" 50 55 }; … … 68 73 HTMLArea.Config.prototype.InsertSnippet = 69 74 { 70 'snippets' : _editor_url+"plugins/InsertSnippet/snippets.js", 71 'css' : ['../InsertSnippet.css'], 72 'showInsertVariable': false 75 'snippets' : _editor_url+"plugins/InsertSnippet/demosnippets.js", // purely demo purposes, you should change this 76 'css' : ['../InsertSnippet.css'], //deprecated, CSS is now pulled from xinha_config 77 'showInsertVariable': false, 78 'backend_data' : null 73 79 }; 74 80 75 81 InsertSnippet.prototype.buttonPress = function(editor) { 76 82 var args = editor.config; 83 args.snippets = this.snippets; 84 var self = this; 77 85 editor._popupDialog( "plugin://InsertSnippet/insertsnippet", function( param ) { 78 86 … … 81 89 } 82 90 83 eval(HTMLArea._geturlcontent(editor.config.InsertSnippet.snippets));91 84 92 editor.focusEditor(); 85 93 if (param['how'] == 'variable') { 86 editor.insertHTML('{'+s nippets[param["snippetnum"]].id+'}');94 editor.insertHTML('{'+self.snippets[param["snippetnum"]].id+'}'); 87 95 } else { 88 editor.insertHTML(s nippets[param["snippetnum"]].HTML);96 editor.insertHTML(self.snippets[param["snippetnum"]].HTML); 89 97 } 90 98 -
trunk/plugins/InsertSnippet/popups/insertsnippet.html
r439 r630 1 <html> 2 <head> 1 <!DOCTYPE html 2 PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 3 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 4 5 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 3 6 <title>Insert Snippet</title> 4 7 <link rel="stylesheet" type="text/css" href="../../../popups/popup.css" /> 8 <link rel="stylesheet" type="text/css" href="../InsertSnippet.css" /> 5 9 <script type="text/javascript" src="../../../popups/popup.js"></script> 6 10 <script type="text/javascript"> … … 8 12 var InsertSnippet = window.opener.InsertSnippet; 9 13 var editor = null; 10 var config; 14 11 15 12 16 function Init() { 13 __dlg_translate("InsertSnippet");14 __dlg_init();15 16 var config = window.dialogArguments;17 __dlg_translate("InsertSnippet"); 18 __dlg_init(null, {width:800,height:600}); 19 20 var config = window.dialogArguments; 17 21 18 eval(HTMLArea._geturlcontent(config.InsertSnippet.snippets)); 19 20 if (config.InsertSnippet.css.length > 0) 21 { 22 for (var i=0;i< config.InsertSnippet.css.length;i++) 23 { 24 var style = document.createElement("link"); 25 style.rel = 'stylesheet'; 26 style.href = config.InsertSnippet.css[i]; 27 document.getElementsByTagName("HEAD")[0].appendChild(style); 28 } 29 } 22 var snippets = config.snippets; 23 24 if ( config.pageStyle && !HTMLArea.is_ie) 25 { 26 var style = document.createElement("style"); 27 style.type = "text/css"; 28 style.innerHTML = config.pageStyle; 29 document.getElementsByTagName("HEAD")[0].appendChild(style); 30 } 31 32 if ( typeof config.pageStyleSheets !== 'undefined' ) 33 { 34 for ( var i = 0; i < config.pageStyleSheets.length; i++ ) 35 { 36 var style = document.createElement("link"); 37 style.type = "text/css"; 38 style.rel = 'stylesheet'; 39 style.href = config.pageStyleSheets[i]; 40 document.getElementsByTagName("HEAD")[0].appendChild(style); 41 } 42 } 43 44 var tbody = document.getElementById("snippettable"); 45 var snippet_html; 46 var snippet_name; 47 var trow; 48 for(var i = 0; i < snippets.length; i++) 49 { 50 trow = tbody.insertRow(i); 51 snippet_html = snippets[i]['HTML']; 52 snippet_name = snippets[i]['id']; 53 54 var insertAsVariable = ''; 55 if (config.InsertSnippet.showInsertVariable) 56 { 57 insertAsVariable = ' | <a href="javascript:onOK('+i+','+'\'variable\''+')">'+HTMLArea._lc("Variable","InsertSnippet")+'</a>'; 58 } 59 var new_cell = trow.insertCell(0); 60 new_cell.innerHTML = snippet_name +': '+HTMLArea._lc("Insert as","InsertSnippet")+' <a href="javascript:onOK('+i+','+'\'html\''+')">HTML</a>'+insertAsVariable + ' (<a id="show_preview'+i+'" href="javascript:preview(\'show\','+i+')">'+HTMLArea._lc("Show preview","InsertSnippet")+'</a>)<div id="preview'+i+'" style="display:none">'+snippets[i]['HTML']+'</div>'; 61 new_cell.id = 'cell' + i; 62 63 } 30 64 31 window.resizeTo(800, 600); 32 window.moveTo(80, 80); 33 var tbody = document.getElementById("snippettable"); 34 var snippet_html; 35 var snippet_name; 36 var trow; 37 for(var i = 0; i < snippets.length; i++) 38 { 39 trow = tbody.insertRow(i); 40 snippet_html = snippets[i]['HTML']; 41 snippet_name = snippets[i]['id']; 42 43 var insertAsVariable = ''; 44 if (config.InsertSnippet.showInsertVariable) 45 { 46 insertAsVariable = ' | <a href="javascript:onOK('+i+','+'\'variable\''+')">'+HTMLArea._lc("Variable","InsertSnippet")+'</a>'; 47 } 48 var new_cell = trow.insertCell(0); 49 new_cell.innerHTML = snippet_name +': '+HTMLArea._lc("Insert as","InsertSnippet")+' <a href="javascript:onOK('+i+','+'\'html\''+')">HTML</a>'+insertAsVariable + ' (<a id="show_preview'+i+'" href="javascript:preview(\'show\','+i+')">'+HTMLArea._lc("Show preview","InsertSnippet")+'</a>)<div id="preview'+i+'" style="display:none">'+snippets[i]['HTML']+'</div>'; 50 new_cell.id = 'cell' + i; 51 52 } 53 54 document.body.onkeypress = __dlg_key_press; 65 document.body.onkeypress = __dlg_key_press; 55 66 } 56 67 … … 73 84 } 74 85 function onCancel() { 75 __dlg_close(null);76 return false;86 __dlg_close(null); 87 return false; 77 88 } 78 89 79 90 function onOK(snippetnum,how) { 80 var params = new Object();81 params["snippetnum"] = snippetnum;82 params["how"] = how;83 __dlg_close(params);84 return false;91 var params = new Object(); 92 params["snippetnum"] = snippetnum; 93 params["how"] = how; 94 __dlg_close(params); 95 return false; 85 96 } 86 97 87 98 function __dlg_key_press(ev) { 88 ev || (ev = window.event);89 switch(ev.keyCode) {90 case 13:91 document.getElementById('bt_ok').click();92 break;93 case 27:94 __dlg_close();95 return false;96 }99 ev || (ev = window.event); 100 switch(ev.keyCode) { 101 case 13: 102 document.getElementById('bt_ok').click(); 103 break; 104 case 27: 105 __dlg_close(); 106 return false; 107 } 97 108 return true; 98 109 } … … 106 117 </style> 107 118 </head> 108 <body class="dialog" onload="Init()">119 <body class="dialog" onload="Init()"> 109 120 <form action="" method="get"> 110 121 <div class="title" >Insert Snippet</div> -
trunk/plugins/InsertSnippet/snippets.php
r439 r630 1 var snippets = new Array();2 var i = 0;3 1 <?php 2 $snippets_file = 'snippets.html'; 4 3 5 function get_all_parts($string) 4 include_once('../../contrib/php-xinha.php'); 5 6 if($passed_data = xinha_read_passed_data()) 6 7 { 7 preg_match_all('#<!--(.*?)-->(.*?)<!--/.*?-->#s',$string,$matches); 8 extract($passed_data); 9 } 10 $snippets = file_get_contents($snippets_file); 11 preg_match_all('/<!--(.*?)-->(.*?)<!--\/.*?-->/s',$snippets,$matches); 8 12 9 $array=array();10 for ($i=0;$i<count($matches[1]);$i++)11 {12 $array[$matches[1][$i]] = $matches[2][$i];13 }14 return $array;13 $array=array(); 14 for ($i=0;$i<count($matches[1]);$i++) 15 { 16 $id = $matches[1][$i]; 17 $html = $matches[2][$i]; 18 $array[] = array('id'=>$id,'HTML'=>$html); 15 19 } 16 $snippets = file_get_contents('snippets.html'); 17 18 $matches = get_all_parts($snippets); 19 foreach ($matches as $name =>$html) 20 { 21 print "snippets[i] = new Object();\n"; 22 print "snippets[i]['id'] = '$name';\n"; 23 print "snippets[i]['HTML'] = '".str_replace("\n",'\n',addcslashes($html,"'"))."';\n"; 24 print "i++;\n"; 25 } 20 print "var snippets = " . xinha_to_js($array); 26 21 27 22 ?>
