Monday, March 10, 2014

jQcustom.js console tables // Втора версия за алтернативни alert,prompt и confirm функции // Създате

Алтернативи на alert,confirm и prompt v2 | Dobrev-Web.EU Пламен Добрев - Web Developer
Здравейте, ще ви покажа втората версия за създаване на алтернативни функции съответстващи на JavaScript функциите alert, confirm и prompt. В предната версия кода беше твърде много и твърде тежък и без много екстри и имаше бъгове. Затова реших да направя този по кратък, оптимизиран, функционален console tables и подреден код! За новия код съм взел дизайна и част от кода тъй като нямаше смисъл да започвам от нулата .
jQcustom.js console tables // Втора версия за алтернативни alert,prompt и confirm функции // Създател: Пламен Добрев (nicks:IzKuFeLiQqQqQ,plamba95) // Програмни езици: jQuery v.1.7.1,CSS3,HTML5 // Дата: 14.03.2012 // Всички права запазени! // Информация: Библиотека на jQuery е задължителна!!! Може да я изтеглите от http://jquery.com/ ! function jqcustom(content, data, callback) { var i = $('.jqcustom_windown').length; if ($('.jqcustom_windown#jqwin' + i).is(':visible')) console tables { i++; } var def_data = { 'type': 'alert', //alert,prompt,confirm,custom 'title': 'Съобщение от сайта!', 'ok': 'Ок', 'cancel': 'Отказ', 'value': '' }; if (data) { for (var val in def_data) { if (typeof data[val] == "undefined") data[val] = def_data[val]; } } else { var data=[]; for (var val in def_data) { data[val] = def_data[val]; } } var output console tables = ""; output += "<div class='jqcustom_mask' console tables id='jqmask" + i + "'></div><div class='jqcustom_windown' id='jqwin" + i + "'>"; if(data['title'] != '' || (data['type'] == 'custom' && data['title'] != 'Съобщение от сайта!')) { output += "<div class='jqcustom_header'>"; output += data['title']; } output += "<img src='http://cdn2.iconfinder.com/data/icons/gnomeicontheme/22x22/actions/window-close.png' alt='Затвори' style='float:right;' console tables class='jqcustom_close'/>"; if(data['title'] != '' || (data['type'] == 'custom' && data['title'] != 'Съобщение от сайта!')) output += "</div>"; output += "<div class='jqcustom_content'>"; if(data['type'] != 'custom') { output += content+ "<div>"; if (data['type'] == 'prompt') output += "<input type='text' console tables class='jqcustom_textarea' value='" + data['value'] + "'/><br />"; output += "<center><input type='button' class='jqcustom_ok' value='" + data['ok'] + "'/>"; if (data['type'] == 'confirm' || data['type'] == 'prompt') output += "<input type='button' class='jqcustom_cancel' value='" + data['cancel'] + "'/>"; output += "</center></div>"; } output += "</div></div></div>"; $('body').append(output); if(data['type'] == 'custom') { $('body').find('#'+content).appendTo('.jqcustom_content'); $('body').find('#'+content).show(); } if (data['type'] == 'prompt') { setTimeout(function() { $('.jqcustom_windown#jqwin' + i).find('.jqcustom_textarea').focus().select(); }, 50); } function jqcustom_center() { $('.jqcustom_mask#jqmask' + i).css({ 'width': $(window).width(), 'height': $(window).height() }); if(data['type'] == 'custom') { $('.jqcustom_windown#jqwin' + i).width("auto"); $('.jqcustom_windown#jqwin' + i).find('.jqcustom_close').css({'margin-top':'-12px','margin-right':'-12px'}); } $('.jqcustom_windown#jqwin' + i).css({ 'left': ($(window).width() - $('.jqcustom_windown#jqwin' + i).width()) / 2 + $(window).scrollLeft() + "px", 'top': ($(window).height() - $('.jqcustom_windown#jqwin' + i).height()) / 2 + $(window).scrollTop() + "px" }); } $(window).ready(jqcustom_center).resize(jqcustom_center); $('.jqcustom_mask#jqmask' + i).fadeTo("slow", 0.8); $('.jqcustom_windown#jqwin' + i).fadeIn('medium'); function jqcustom_close() { $(".jqcustom_windown#jqwin" + i + ",.jqcustom_mask#jqmask" + i).fadeOut("medium", function() { if(data['type'] == 'custom') { $('body').find('#'+content).hide(); $('body').find('#'+content).appendTo('#content'); } $(".jqcustom_windown#jqwin" + i + ",.jqcustom_mask#jqmask" + i).remove(); }); } function jqcustom_ok() { if (callback) { if (data['type'] == 'alert' || data['type'] == 'confirm') callback(true); else if (data['type'] == 'prompt') callback($('.jqcustom_textarea').val()); } jqcustom_close(); } $(document).unbind('keydown').bind('keydown',function(e) { if (e.keyCode == 27) { if (callback) console tables { callback(false); } jqcustom_close(); } else if (e.keyCode console tables == 13) { jqcustom_ok(); } }); $('.jqcustom_mask#jqmask' + i).click(function() { if (callback) { callback(false); } jqcustom_close(); }); $('.jqcustom_windown#jqwin' + i).find(".jqcustom_close,.jqcustom_cancel,.jqcustom_mask#jqmask" + i).click(function() { if (callback) { callback(false); } jqcustom_close(); console tables }); $('.jqcustom_windown#jqwin' + i).find('.jqcustom_ok').click(function() { jqcustom_ok(); }); }
  .jqcustom_mask { position:absolute; left:0; top:0; z-index:10; background-color:#000000; display:none; } .jqcustom_windown{ console tables background-color:lightgreen; border:1px solid black; height:auto; width:400px; console tables position:absolute; z-index:100; -webkit-border-radius: 10px; -moz-border-radius: 10px; border-radius: 10p

No comments:

Post a Comment