﻿/*
@author: Karl-Johan Sjögren / http://blog.crazybeavers.se/
@url: http://blog.crazybeavers.se/wp-content/demos/jquery.tag.editor/
@license: Creative Commons License - ShareAlike http://creativecommons.org/licenses/by-sa/3.0/
@version: 1.3
@changelog
 1.3
   Any string already in the textbox when enabling the tag editor is now parsed as tags
   Added initialParse to stop the initial parsing
   Added confirmRemovalText as an option to better support different localizations
   Added the getTags method.
   Fixed completeOnBlur that wasn't working
 1.2
  Fixed bug with completeOnSeparator for Firefox
  Fixed so that pressing return on an empty editor would submit the form
 1.1
  Initial public release
  Added the completeOnSeparator and completeOnBlur options
*/
(function($) {
    $.fn.extend({
        tagEditor: function(options) {
            var defaults = {
                separator: ',',
                items: [],
                className: 'tagEditor',
                confirmRemoval: false,
                confirmRemovalText: 'Bu etiketi kaldırmak istiyor musunuz?',
                completeOnSeparator: false,
                completeOnBlur: false,
                initialParse: true
            }

            var options = $.extend(defaults, options);
            var listBase, textBase = this, hiddenText;
            var itemBase = [];

            this.getTags = function() {
                return itemBase.join(options.separator);
            };

            return this.each(function() {
                hiddenText = $(document.createElement('input'));
                hiddenText.attr('type', 'hidden');
                textBase.after(hiddenText);

                listBase = $(document.createElement('ul'));
                listBase.attr('class', options.className);
                $(this).after(listBase);

                for (var i = 0; i < options.items.length; i++) {
                    addTag(jQuery.trim(options.items[i]));
                }

                if (options.initialParse)
                    parse();

                if (options.completeOnBlur)
                    $(this).blur(parse);

                buildArray();
                $(this).keypress(handleKeys);

                var form = $(this).parents("form");
                form.submit(function() {
                    parse();
                    hiddenText.val(itemBase.join(options.separator));
                    hiddenText.attr("id", textBase.attr("id"));
                    hiddenText.attr("name", textBase.attr("name"));
                    textBase.attr("id", textBase.attr("id") + '_old');
                    textBase.attr("name", textBase.attr("name") + '_old');
                });

                function addTag(tag) {
                    tag = jQuery.trim(tag);
                    for (var i = 0; i < itemBase.length; i++) {
                        if (itemBase[i].toLowerCase() == tag.toLowerCase())
                            return;
                    }

                    var item = $(document.createElement('span'));
                    item.text(tag);
                    item.attr('title', 'Etiketi Kaldır');
                    item.click(function() {
                        if (options.confirmRemoval)
                            if (!confirm(options.confirmRemovalText))
                            return;

                        item.remove();
                        parse();
                    });

                    listBase.append(item);
                }

                function buildArray() {
                    itemBase = [];
                    var items = $("span", listBase);

                    for (var i = 0; i < items.length; i++) {
                        itemBase.push(jQuery.trim($(items[i]).text()));
                    }
                }

                function parse() {
                    var items = textBase.val().split(options.separator);

                    for (var i = 0; i < items.length; i++) {
                        var trimmedItem = jQuery.trim(items[i]);
                        if (trimmedItem.length > 0)
                            addTag(trimmedItem);
                    }
                    textBase.val("");
                    buildArray();
                }

                function handleKeys(ev) {
                    var keyCode = (ev.which) ? ev.which : ev.keyCode;

                    if (options.completeOnSeparator) {
                        if (String.fromCharCode(keyCode) == options.separator) {
                            parse();
                            return false;
                        }
                    }

                    switch (keyCode) {
                        case 13:
                            {
                                if (jQuery.trim(textBase.val()) != '') {
                                    parse();
                                    return false;
                                }
                                return true;
                            }
                    }
                }
            });
        }
    });
})(jQuery);

/*Elastic*/
(function(jQuery){jQuery.fn.extend({elastic:function(){var mimics=['paddingTop','paddingRight','paddingBottom','paddingLeft','fontSize','lineHeight','fontFamily','width','fontWeight'];return this.each(function(){if(this.type!='textarea'){return false}var $textarea=jQuery(this),$twin=jQuery('<div />').css({'position':'absolute','display':'none','word-wrap':'break-word'}),lineHeight=parseInt($textarea.css('line-height'),10)||parseInt($textarea.css('font-size'),'10'),minheight=parseInt($textarea.css('height'),10)||lineHeight*3,maxheight=parseInt($textarea.css('max-height'),10)||Number.MAX_VALUE,goalheight=0,i=0;if(maxheight<0){maxheight=Number.MAX_VALUE}$twin.appendTo($textarea.parent());var i=mimics.length;while(i--){$twin.css(mimics[i].toString(),$textarea.css(mimics[i].toString()))}function setHeightAndOverflow(height,overflow){curratedHeight=Math.floor(parseInt(height,10));if($textarea.height()!=curratedHeight){$textarea.css({'height':curratedHeight+'px','overflow':overflow})}}function update(){var textareaContent=$textarea.val().replace(/&/g,'&amp;').replace(/  /g,'&nbsp;').replace(/<|>/g,'&gt;').replace(/\n/g,'<br />');var twinContent=$twin.html();if(textareaContent+'&nbsp;'!=twinContent){$twin.html(textareaContent+'&nbsp;');if(Math.abs($twin.height()+lineHeight-$textarea.height())>3){var goalheight=$twin.height()+lineHeight;if(goalheight>=maxheight){setHeightAndOverflow(maxheight,'auto')}else if(goalheight<=minheight){setHeightAndOverflow(minheight,'hidden')}else{setHeightAndOverflow(goalheight,'hidden')}}}}$textarea.css({'overflow':'hidden'});$textarea.keyup(function(){update()});$textarea.live('input paste',function(e){setTimeout(update,250)});update()})}})})(jQuery);


/* jQuery.CuteTime v 1.0.5 http://tpgblog.com/cutetime/
compiled by http://yui.2clics.net/ */
(function(e){var b=Number.NEGATIVE_INFINITY;var d=Number.POSITIVE_INFINITY;var a="data-timestamp";e.fn.cuteTime=function(l){var k=new Date().getTime();var m;var n;if((typeof l=="object")||(l==undefined)){e.fn.cuteTime.c_settings=e.extend({},e.fn.cuteTime.settings,l);e.fn.cuteTime.the_selected=this;this.each(function(){n=e(this);m=h(n);n.text(c(k-m))});e.fn.cuteTime.start_cuteness()}return this};e.cuteTime=function(l){var k=new Date().getTime();var m;var n;if(typeof l=="string"){m=j(l);if(!isNaN(m)){return c(k-m)}else{return"INVALID DATE/TIME FORMAT"}}return this};e.fn.cuteTime.settings={refresh:-1,time_ranges:[{bound:b,cuteness:"simdi!",unit_size:0},{bound:0,cuteness:"hemen",unit_size:0},{bound:20*1000,cuteness:"birkaç sn önce",unit_size:0},{bound:60*1000,cuteness:"1 dk önce",unit_size:0},{bound:60*1000*2,cuteness:" dk önce",unit_size:60*1000},{bound:60*1000*60,cuteness:"1 saat önce",unit_size:0},{bound:60*1000*60*2,cuteness:" saat önce",unit_size:60*1000*60},{bound:60*1000*60*24,cuteness:"dün",unit_size:0},{bound:60*1000*60*24*2,cuteness:" gün önce",unit_size:60*1000*60*24},{bound:60*1000*60*24*30,cuteness:"geçen ay",unit_size:0},{bound:60*1000*60*24*30*2,cuteness:" ay önce",unit_size:60*1000*60*24*30},{bound:60*1000*60*24*30*12,cuteness:"geçen yıl",unit_size:0},{bound:60*1000*60*24*30*12*2,cuteness:" yıl önce",unit_size:60*1000*60*24*30*12},{bound:d,cuteness:"çok uzun süre önce",unit_size:0}]};e.fn.cuteTime.start_cuteness=function(){var k=e.fn.cuteTime.c_settings.refresh;if(e.fn.cuteTime.process_tracker==null){if(k>0){e.fn.cuteTime.process_tracker=setInterval("$.fn.cuteTime.update_cuteness()",k)}}else{}return this};e.fn.cuteTime.update_cuteness=function(){var k=new Date().getTime();var m;var l;e.fn.cuteTime.the_selected.each(function(){m=e(this);l=h(m);m.text(c(k-l))})};e.fn.cuteTime.stop_cuteness=function(){if(e.fn.cuteTime.process_tracker!=null){clearInterval(e.fn.cuteTime.process_tracker);e.fn.cuteTime.process_tracker=null}else{}return this};function c(n){var l=e.fn.cuteTime.c_settings.time_ranges;var m;var k="";jQuery.each(l,function(o,p){if(o<l.length-1){if((n>=p.bound)&&(n<l[o+1]["bound"])){if(p.unit_size>0){m=Math.floor(n/p.unit_size)}else{m=""}k=m+p.cuteness;return false}}else{return false}});if(k==""){k="2 pookies ago"}return k}function j(l){var k=(new Date(l)).valueOf();if(isNaN(k)){k=new Date(l.replace(/-/g," "))}return k}function h(l){var k=Number.NaN;time_string=f(l);if(time_string!=null){k=j(time_string)}if(isNaN(k)){time_string=g(l);if(time_string!=null){k=j(time_string)}}if(isNaN(k)){time_string=new Date().toString();k=j(time_string)}i(time_string,l);return k}function f(l){var k=l.attr(a);if(k!=undefined){return k}else{return null}}function i(k,l){l.attr(a,k)}function g(k){return k.text()}})(jQuery);
