tinyMCE.init({
// General options
mode: "textareas",
theme: "advanced",
plugins: "autolink,lists,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,wordcount,advlist,autosave,visualblocks",
// Theme options
theme_advanced_buttons1: "|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
theme_advanced_buttons2: "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
theme_advanced_buttons3: "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
theme_advanced_buttons4: "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak,restoredraft,visualblocks",
theme_advanced_toolbar_location: "top",
theme_advanced_toolbar_align: "left",
theme_advanced_statusbar_location: "bottom",
theme_advanced_resizing: true,
// Example content CSS (should be your site CSS)
content_css: "css/content.css",
// Drop lists for link/image/media/template dialogs
template_external_list_url: "lists/template_list.js",
external_link_list_url: "lists/link_list.js",
external_image_list_url: "/ajax/am/get-list-image.js",
media_external_list_url: "lists/media_list.js",
// Style formats
style_formats: [
{title: 'Bold text', inline: 'b'},
{title: 'Red text', inline: 'span', styles: {color: '#ff0000'}},
{title: 'Red header', block: 'h1', styles: {color: '#ff0000'}},
{title: 'Example 1', inline: 'span', classes: 'example1'},
{title: 'Example 2', inline: 'span', classes: 'example2'},
{title: 'Table styles'},
{title: 'Table row 1', selector: 'tr', classes: 'tablerow1'}
],
// document_base_url: "/static/image/product/",
convert_urls: false,
height: 450,
width: 730
});
/ajax/am/get-list-image.js
var tinyMCEImageList = new Array(
["/static/image/product/338.jpg", "/static/image/product/338.jpg"],
["/static/image/product/339.jpg", "/static/image/product/339.jpg"],
["/static/image/product/thumb_645.jpg", "/static/image/product/thumb_645.jpg"],
["thumb_646.jpg", "/static/image/product/thumb/thumb_646.jpg"]);
get-list-image.php ( PHP script text )
<?php
// You can't simply echo everything right away because we need to set some headers first!
$output = ''; // Here we buffer the JavaScript code we want to send to the browser.
$delimiter = "\n"; // for eye candy... code gets new lines
$output .= 'var tinyMCEImageList = new Array(';
$directory = APPLICATION_PATH . "/static/image/product"; // Use your correct (relative!) path here
function dirToArray($dir) {
$result = array();
$cdir = scandir($dir);
foreach ($cdir as $key => $value) {
if (!in_array($value, array(".", ".."))) {
if (is_dir($dir . DIRECTORY_SEPARATOR . $value)) {
$result[$value] = dirToArray($dir . DIRECTORY_SEPARATOR . $value);
} else {
$result[] = $value;
}
}
}
return $result;
}
$list_image = (dirToArray($directory));
//foreach ($list_image as $image) {
//// echo $image."<br/>";
// $output .= $delimiter
// . '["'
// . $image
// . '", "'
// . '\static\image\product\\thumb' . $image
// . '"],';
//}
$total = count($list_image);
for ($i = 0; $i < $total - 1; $i++) {
$output .= $delimiter
. '["'
. '/static/image/product/'. $list_image[$i]
. '", "'
. '/static/image/product/'. $list_image[$i]
. '"],';
}
$output .= $delimiter
. '["'
. $list_image[$total - 1]
. '", "'
. '/static/image/product/thumb/' . $list_image[$total - 1]
. '"]';
// Finish code: end of array definition. Now we have the JavaScript code ready!
$output .= ');';
// Make output a real JavaScript file!
header('Content-type: text/javascript'); // browser will now recognize the file as a valid JS file
// prevent browser from caching
header('pragma: no-cache');
header('expires: 0'); // i.e. contents have already expired
// Now we can send data to the browser because all headers have been set!
echo $output;
Không có nhận xét nào:
Đăng nhận xét