function Dialog(control, width, height, okCallback) { HideDropDowns(); $(control) .show() .dialog({ modal: true, width: width, height: height, resizable: false, close: function() { $(this).dialog("destroy"); ShowDropDowns() }, buttons: { "Save": function() { ShowDropDowns(); okCallback(); $(this).dialog("close"); } } }); } function DialogWithoutButtons(control, width, height) { HideDropDowns(); $(control) .show() .dialog({ modal: true, width: width, height: height, resizable: false, close: function() { $(this).dialog("destroy"); ShowDropDowns() } }); } function Message(message, redirectUrl) { HideDropDowns(); $("
" + message + "
") .appendTo("body") .dialog({ modal: true, overlay: { opacity: 0.9, background: "white" }, width: 770, height: 130, resizable: false, close: function() { $(this).dialog("destroy"); ShowDropDowns() }, buttons: { "Next": function() { $(this).dialog("close"); if (redirectUrl) location = redirectUrl; } } }); } function ConfirmMessage(okCallback) { HideDropDowns(); $("
Sind Sie sicher?
") .appendTo("body") .dialog({ modal: true, height: 115, resizable: false, close: function() { $(this).dialog("destroy"); ShowDropDowns() }, buttons: { "Yes, proceed": function() { $(this).dialog("close"); okCallback(); }, "No": function() { $(this).dialog("close"); } } }); } function DatePicker(control) { $(control).datepicker({ dateFormat: "mm/dd/yy", yearRange: "1900:2015", changeMonth: true, changeYear: true, changeFirstDay: false }); //this is a fix for the jquery datepicker, because the proper class won't be added otherwise $("#ui-datepicker-div").addClass("ui-datepicker-div"); } function ReplaceBreaksWithCrlf(text) { if (!text) return ""; while (text.indexOf("
", 0) >= 0) text = text.replace("
", "\r\n"); return text; } function HideDropDowns() { if ($.browser.msie && $.browser.version < 7) $(".hide-dropdown").hide(); } function ShowDropDowns() { if ($.browser.msie && $.browser.version < 7) $(".hide-dropdown").show(); } function MaxLength(textarea, maxLength) { var divId = "___MaxLength"; $(textarea).blur(function() { $("#" + divId).remove(); }); $(textarea).focus(function() { var left = $(textarea).offset().left; var top = $(textarea).offset().top; $("
") .attr("id", divId) .addClass("epunkt-grid-item") .css({ position: "absolute", left: left, top: top, width: 150, zIndex: 99999 }) .hide() .html($(textarea).val().length + "/" + maxLength + " Characters.") .appendTo("body") .show() .css({ top: top - $("#" + divId).height() }); }); $(textarea).keyup(function() { $("#" + divId) .html($(textarea).val().length + "/" + maxLength + " Characters."); }); $(textarea).keydown(function(evnt) { if (evnt.keyCode == 8 || evnt.keyCode == 46 || evnt.keyCode == 37 || evnt.keyCode == 39 || evnt.keyCode == 38 || evnt.keyCode == 40) //we still allow Backspace, Del and the Cursors. return true; if ($(textarea).val().length >= maxLength) return false; }); } (function($) { $.fn.maxLen = function(maxLength) { $(this).each(function() { var divId = "___maxLength"; $(this).attr("maxlength", maxLength); $(this).blur(function() { $("#" + divId).remove(); }); $(this).focus(function() { var left = $(this).offset().left; var top = $(this).offset().top - 14; $("
") .attr("id", divId) .addClass("epunkt-grid-item") .css({ position: "absolute", left: left, top: top, width: 100, zIndex: 99999 }) .hide() .appendTo("body") .show(); $(this).keyup(); }); $(this).keyup(function() { $("#" + divId).html($(this).val().length + "/" + maxLength + " Characters."); }); }); } })(jQuery); function HoverInfo(id, text, width) { $(id).hover(function() { if (!width) width = 350; var left = $(id).offset().left; var top = $(id).offset().top + 25; if (left + 10 + width > $(document).width()) left = $(document).width() - 10 - width; $("#___HoverInfo").remove(); $("
") .attr("id", "___HoverInfo") .addClass("epunkt-hover-box") .css({ position: "absolute", left: left, top: top, width: width, zIndex: 99999 }) .html(text) .hide() .appendTo("body") .fadeIn(300); }, function() { $("#___HoverInfo") .fadeOut(300); }); } (function($) { $.fn.advancedDropdown = function(options) { var textbox = $(this); var defaults = { items: new Array(), cssClassDropdown: "epunkt-advanceddropdown", cssClassItems: "epunkt-advanceddropdown-items", cssClassItem: "epunkt-advanceddropdown-item", cssClassItemHover: "epunkt-advanceddropdown-item-hover", cssClassImage: "epunkt-advanceddropdown-image", cssClassItemInfo: "epunkt-advanceddropdown-item-info", maxHeight: 300 }; options = $.extend(defaults, options); $._advancedDropdowns = $._advancedDropdowns ? $._advancedDropdowns : new Array(); $._advancedDropdowns.push(SetPosition); $.fn.extend({ _originalDialog: $(this)._originalDialog ? $(this)._originalDialog : $.fn.dialog, dialog: function(options) { return this.each(function() { $(this)._originalDialog(options); $.each($._advancedDropdowns, function(i, val) { val(); }); $(document).click(); }); } }); function GetId() { return "___advancedDropDown_" + textbox.attr("id"); } function GetItemsId() { return "___advancedDropDown_" + textbox.attr("id") + "_items"; } function GetItemId(index) { return "___advancedDropDown_" + textbox.attr("id") + "_item_" + index; } function GetDropdownHtml() { var text = ""; $.each(options.items, function(i, item) { if (item.value == textbox.val()) { text = item.text; }; }); if (text == "" && options.items.length >= 1) { textbox.val(options.items[0].value); text = options.items[0].text; } return "
" + text; } function SetPosition() { textbox.show(); $("#" + GetId()).css({ left: textbox.offset().left, top: textbox.offset().top, height: textbox.height(), width: textbox.width() }); textbox.hide(); $("#" + GetId()).html(GetDropdownHtml()); } return this.each(function() { $("#" + GetId(textbox)).remove(); var dropdown = $("
") .attr("id", GetId(textbox)) .addClass(options.cssClassDropdown) .html(GetDropdownHtml()) .insertAfter(textbox); SetPosition(textbox); $(document).click(function() { $("#" + GetItemsId()).remove(); }); $(window).resize(function() { $(document).click(); }); dropdown.click(function(e) { $(document).click(); e.stopPropagation(); $("#" + GetItemsId()).remove(); var items = $("
") .attr("id", GetItemsId()) .addClass(options.cssClassItems) .css({ position: "absolute", zIndex: 99999999 }) .show() .appendTo("body"); var html = ""; $.each(options.items, function(i, item) { html += "
" + item.text; if (item.info && item.info != "") html += "
" + item.info + "
"; html += "
"; }); items.html(html); items.css({ left: dropdown.offset().left + "px", top: dropdown.offset().top + dropdown.height() + "px", width: dropdown.width() + "px" }); if (items.height() > options.maxHeight) { items.css({ height: options.maxHeight + "px", overflow: "scroll" }); } $.each(options.items, function(i, item) { $("#" + GetItemId(i)).hover(function() { $("#" + GetItemId(i)).addClass(options.cssClassItemHover); }, function() { $("#" + GetItemId(i)).removeClass(options.cssClassItemHover); }); $("#" + GetItemId(i)).click(function() { textbox.val(options.items[i].value); dropdown.html(GetDropdownHtml()) $(document).click(); }); }); items.click(function(e) { e.stopPropagation(); }); }); }); }; })(jQuery); (function($) { $.fn.autoComplete = function(options) { var defaults = { seperator: null, cssClassItems: "epunkt-autocomplete-items", cssClassItem: "epunkt-autocomplete-item", cssClassItemHover: "epunkt-autocomplete-item-hover", triggerEnterOnClick: false }; options = $.extend(defaults, options); if (options.method == null) return $(this); var cache = null; var cacheIsBeeingFilled = false; var selectedIndex = -1; var lastTextbox = null; //we use these variables or the ajax-callback-method would need a lot more parameters var lastText = null; function GetId() { return "___autoComplete"; } function GetItemId(index) { return "___autoComplete_" + index; } function Remove() { $("#" + GetId()).remove(); selectedIndex = -1; } function RenderItems(textbox, text) { var html = ""; var filtered = new Array(); $.each(cache, function(i, tag) { if (i <= 20 && tag.toLowerCase().indexOf(text.toLowerCase(), 0) >= 0) filtered.push(tag); }); $.each(filtered, function(i, tag) { var highlightedText = tag.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + text.replace(/([\^\$\(\)\[\]\{\}\*\.\+\?\|\\])/gi, "\\$1") + ")(?![^<>]*>)(?![^&;]+;)", "gi"), "$1"); html += "
" + highlightedText + "
"; }); if (html == "") Remove(); else $("#" + GetId()) .html(html) .css({ top: (textbox.offset().top + textbox.height() + 3) + "px", left: (textbox.offset().left) + "px", width: (textbox.width() + 4) + "px" }) .show(); $.each(filtered, function(i, tag) { $("#" + GetItemId(i)).click(function(evnt) { AddText(textbox, tag, options.triggerEnterOnClick); }); }); } function AddText(textbox, tag, triggerEnter) { var existingText = textbox.val(); if (options.seperator != null && options.seperator != "" && existingText.lastIndexOf(options.seperator) >= 0) existingText = existingText.substring(0, existingText.lastIndexOf(options.seperator)) + options.seperator + " "; else existingText = ""; textbox.val(existingText + tag); textbox.focus(); if (triggerEnter) textbox.trigger("keyup", [{ preventDefault: function() { }, keyCode: 13 }]); } function SelectItem(textbox) { $("." + options.cssClassItemHover).removeClass(options.cssClassItemHover); var selectedItem = $("#" + GetItemId(selectedIndex)); selectedItem.addClass(options.cssClassItemHover); AddText(textbox, selectedItem.attr("title"), false); } function SetCache(items) { cache = new Array(); $.each(items, function(i, val) { cache.push(val); }); cacheIsBeeingFilled = false; RenderItems(lastTextbox, lastText); } return this.each(function() { var textbox = $(this); textbox.attr("autocomplete", "off"); textbox.keydown(function(event) { if (event.which == 13 || event.which == 9) { //ENTER, TAB if ($("#" + GetId(selectedIndex)).length > 0) { textbox.val(textbox.val() + options.seperator + " "); setTimeout("$('#" + textbox.attr("id") + "').focus();", 50); } Remove(); } }); textbox.keyup(function(event) { var text = textbox.val(); if (options.seperator != null && options.seperator != "") if (text.lastIndexOf(options.seperator) >= 0) text = text.substring(text.lastIndexOf(options.seperator) + 1); text = $.trim(text); if (event.which == 8) //backspace clears the cache cache = null; if (text.length > 1) { if ($("#" + GetId()).length <= 0) { $("
") .attr("id", GetId()) .addClass(options.cssClassItems) .hide() .css({ top: (textbox.offset().top + textbox.height() + 3) + "px", left: (textbox.offset().left) + "px", width: (textbox.width() + 4) + "px", position: "absolute", zIndex: 9999 }) .insertAfter(textbox) } $(document).click(function() { Remove(); }); $(window).resize(function() { $(document).click(); }); if (event.which == 40 || event.which == 38) { if (event.which == 38) //KEYUP selectedIndex--; else if (event.which == 40) //KEYDOWN selectedIndex++; if (selectedIndex < 0 || $("#" + GetId(selectedIndex)).length <= 0) selectedIndex = 0; SelectItem(textbox); } else if (event.which == 37 || event.wich == 39) { //KEYLEFT, KEYRIGHT //do nothing here } else { if (cache==null && !cacheIsBeeingFilled) { cacheIsBeeingFilled = true; lastTextbox = textbox; lastText = text; var textToSuggestFor = text; while (textToSuggestFor.indexOf("/") >= 0) textToSuggestFor = textToSuggestFor.replace("/", ""); options.method(textToSuggestFor, SetCache); } else if (cache) RenderItems(textbox, text); } } else { Remove(); } }); }); } })(jQuery);