ruạṛ
/* Fire it up */ $(document).ready(function() { /* ajax status updates on .toggle elements */ setup_ajax_toggle(); /* * set up tabs on pages not containing a tinymce instance * has to be done after tinymce or tab navigation breaks */ setup_tabs('.tabs'); /* wysiwyg editor */ start_tinymce3('content'); start_tinymce3('product_description'); /* inline .control-panel editable fields */ setup_inline_editing(); /* set up select_on-focus fields */ $("input.select_on_focus").focus(function(){ $(this).select(); }); /* initialise datepickers */ $('input.date').datepicker({dateFormat: 'yy-mm-dd'}); /* initialise colorbox */ $("a[rel=gallery]").colorbox(); /* set up autocompletes */ $('#select_product_name').autocomplete({ source: '/admin/ajax/autocomplete-product-path.php' , minLength: 2 , select: function(event, ui){ $('#select_product_name').val(ui.item.label) $('#assoc_id').val(ui.item.value); return false; } }); $('#find_product').autocomplete({ source: '/admin/ajax/autocomplete-product-name.php' , minLength: 2 , select: function(event, ui){ $('#find_product').val(ui.item.label) $('#prod').val(ui.item.value); return false; } }); setupPageCompression(); return; }); /* * add ajax submissision and message catching to .toggle elements * @todo make this more generic */ function setup_ajax_toggle(){ $('.toggle').click(function(e){ e.preventDefault(); //console.log(e); $('body').addClass('waiting'); t = e.currentTarget; $.ajax({ url: e.currentTarget.href , success: function(state){ //console.log(state); if(state.match(/^<span .*<\/span>$/)) { $(t).html(state); } else { $('#message').html(state); $( "#message" ).dialog({ modal: true, buttons: { Ok: function() { $( this ).dialog( "close" ); } } }); } $('body').removeClass('waiting'); } }); }); } /* * set up tabs */ function setup_tabs(wrapper){ $allTabs = $(wrapper+'>div'); if($allTabs.length > 0) { $activeTab = $allTabs.filter('.active'); if($activeTab.length > 0) { $activeTab = $activeTab.first(); activeIndex = $allTabs.index($activeTab); } else { activeIndex = 0; } $(wrapper).tabs({active: activeIndex}); //$('.tabs').tabs({collapsible: true, active: false}); /* $('.tabs').tabs(); active = $( ".tabs" ).tabs( "option", "active" ); console.log(active); $( ".tabs>div" ).tabs( "option", "active", 1 ); active = $( ".tabs>div" ).tabs( "option", "active" ); console.log(active); */ } } /* * set up interface enhancements on .control_table editable fields * - remember initial value * - highlight changed * - highlight save button * @todo warning on leaving page */ function setup_inline_editing(){ $('input.inline-editing').focus(function(){ console.log($(this).data('oValue')); if($(this).data('oValue')==undefined) { $(this).data('oValue',$(this).val()); } }).blur(function(){ v = $(this).val(); o = $(this).data('oValue'); if(v==''){ $(this).val(o); } else if(v != o) { $(this).addClass('changed'); $('input.update').addClass('remind'); } }); } /** * set up editor */ function start_tinymce3(bodyClass){ /* initialise tinymce instances */ $('textarea.editor.'+bodyClass).tinymce({ // Location of TinyMCE script script_url : 'tiny_mce3/tiny_mce.js', // General options theme : "advanced", plugins : "autolink,lists,style,layer,table,advhr,advimage,advlink,inlinepopups,preview,media,searchreplace,print,contextmenu,paste,fullscreen,visualchars,nonbreaking,xhtmlxtras,advlist,autosave,jmform", dialog_type : "modal", file_browser_callback : "tinyBrowser", relative_urls: false, //form plugin extended_valid_elements : "form[name|id|action|method|enctype|accept-charset|onsubmit|onreset|target|class],input[id|name|type|value|size|maxlength|checked|accept|src|width|height|disabled|readonly|tabindex|accesskey|onfocus|onblur|onchange|onselect|onclick|onkeyup|onkeydown|required|style|class|placeholder],textarea[id|name|rows|cols|maxlength|disabled|readonly|tabindex|accesskey|onfocus|onblur|onchange|onselect|onclick|onkeyup|onkeydown|required|style|class|placeholder],option[name|id|value|selected|style|class],select[id|name|type|value|size|maxlength|checked|width|height|disabled|readonly|tabindex|accesskey|onfocus|onblur|onchange|onselect|onclick|multiple|style|class],th[*],thead[*],tfoot[*]", // Theme options theme_advanced_buttons1 : "code,fullscreen,preview,|,undo,redo,|,cut,copy,paste,pastetext,pasteword,|,link,unlink,anchor,image,media,advhr,charmap,|,visualaid,visualchars,nonbreaking,|,search,replace,|,removeformat,cleanup,help", theme_advanced_buttons2 : "tablecontrols,|,bullist,numlist,|,jmform,jmform_insert_input,jmform_insert_select,jmform_insert_textarea,jmform_delete,|,insertlayer,moveforward,movebackward,absolute,|,styleprops,attribs", theme_advanced_buttons3 : "formatselect,fontselect,fontsizeselect,|,forecolor,backcolor,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,outdent,indent,blockquote,|,sub,sup", //styleselect, //theme_advanced_buttons4 : "", theme_advanced_toolbar_location : "top", theme_advanced_toolbar_align : "left", theme_advanced_statusbar_location : "bottom", theme_advanced_resizing : false, // Example content CSS (should be your site CSS) content_css : "/resources/template/style.css", body_class : bodyClass // 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 : "lists/image_list.js", media_external_list_url : "lists/media_list.js", */ }); } function start_tinymce_bk(){ /* initialise tinymce instances */ $('textarea.tinymce').tinymce({ // Location of TinyMCE script script_url : 'tiny_mce/tiny_mce.js', valid_children : "+a[*]", // General options theme : "advanced", plugins : "autolink,lists,style,layer,table,advhr,advimage,advlink,inlinepopups,preview,media,searchreplace,print,contextmenu,paste,fullscreen,visualchars,nonbreaking,xhtmlxtras,advlist,autosave,jmform", dialog_type : "modal", file_browser_callback : "tinyBrowser", relative_urls: false, //form plugin extended_valid_elements : "form[name|id|action|method|enctype|accept-charset|onsubmit|onreset|target|class],input[id|name|type|value|size|maxlength|checked|accept|src|width|height|disabled|readonly|tabindex|accesskey|onfocus|onblur|onchange|onselect|onclick|onkeyup|onkeydown|required|style|class|placeholder],textarea[id|name|rows|cols|maxlength|disabled|readonly|tabindex|accesskey|onfocus|onblur|onchange|onselect|onclick|onkeyup|onkeydown|required|style|class|placeholder],option[name|id|value|selected|style|class],select[id|name|type|value|size|maxlength|checked|width|height|disabled|readonly|tabindex|accesskey|onfocus|onblur|onchange|onselect|onclick|multiple|style|class],th[*],thead[*],tfoot[*]", // Theme options theme_advanced_buttons1 : "code,fullscreen,preview,|,undo,redo,|,cut,copy,paste,pastetext,pasteword,|,link,unlink,anchor,image,media,advhr,charmap,|,visualaid,visualchars,nonbreaking,|,search,replace,|,removeformat,cleanup,help", theme_advanced_buttons2 : "tablecontrols,|,bullist,numlist,|,jmform,jmform_insert_input,jmform_insert_select,jmform_insert_textarea,jmform_delete,|,insertlayer,moveforward,movebackward,absolute,|,styleprops,attribs", theme_advanced_buttons3 : "formatselect,fontselect,fontsizeselect,|,forecolor,backcolor,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,outdent,indent,blockquote,|,sub,sup", //styleselect, //theme_advanced_buttons4 : "", theme_advanced_toolbar_location : "top", theme_advanced_toolbar_align : "left", theme_advanced_statusbar_location : "bottom", theme_advanced_resizing : false, // Example content CSS (should be your site CSS) content_css : "/resources/template/style.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 : "lists/image_list.js", media_external_list_url : "lists/media_list.js", */ body_class : "content" }); } /** IE handling functions **/ function getInternetExplorerVersion() // Returns the version of Internet Explorer or a -1 // (indicating the use of another browser). { var rv = -1; // Return value assumes failure. if (navigator.appName == 'Microsoft Internet Explorer') { var ua = navigator.userAgent; var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})"); if (re.exec(ua) != null) rv = parseFloat( RegExp.$1 ); } return rv; } function setupIE() { $('body').addClass('ie'); $('.control_panel td:nth-child(0n+2)').addClass('left'); $('.control_panel th:nth-child(0n+2)').addClass('left'); $('.control_panel .page:nth-child(2n) tr').addClass('alt'); $('.control_panel .articles td:nth-child(0n+2)').addClass('indent'); $('.control_panel .articles tr:nth-child(2n)').addClass('alt'); $('.control_panel .gallery tr:nth-child(2n)').addClass('alt'); $('.images tr:nth-child(2n)').addClass('alt'); } setupPageCompression() { var tierElements = $("tbody.page"); tierElements.each(function() { var tier = getTier($(this)); var nextElement = $(this).next(); var nextTier = getTier(nextElement); if(tier < nextTier && tier !== 0) { $(this).find("td:first-child").text("\u25B6"); $(this).css("cursor", "pointer"); var element = $(this); while(getTier($(this)) < getTier(element.next())) { element.next().hide(); element = element.next(); } $(this).click(function() { var visibility = nextElement.is(":visible"); var element = $(this); while(tier < getTier(element.next())) { if(visibility) { element.next().fadeOut(); $(this).find("td:first-child").text("\u25B6"); if(element.find("td:first-child").text() === "\u25BC") { element.find("td:first-child").text("\u25B6"); } } else { if(tier === getTier(element.next()) - 1) { element.next().fadeIn(); } $(this).find("td:first-child").text("\u25BC"); } element = element.next(); } }); } }); }
cải xoăn