$(document).ready(function() { BigTreeCustomControls(); BigTreePageLoadHooks(); //BigTreeQuickLoader.init(); // !BigTree Quick Search $('nav.main form .qs_query').keyup(function(ev) { v = $(this).val(); if (v && ev.keyCode != 9) { //no tabs! $("#quick_search_results").load("admin_root/ajax/quick-search-results/", { query: v }, function() { $("#quick_search_results").show(); }); } else { $("#quick_search_results").hide().html(""); } }).focus(function() { $(this).addClass("focus"); }).blur(function() { setTimeout("$('nav.main form input[type=\"search\"]').removeClass(\"focus\").val(\"\"); $(\"#quick_search_results\").fadeOut(200, function() { $(this).html(\"\"); });", 300); }); $("nav.main").on("click",".advanced_search",function() { $("#quick_search_results").parents().submit(); return false; }); // Subnav extras menu $("#sub_nav menu").hover(function() { $(this).parent().addClass("dropdown_open"); },function() { $(this).parent().removeClass("dropdown_open"); }); // Growl Hooks $("#growl").on("click",".close",function() { $(this).parents("article").remove(); return false; }); }); function BigTreeCustomControls(selector) { if (selector) { // Setup custom checkboxes $(selector).find("input[type=checkbox]").each(function() { if (!$(this).hasClass("custom_control") && $(this).css("display") != "none") { this.customControl = new BigTreeCheckbox(this); } }); // Setup custom select boxes $(selector).find("select:not([multiple])").each(function() { if (!$(this).hasClass("custom_control") && $(this).css("display") != "none") { this.customControl = new BigTreeSelect(this); } }); // Setup custom file boxes. $(selector).find("input[type=file]").each(function() { if (!$(this).hasClass("custom_control") && $(this).css("display") != "none") { this.customControl = new BigTreeFileInput(this); } }); // Setup custom radio buttons. $(selector).find("input[type=radio]").each(function() { if (!$(this).hasClass("custom_control") && $(this).css("display") != "none") { this.customControl = new BigTreeRadioButton(this); } }); } else { // Setup custom checkboxes $("input[type=checkbox]").each(function() { if (!$(this).hasClass("custom_control") && $(this).css("display") != "none") { this.customControl = new BigTreeCheckbox(this); } }); // Setup custom select boxes $("select:not([multiple])").each(function() { if (!$(this).hasClass("custom_control") && $(this).css("display") != "none") { this.customControl = new BigTreeSelect(this); } }); // Setup custom file boxes. $("input[type=file]").each(function() { if (!$(this).hasClass("custom_control") && $(this).css("display") != "none") { this.customControl = new BigTreeFileInput(this); } }); // Setup custom radio buttons. $("input[type=radio]").each(function() { if (!$(this).hasClass("custom_control") && $(this).css("display") != "none") { this.customControl = new BigTreeRadioButton(this); } }); } } function BigTreePageLoadHooks() { // !BigTree Link Finder $("#link_finder").keyup(function() { q = $(this).val(); if (q == "") { $("#link_finder_results").hide().html(""); } else { $("#link_finder_results").load("admin_root/ajax/link-finder/", { query: q }, function() { $("#link_finder_results").show().children("a").click(function() { return false; }); }); } }); // !BigTree Sticky Controls BigTree.stickyControls = $(".sticky_controls"); if (BigTree.stickyControls.length) { BigTree.stickyControlsTop = BigTree.stickyControls.offset().top; if (window.scrollY >= BigTree.stickyControlsTop && !BigTree.stickyControlsStuck) { BigTree.stickyControlsStuck = true; BigTree.stickyControls.addClass("stuck"); } $(window).scroll(function() { if (window.scrollY >= BigTree.stickyControlsTop && !BigTree.stickyControlsStuck) { BigTree.stickyControlsStuck = true; BigTree.stickyControls.addClass("stuck"); } if (window.scrollY < BigTree.stickyControlsTop && BigTree.stickyControlsStuck) { BigTree.stickyControlsStuck = false; BigTree.stickyControls.removeClass("stuck"); } }); } // Property Block Hide/Show $("h3.properties").click(function() { if ($(this).find(".icon_small").hasClass("icon_small_caret_right")) { // Set a cookie to keep it open next time. $.cookie("bigtree_admin[page_properties_open]","on", { expires: 365, path: "/" }); } else { $.cookie("bigtree_admin[page_properties_open]","", { path: "/" }); } $(this).find(".icon_small").toggleClass("icon_small_caret_right").toggleClass("icon_small_caret_down"); $(".property_block").toggle().next().toggle(); return false; }); $(".inset_block .hide").click(function() { id = $(this).attr("data-id"); $.cookie("bigtree_admin[ignore_view_description][" + id + "]","on", { expires: 365, path: "/" }); $(this).parent().hide(); }); // Tooltips $(".has_tooltip").each(function() { width = BigTree.WindowWidth(); offset = $(this).offset(); if (offset.left > (width / 2)) { position = "left"; } else { position = "right"; } new BigTreeToolTip($(this),$(this).attr("data-tooltip"),position,false,true); }); // Image views $(".image_list img").load(function() { w = $(this).width(); h = $(this).height(); if (w > h) { perc = 108 / w; h = perc * h; style = { margin: Math.floor((108 - h) / 2) + "px 0 0 0" }; } else { style = { margin: "0px" }; } $(this).css(style); }); BigTree.FormHooks(".container form"); } var BigTreePasswordInput = Class.extend({ Buffer: "", Element: false, FakeElement: false, Timer: false, init: function(element) { this.FakeElement = $('').attr("tabindex",$(element).attr("tabindex")); // Copy class name over this.FakeElement.get(0).className = $(element).get(0).className; this.Element = $(element).addClass("custom_control").removeClass("required"); this.Element.hide().after(this.FakeElement); this.FakeElement.on("blur",$.proxy(this.blur,this)) .on("focus",$.proxy(this.focus,this)) .on("change",$.proxy(this.change,this)); }, blur: function() { this.Buffer = this.FakeElement.val(); this.FakeElement.val(str_repeat("•",this.FakeElement.val().length)); }, change: function() { this.Element.val(this.FakeElement.val()); }, focus: function() { this.FakeElement.val(this.Buffer); } }); // !BigTreeCheckbox Class var BigTreeCheckbox = Class.extend({ Element: false, Link: false, init: function(element,text) { this.Element = $(element); if (this.Element.hasClass("custom_control")) { return false; } this.Element.addClass("custom_control"); div = $("
").addClass("checkbox"); a = $("").attr("href","#checkbox"); a.click($.proxy(this.click,this)); a.focus($.proxy(this.focus,this)); a.blur($.proxy(this.blur,this)); a.keydown($.proxy(this.keydown,this)); this.Element.next("label").click($.proxy(this.click,this)); if (element.checked) { a.addClass("checked"); } if (element.disabled) { a.addClass("disabled"); a.attr("tabindex","-1"); } if (element.tabIndex) { a.attr("tabindex",element.tabIndex); } this.Link = a; div.append(a); $(element).hide().after(div); }, focus: function() { if (!this.Element.prop("disabled")) { this.Link.addClass("focused"); } }, blur: function() { this.Link.removeClass("focused"); }, keydown: function(event) { if (event.keyCode == 32) { $.proxy(this.click,this)(); return false; } }, click: function() { if (!this.Element.prop("disabled")) { if (this.Link.hasClass("checked")) { this.Link.removeClass("checked"); this.Element.prop("checked",false); } else { this.Link.addClass("checked"); this.Element.prop("checked",true); } this.Element.triggerHandler("click"); this.Element.triggerHandler("change"); } return false; }, disable: function() { this.Link.addClass("disabled"); this.Element.prop("disabled",true); }, enable: function() { this.Link.removeClass("disabled"); this.Element.removeAttr("disabled"); } }); // !BigTreeSelect Class var BigTreeSelect = Class.extend({ BoundWindowClick: false, BoundOverflowScroll: false, Container: false, Element: false, Open: false, Options: [], WasRelative: false, init: function(element) { this.Element = $(element); if (this.Element.hasClass("custom_control")) { return false; } this.Element.addClass("custom_control"); // WebKit likes to freak out when we focus a position: absolute to the new value this.Element.val(el.attr("data-value")); // Update the selected state of the custom dropdown this.Container.find("span").html('
' + el.html()); this.Container.find("a").removeClass("active"); el.addClass("active"); // Close the dropdown this.close(); // Tell the ',$.proxy(this.saveNewFile,this),"caption"); } else { this.saveNewFile({ caption: "" }); } return false; }, deletePhoto: function() { new BigTreeDialog("Remove Photo",'

Are you sure you want to remove this photo?

',$.proxy(function() { $(this).parents("li").remove(); },this),"delete",false,"OK"); return false; }, editPhoto: function(ev) { link = $(ev.target); this.activeCaption = link.siblings(".caption"); new BigTreeDialog("Image Caption",'
',$.proxy(this.saveCaption,this),"caption"); return false; }, saveCaption: function(data) { this.activeCaption.val(data.caption); this.activeCaption = false; }, saveNewFile: function(data) { if (this.disableCaptions) { li = $('
  • ').html('
    Awaiting Uploading
    '); } else { li = $('
  • ').html('
    Awaiting Uploading
    '); } li.append(this.fileInput.hide()); li.append($('').val(data.caption)); this.container.find("ul").append(li); this.counter++; c = this.counter; new_file = $('').hide(); this.container.find(".file_wrapper").append(new_file); customControl = this.fileInput.get(0).customControl; new_file.get(0).customControl = customControl.connect(new_file.get(0)); this.fileInput.get(0).customControl = false; this.fileInput = new_file; }, openFileManager: function(ev) { target = $(ev.target); // In case they click the span instead of the button. if (!target.attr("href")) { field = target.parent().attr("href").substr(1); options = $.parseJSON(target.parent().attr("data-options")); } else { field = target.attr("href").substr(1); options = $.parseJSON(target.attr("data-options")); } BigTreeFileManager.formOpen("photo-gallery",field,options,$.proxy(this.useExistingFile,this)); return false; }, useExistingFile: function(path,caption,thumbnail) { li = $('
  • ').html('
    '); li.find("img").load(function() { w = $(this).width(); h = $(this).height(); if (w > h) { perc = 75 / w; h = perc * h; style = { margin: Math.floor((75 - h) / 2) + "px 0 0 0" }; } else { perc = 75 / h; w = perc * w; style = { margin: "0 0 0 " + Math.floor((75 - w) / 2) + "px" }; } $(this).css(style); }); li.append($('').val(path)); li.append($('').val(caption)); this.container.find("ul").append(li); this.counter++; c = this.counter; } }); // !BigTree Tag Adder Object var BigTreeTagAdder = { element: false, searching: false, selected: -1, dropdown: false, lastsearch: false, init: function(module,entry,element) { this.element = $(element); // Setup delete hooks on existing tags $("#tag_list a").click(this.deleteHook); $("#tag_entry").keydown($.proxy(this.checkKeys,this)); $("#tag_entry").keyup($.proxy(this.searchTags,this)); }, checkKeys: function(ev) { if (ev.keyCode == 13) { if (this.selected > -1 && this.dropdown) $("#tag_entry").val($("#tag_results li").eq(this.selected).find("a").html().replace("","").replace("","")); this.addTag(ev); return false; } if (ev.keyCode == 38) { this.moveUp(ev); return false; } if (ev.keyCode == 40) { this.moveDown(ev); return false; } }, moveUp: function(ev) { if (!this.dropdown || this.selected < 0) return; $("#tag_results li").eq(this.selected).removeClass("selected"); this.selected--; if (this.selected > -1) $("#tag_results li").eq(this.selected).addClass("selected"); }, moveDown: function(ev){ max = $("#tag_results li").length - 1; if (!this.dropdown || this.selected == max) return; if (this.selected > -1) $("#tag_results li").eq(this.selected).removeClass("selected"); this.selected++; $("#tag_results li").eq(this.selected).addClass("selected"); }, searchTags: function(ev) { tag = $("#tag_entry").val(); if (tag != BigTreeTagAdder.lastsearch) { BigTreeTagAdder.lastsearch = tag; if (tag.length > 3) { $("#tag_results").load("admin_root/ajax/tags/search/", { tag: tag }, BigTreeTagAdder.hookResults); } else { $("#tag_results").hide(); } } }, hookResults: function() { BigTreeTagAdder.selected = -1; ul = $("#tag_results"); if (ul.html()) { ul.show(); BigTreeTagAdder.dropdown = true; $("#tag_results li a").click(BigTreeTagAdder.chooseTag); } else { BigTreeTagAdder.dropdown = false; ul.hide(); } }, deleteHook: function(ev) { $(this).parents("li").remove(); return false; }, chooseTag: function(ev) { el = ev.target; tag = el.innerHTML.replace("","").replace("",""); if (tag) { $.ajax("admin_root/ajax/tags/create-tag/", { type: "POST", data: { tag: tag }, success: BigTreeTagAdder.addedTag }); } return false; }, addTag: function(ev) { tag = $("#tag_entry").val(); if (tag) { $.ajax("admin_root/ajax/tags/create-tag/", { type: "POST", data: { tag: tag }, success: BigTreeTagAdder.addedTag }); } }, addedTag: function(data) { id = data; li = $("
  • ").addClass("tag").html('' + tag + 'x'); li.children("a").click(BigTreeTagAdder.deleteHook); $("#tag_list").append(li); $("#tag_entry").val("").focus(); $("#tag_results").hide(); BigTreeTagAdder.dropdown = false; } }; // !BigTree Dialog Class var BigTreeDialog = Class.extend({ dialogWindow: false, onComplete: false, onCancel: false, dialogWidth: false, dialogHeight: false, heightWatchTimer: false, init: function(title,content,oncomplete,icon,noSave,altSaveText,altOnComplete,altOnCancel) { $("body").on("keyup",$.proxy(this.CheckForEsc,this)); this.onComplete = oncomplete; overlay = $('
    '); dialog_window = $('
    '); $("body").append(overlay).append(dialog_window); if (altSaveText) { saveText = altSaveText; } else { saveText = "Save"; } if (!noSave) { if (icon) { dialog_window.html('

    ' + title + '

    ' + content + '
    '); } else { dialog_window.html('

    ' + title + '

    ' + content + '
    '); } } else { dialog_window.html('

    ' + title + '

    ' + content + '

    '); } BigTreeCustomControls(dialog_window); this.dialogWidth = dialog_window.width(); this.dialogHeight = dialog_window.height(); leftd = parseInt((BigTree.WindowWidth() - this.dialogWidth) / 2); topd = parseInt((BigTree.WindowHeight() - this.dialogHeight) / 2); dialog_window.css({ "top": topd + "px", "left": leftd + "px" }); if (altOnCancel) { this.onCancel = altOnCancel; dialog_window.find(".bigtree_dialog_close").click(altOnCancel); } else { dialog_window.find(".bigtree_dialog_close").click($.proxy(this.DialogClose,this)); } if (altOnComplete) { dialog_window.find(".bigtree_dialog_form").submit(this.onComplete); } else { dialog_window.find(".bigtree_dialog_form").submit($.proxy(this.DialogSubmit,this)); } dialog_window.find("input[type=submit]").focus(); this.dialogWindow = dialog_window; // Move the dialog around with the window size. $(window).resize($.proxy(this.WindowResize,this)); // Set a timer to watch for a change in the dialog height this.heightWatchTimer = setInterval($.proxy(this.WatchHeight,this),250); BigTree.FormHooks(".bigtree_dialog_form"); }, CheckForEsc: function(e) { if (e.keyCode == 27) { if (this.onCancel) { this.onCancel(); $("body").off("keyup"); } else { this.DialogClose(); } } }, DialogClose: function() { $(".bigtree_dialog_overlay").last().remove(); $(".bigtree_dialog_window").last().remove(); BigTree.zIndex -= 2; $("body").off("keyup"); $(window).off("resize"); return false; }, DialogSubmit: function(ev) { ev.preventDefault(); ev.stopPropagation(); // Let's move all the TinyMCE content back. if (typeof tinyMCE != "undefined") { this.dialogWindow.find("textarea:hidden").each(function() { id = $(this).attr("id"); $(this).val(tinyMCE.get(id).getContent()); }); } this.onComplete(BigTree.CleanObject(this.dialogWindow.find(".bigtree_dialog_form").serializeJSON())); if (this.onCancel) { this.onCancel(); } else { this.DialogClose(); } return false; }, WatchHeight: function() { height = this.dialogWindow.height(); if (height != this.dialogHeight) { this.dialogHeight = height; this.WindowResize(false,true); } }, WindowResize: function(ev,animate) { leftd = parseInt((BigTree.WindowWidth() - this.dialogWidth) / 2); topd = parseInt((BigTree.WindowHeight() - this.dialogHeight) / 2); if (animate) { this.dialogWindow.animate({ "top": topd + "px", "left": leftd + "px" }, 200); } else { this.dialogWindow.css({ "top": topd + "px", "left": leftd + "px" }); } } }); // !BigTreeFileManager var BigTreeFileManager = { // Properties availableThumbs: false, browser: false, callback: false, currentFolder: 0, currentlyKey: false, currentlyName: false, fieldName: false, minHeight: false, minWidth: false, startSearchTimer: false, titleSaveTimer: false, type: false, // Methods addFile: function() { new BigTreeDialog("Upload File",'
    ',$.proxy(this.createFile,this),"folder",false,"Upload File",true,this.cancelAdd); return false; }, addFolder: function() { new BigTreeDialog("New Folder",'
    ',$.proxy(this.createFolder,this),"folder",false,"Create Folder",true,this.cancelAdd); return false; }, cancelAdd: function() { $(".bigtree_dialog_overlay").last().remove(); $(".bigtree_dialog_window").last().remove(); BigTree.zIndex -= 2; return false; }, chooseImageSize: function() { $("#file_browser_upload").unbind("click").html("").css({ cursor: "default" }).click(function() { return false; }); $("#file_browser_form .footer input.blue").hide(); $("#file_browser_info_pane").css({ height: "437px", marginTop: 0 }); size_pane = $("#file_browser_size_pane"); size_pane.html('

    Select Image Size

    Click on an image size below to insert into your content.

    '); for (i = 0; i< this.availableThumbs.length; i++) { size = this.availableThumbs[i]; link = $(''); link.attr("href",size.file.replace("{wwwroot}", "www_root/").replace("{staticroot}","static_root/")); link.html(size.name); size_pane.append(link); } link = $(''); link.attr("href",$("#file_browser_selected_file").val().replace("{wwwroot}", "www_root/").replace("{staticroot}","static_root/")); link.html("Original"); size_pane.append(link); size_pane.css({ marginLeft: "210px" }); $("#file_browser_info_pane").css({ marginLeft: "-1px" }); size_pane.find("a").click(function() { BigTreeFileManager.fieldName.value = $(this).attr("href"); BigTreeFileManager.closeFileBrowser(); return false; }); }, closeFileBrowser: function() { $(".bigtree_dialog_overlay").last().remove(); $("#file_browser").remove(); BigTree.zIndex = BigTree.zIndexBackup; $("#mceModalBlocker, #mce-modal-block").show(); return false; }, createFile: function() { $("body").append($('\
    \ \ \ \
    \
    \
    \ \
    \
    \
    \ \
    '); $("body").append(overlay).append(this.browser); // Hook the cancel, submit, and search. $("#file_browser_cancel").click($.proxy(this.closeFileBrowser,this)); $("#file_browser_form").submit($.proxy(this.submitSelectedFile,this)); $("#file_browser_search").keyup(function() { clearTimeout(BigTreeFileManager.startSearchTimer); BigTreeFileManager.startSearchTimer = setTimeout("BigTreeFileManager.search()",300); }); // Hide TinyMCE's default modal background, we're using our own. $("#mceModalBlocker, #mce-modal-block").hide(); // Handle the clicks on the breadcrumb of folders $("#file_browser_breadcrumb").on("click","a",function() { folder = $(this).attr("href").substr(1); if (BigTreeFileManager.type == "image" || BigTreeFileManager.type == "photo-gallery") { BigTreeFileManager.openImageFolder(folder); } else { BigTreeFileManager.openFileFolder(folder); } return false; }); // Handle the create new folder / file clicks $("#file_browser .header .add_file").click($.proxy(this.addFile,this)); $("#file_browser .header .add_folder").click($.proxy(this.addFolder,this)); $("#file_browser .header .delete_folder").click($.proxy(this.deleteFolder,this)); // Open the right browser if (type == "image" || type == "photo-gallery") { this.imageBrowser(); } else { this.fileBrowser(); } }, openFileFolder: function(folder) { this.currentFolder = folder; $("#file_browser_selected_file").val(""); $("#file_browser_info_pane").html(""); $("#file_browser_form .footer .blue").hide(); $("#file_browser_contents").scrollTop(0).load("admin_root/ajax/file-browser/get-files/", { folder: folder }, $.proxy(this.fileBrowserPopulated,this)); }, openImageFolder: function(folder) { this.currentFolder = folder; $("#file_browser_selected_file").val(""); $("#file_browser_info_pane").html(""); $("#file_browser_form .footer .blue").hide(); $("#file_browser_contents").scrollTop(0).load("admin_root/ajax/file-browser/get-images/", { minWidth: this.minWidth, minHeight: this.minHeight, folder: folder }, $.proxy(this.imageBrowserPopulated,this)); }, replaceFile: function(ev) { ev.preventDefault(); ev.stopPropagation(); new BigTreeDialog("Replace File",'
    ',BigTreeFileManager.replaceFileProcess,"folder",false,"Replace File",true,BigTreeFileManager.cancelAdd); }, replaceFileProcess: function(data) { $("body").append($('