Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
- <title>FLAGS DEMO</title>
- <script src="jquery-1.7.1.js"></script>
- <script>
- (function($){
- $.fn.languageSelect = function(opts) {
- /*
- opts example
- [
- {val:'us', text:'English', img:'us.png'},
- {val:'ru', text:'Русский', img:'ru.png'},
- {val:'uz', text:'Ўзбекча', img:'uz.png'}
- ]
- */
- function onLanguageSelectClick(e) {
- if (e.data == 'selected') {
- $(this).next().slideToggle(100);
- }
- else if (e.data == 'option') {
- var select = $(this).parent().parent().parent();
- select.find('.options').slideUp(100);
- var href = $(this).find('a').attr('href');
- href = href.substr(href.indexOf('#')+1, href.length);
- select.prev().val(href);
- select.find('.selected > a').
- html(generateLanguageRow(findOption(href, opts)) + '<img src="ad.png" class="arrowDown" />');
- }
- else {
- $('li.options').slideUp(100);
- }
- return false;
- }
- var opt = findOption(this.val(), opts);
- var selectedRow =
- opt
- ? generateLanguageRow(opt)
- : '<span class="empty">Langauge</span>';
- var optionRows = '';
- for(var i = 0; i < opts.length; i++) {
- optionRows +=
- '<li>' +
- '<a href="#'+ opts[i].val +'">'
- + generateLanguageRow(opts[i]) +
- '</a>' +
- '</li>';
- }
- var html =
- '<ul class="languageSelect">' +
- '<li class="selected">' +
- '<a href="#">' +
- selectedRow +
- '<img src="ad.png" class="arrowDown" />' +
- '</a>' +
- '</li>' +
- '<li class="options" style="display: none; z-index:12;">' +
- '<ul>' +
- optionRows +
- '</ul>' +
- '</li>' +
- '</ul>';
- this.after(html);
- var langaugeSelect = this.next('ul.languageSelect');
- langaugeSelect.find('li.selected').click('selected', onLanguageSelectClick);
- langaugeSelect.find('li.options > ul li').click('option', onLanguageSelectClick);
- $(document).click(onLanguageSelectClick);
- return this;
- };
- function findOption(val, opts) {
- for (var i = 0; i < opts.length; i++) {
- if (opts[i].val == val) return opts[i];
- }
- return null;
- }
- function generateLanguageRow(opt) {
- var html =
- '<img src="' + opt.img + '" class="flag" alt="' + opt.text +'" />';
- html +=
- '<span class="language">' + opt.text + '</span>';
- return html;
- }
- }(jQuery));
- $(function() {
- $('#language').languageSelect(
- [
- {val:'us', text:'English', img:'us.png'},
- {val:'ru', text:'Русский', img:'ru.png'},
- {val:'uz', text:'Ўзбекча', img:'uz.png'}
- ]
- );
- $('#emptyLanguage').languageSelect(
- [
- {val:'us', text:'English', img:'us.png'},
- {val:'ru', text:'Русский', img:'ru.png'},
- {val:'uz', text:'Ўзбекча', img:'uz.png'}
- ]
- );
- });
- </script>
- <style type="text/css">
- #content {
- }
- img {
- border: 0;
- }
- ul {
- list-style: none;
- padding: 0;
- margin: 0;
- }
- li {
- padding: 0;
- margin: 0;
- }
- ul.languageSelect {
- background: #FFF;
- color: #000;
- }
- ul.languageSelect a, ul.languageSelect a:visited {
- color: #000;
- text-decoration: none;
- }
- ul.languageSelect li.selected {
- position: relative;
- border: 1px solid #ccc;
- width: 120px;
- }
- ul.languageSelect li.selected img.arrowDown {
- width: 18px;
- height: 18px;
- vertical-align: middle;
- margin: 0 3px;
- position: absolute;
- top: 3px;
- right: 0px;
- }
- ul.languageSelect .empty {
- display: inline-block;
- padding-left: 3px;
- }
- ul.languageSelect li.options {
- margin-top: 5px;
- border: 1px solid #ccc;
- width: 120px;
- }
- ul.languageSelect img.flag {
- width: 24px;
- height: 24px;
- vertical-align: middle;
- margin:0 3px;
- }
- ul.languageSelect .language {
- vertical-align: middle;
- }
- </style>
- </head>
- <body>
- <div id="content">
- <input type="hidden" id="language" value="ru" />
- <br />
- <input type="hidden" id="emptyLanguage" value="" />
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment