HEX
Server: Apache/2.4.25 (Debian)
System: Linux server17 4.9.0-19-amd64 #1 SMP Debian 4.9.320-2 (2022-06-30) x86_64
User: web37 (1062)
PHP: 7.4.30
Disabled: show_source, highlight_file, apache_child_terminate, apache_get_modules, apache_note, apache_setenv, virtual, dl, disk_total_space, posix_getpwnam, posix_getpwuid, posix_mkfifo, posix_mknod, posix_setpgid, posix_setsid, posix_setuid, posix_uname, proc_nice, openlog, syslog, pfsockopen
Upload Files
File: /var/www/web37/htdocs/fickanzeiger/javascript/jquery/jquery.keywordSelector.js
(function($){

    $.fn.keywordSelector = function(params){
    
        
        return $(this).each(function(){
            var that = {
                maxSelectsCount: 0,
                form: $(this)[0],
                duplicateMsg: setting.lang['You have already added this keyword. Select another one.'],
                keywordIds: new Array(),
                lp: 0,
                
                addNewRow: function(){
                    var template = $.format($("#keywordRowTemplate").val());
                    var $newRow = $(template(++that.lp));
                    $("#keywordsSelectTable").append($newRow);
                    return $newRow;
                },
                
                init: function(){
                
                    if($("#keywordRowTemplate").length == 0)return;
                    
                    that.maxSelectsCount = setting.maxKeywordsCountPerSite;
                    
                    if(params.keywordIds)
                    {
                        that.keywordIds = params.keywordIds;
                    
                        if(that.keywordIds.length < that.maxSelectsCount)
                        {
                            params.keywordIds.push("");
                        }
                    } 
                    
                    $("[name=keywords\[\]]", this.form).livequery("change", this.onKeywordChanged);
                    that.setKeywords(that.keywordIds);
                },
                
                setKeywords: function(keywordIds){
                    for (var i = 0; i < keywordIds.length; i++) {
                        $("[name=keywords\[\]]", that.addNewRow()).val(keywordIds[i]);
                    }
                },
                
                onKeywordChanged: function(){
                    var value = $(this).val();
                    var wasTimes = {};
                    var $keywords = $("[name=keywords\[\]]", this.form);
                    
                    $keywords.each(function(){
                        if (!wasTimes[$(this).val()]) 
                            wasTimes[$(this).val()] = 0;
                        wasTimes[$(this).val()]++;
                    });
                    
                    if (value != "" && wasTimes[value] > 1) {
                        $.alertDialog(that.duplicateMsg);
                        $(this).val("");
                        return false;
                    }
                    
                    if (!wasTimes[''] && $keywords.length < that.maxSelectsCount) 
                        that.addNewRow();
                }
            };
            
            that.init();
            
        });
    }
    
})(jQuery);