/** * @copyright 2006-2011 LanMediaService, Ltd. * @license http://www.lanmediaservice.com/license/1_0.txt * @author Ilya Spesivtsev * @version $Id: UI.js 700 2011-06-10 08:40:53Z macondos $ */ if (!LMS.Video) { LMS.Video = {}; } LMS.Video.UI = { currentGenre: null, currentCountry: null, limitNavigationItems: 15, limitPages: 10, offset: null, pageSize: 20, total: 0, paginator: null, continuousScrolling: true, pages: [], waitLoad: false, overlay: null, currentOrder: null, currentDir: null, maxFrameWidth: 500, lastSuggestionQuery: null, mode: null, catalogInited: false, mainWrapperInited: false, tabs: {}, level2: 'catalog', bookmarks: {films:[]}, recentlyViewed: [], currentFilmId: null, links: {}, init: function() { this.initHacks(); $j('#toolbar [title]').tipsy({delayIn: 200, gravity: 's'}); $j('.scroll-up[title]').tipsy({gravity: 'e'}); $j('[title]').tipsy({delayIn: 200}); this.tabs.catalog = {}; this.tabs.bestsellers = {}; this.tabs.search = {}; this.tabs.movie = {}; this.tabs.person = {}; this.tabs.settings = {}; LMS.Connector.connect('routeCatalog', this, 'routeCatalog'); LMS.Connector.connect('routeDefault', this, 'routeBestsellers'); LMS.Connector.connect('routeSettings', this, 'routeSettings'); LMS.Connector.connect('routeMovie', this, 'routeFilm'); LMS.Connector.connect('routePerson', this, 'routePerson'); LMS.Connector.connect('routeBestsellers', this, 'routeBestsellers'); LMS.Connector.connect('routeSearch', this, 'routeSearch'); this.overlay = LMS.Widgets.Factory('Overlay'); if (USER_GROUP!=0) { window.action.getBookmarks(); } var matches = window.location.hash.match(/#film:(\d+)/); if (matches) { window.location.hash = '/movie/id/' + matches[1]; } if (window.location.hash.match(/#page:/)) { window.location.hash = ''; } router.onBeforeRoute = this.onBeforeRoute.bind(this); router.init(); this.initSuggestion(); this.initRecentViewed(); this.loadVideoplayerSettings(); this.loadLinksSettings(); }, initCatalog: function() { this.initPaginator() this.initNavigator(); window.action.getRandomFilm(); window.action.getPopFilms(); window.action.getLastComments(); window.action.getLastRatings(); this.catalogInited = true; if (!this.mainWrapperInited) { this.initMainWrapper(); } }, initMainWrapper: function() { this.mainWrapperInited = true; }, setTemplate: function(template) { setCookie('template', template, 'Tue, 24-Mar-2020 20:16:28 GMT'); window.location.reload(); }, routeCatalog: function(params) { this.tabs.catalog.hash = window.location.hash.substring(1); if (params.country != this.currentCountry) { window.action.getGenres(params.country? params.country : 0); } if (params.genre != this.currentGenre) { window.action.getCountries(params.genre? params.genre : 0); } var offset = this.pageNumberToOffset(params.page? params.page : 1); this.getCatalog( offset, params.genre? params.genre : null, params.country? params.country : null, params.order? params.order : null ); }, routeBestsellers: function(params) { this.tabs.bestsellers.hash = window.location.hash.substring(1); window.action.getBestsellers(); if (!this.mainWrapperInited) { this.initMainWrapper(); } }, routeSearch: function(params) { this.tabs.search.hash = window.location.hash.substring(1); window.action.search(params.query); if (!this.mainWrapperInited) { this.initMainWrapper(); } }, routeFilm: function(params) { this.tabs.movie.hash = window.location.hash.substring(1); var filmId = params.id; var page = params.page? params.page : 'overview'; if (filmId == this.currentFilmId) { this.gotoTab('movie'); switch (page) { case 'comments': this.showFilmComments(filmId); break; case 'overview': default: this.showFilmOverview(); } } else { window.action.getFilm(params.id, page); } }, routePerson: function(params) { this.tabs.person.hash = window.location.hash.substring(1); window.action.getPerson(params.id); }, routeSettings: function(params) { this.gotoTab('settings'); var title = 'Настройки'; this.setTitle(title); this.setFavicon(); this.tabs.settings.name = title; this.updateBreadcrumb(); if (params.page) { var page = params.page } else { var page = $j('#settings_wrapper .menu-item:first').attr('data-page'); } this.selectSettingPage(page); }, localStorageHandler: function(e) { if (!e) { e = window.event; } switch (e.key) { case 'user.recently_viewed': this.loadRecentlyViewed(); this.drawRecentlyViewed(); break; } }, gotoTab: function(tabCode) { if (tabCode=='catalog' || tabCode=='bestsellers' || tabCode=='search') { this.level2 = tabCode; } if (!this.tabs.current || this.tabs.current!=this.tabs[tabCode]) { if (this.tabs.current) { this.saveTab(); } this.tabs.current = this.tabs[tabCode]; this.tabs.current.tabCode = tabCode; this._setMode(tabCode); if (this.tabs.current) { this.loadTab(); } this.updateBreadcrumb(); } }, _setMode: function(mode) { this.mode = mode; $('container').className = 'mode-' + mode; }, setTitle: function(title) { document.title = title + ' - ' + SITE_TITLE; }, saveTab: function() { this.tabs.current.title = document.title; this.tabs.current.favicon = this.getFavicon(); this.tabs.current.scrollY = document.viewport.getScrollOffsets().top }, loadTab: function() { if (!Object.isUndefined(this.tabs.current.hash)) { router.routedHash(this.tabs.current.hash); } if (!Object.isUndefined(this.tabs.current.title)) { //wait to update History var title = this.tabs.current.title; var lastTitle = document.title; setTimeout(function() { if (lastTitle==document.title) { document.title = title; } }, 500); } if (!Object.isUndefined(this.tabs.current.favicon)) { this.setFavicon(this.tabs.current.favicon); } if (!Object.isUndefined(this.tabs.current.scrollY)) { window.scrollTo(0, this.tabs.current.scrollY); } this.updateBreadcrumb(); }, onBeforeRoute: function(location) { for (var tabCode in this.tabs) { if (tabCode!='current' && this.tabs[tabCode].hash==location) { this.gotoTab(tabCode); return false; } } return true; }, breadcrumbLevel2Handler: function() { if (this.level2=='catalog') { this.catalogButtonHandler() } else { this.gotoTab(this.level2); } }, updateBreadcrumb: function() { var breadcrumb = $$('.breadcrumb')[0]; if (this.tabs.current==this.tabs.catalog || this.tabs.current==this.tabs.bestsellers || this.tabs.current==this.tabs.search || this.tabs.current==this.tabs.settings ) { var elements = Element.select(breadcrumb, 'li'); if (elements[2]) { elements[2].remove(); } var a = Element.select(breadcrumb, 'a')[1]; switch (this.tabs.current) { case this.tabs.catalog: a.innerHTML = 'Каталог'; break; case this.tabs.bestsellers: a.innerHTML = 'Бестселлеры'; break; case this.tabs.search: a.innerHTML = 'Результаты поиска'; break; case this.tabs.settings: a.innerHTML = 'Настройки'; break; } $j('#nav li').removeClass('selected'); $j('#nav li.' + this.tabs.current.tabCode).addClass('selected'); } else if ( this.tabs.current==this.tabs.movie || this.tabs.current==this.tabs.person ) { if (this.tabs.current.name) { var elements = Element.select(breadcrumb, 'a'); if (elements.length==2) { var li = new Element('LI'); var a = new Element('A'); li.appendChild(a); breadcrumb.appendChild(li); } else { a = elements[2]; } a.innerHTML = this.tabs.current.name; } } $j('.breadcrumb li').each(function(i, el){ $j(el).css('z-index', 10-i); }); }, getCatalog: function(offset, genre, country, order, continuous) { var existsPage = this.getPageByOffset(offset); if (existsPage && genre==this.currentGenre && country==this.currentCountry && order==this.currentOrder) { this.gotoTab('catalog'); Effect.ScrollTo(existsPage.topElement, {duration: 0.15, offset: -20}); } else { if (Object.isUndefined(continuous)) { continuous = false; } if ((!this.continuousScrolling || !continuous) && document.viewport.getScrollOffsets().top>$('catalog_wrapper').cumulativeOffset().top) { Effect.ScrollTo($('main'), {duration: 0.15}); } this.currentOrder = order; this.currentGenre = genre; this.currentCountry = country; this.updateGenreWrapper(); this.updateCountryWrapper(); this.updateOrder(); window.action.getCatalog(offset, this.pageSize, genre, country, order, continuous); if (!this.catalogInited) { this.initCatalog(); } } }, drawCatalog: function(data, continuous) { this.gotoTab('catalog'); var title = "Каталог"; this.total = parseInt(data.total); var frameHtml = TEMPLATES.CATALOG.process(data); var wrapper = $('catalog'); if (!this.continuousScrolling || !continuous || !this.pages.length) { this.offset = parseInt(data.offset); this.setupPaginator(false); wrapper.innerHTML = frameHtml; var page = { offset: this.offset, top: wrapper.cumulativeOffset().top, topElement: wrapper, title: title }; this.pages = []; this.pages.push(page); this.continuousScrolling = true; this.removePageMarkers(); this.setTitle(title); this.setFavicon(); } else { var tempElement = new Element('TEMP'); tempElement.innerHTML = frameHtml; var childNodes = []; for (var i=0; i=this.limitPages) { this.continuousScrolling = false; if ((parseInt(data.offset)+this.pageSize)=5) { this.slidePersones(0); } else { window.action.getMoviePerson(personId); } }, hidePerson: function () { $j('#movie .person-preview.active').removeClass('active'); $('movie').removeClassName('show-pesonal-detail'); }, slidePersones: function(timeout) { var self = this; this.slidePersonesTimeout = setTimeout(function(){ $j('#movie .persones').removeClass('collapsed') }, timeout); }, cancelSlidePersones: function() { if (this.slidePersonesTimeout) { clearTimeout(this.slidePersonesTimeout); this.slidePersonesTimeout = null; } }, updateGenreWrapper: function() { if (this.currentGenre) { var el = $$('#genres_all li[data-id='+this.currentGenre+']', '#genres li[data-id='+this.currentGenre+']')[0]; var name = el? el.readAttribute('data-name') : ''; } else { var name = 'Любой жанр'; } $('genre').innerHTML = name; }, updateCountryWrapper: function() { if (this.currentCountry) { var el = $$('#countries_all li[data-id='+this.currentCountry+']', '#countries li[data-id='+this.currentCountry+']')[0]; var name = el? el.readAttribute('data-name') : ''; } else { var name = 'Любая страна'; } $('country').innerHTML = name; }, initNavigator: function() { window.action.getGenres(this.currentCountry); window.action.getCountries(this.currentGenre); }, initRecentViewed: function() { this.loadRecentlyViewed(); this.filterRecentlyViewed(); this.drawRecentlyViewed(); if (window.addEventListener) { window.addEventListener("storage", this.localStorageHandler.bind(this), false); } else { window.attachEvent("onstorage", this.localStorageHandler.bind(this)); }; }, saveRecentlyViewed: function() { if (!Modernizr.localstorage) {return false;} try { localStorage.setItem('user.recently_viewed', JSON.stringify(this.recentlyViewed)); } catch (e){ } }, loadRecentlyViewed: function() { if (!Modernizr.localstorage) {return false;} try { var l = localStorage.getItem('user.recently_viewed'); this.recentlyViewed = l? JSON.parse(l) : []; } catch (e){ } }, drawRecentlyViewed: function() { $('recently_viewed').innerHTML = TEMPLATES.RECENTLY_VIEWED.process({items: this.recentlyViewed}); $j('#recently_viewed a').click(this.hideFilters.bind(this)); if (this.recentlyViewed.length) { $j('#recently_viewed_menu_item').show(); } }, filterRecentlyViewed: function() { var time = new Date().getTime() - 24*3600*1000; this.recentlyViewed = this.recentlyViewed.findAll(function(s) {return s.time>time;}); this.recentlyViewed = this.recentlyViewed.slice(0, 99); this.recentlyViewed = this.recentlyViewed.sortBy(function(s) {return -s.time;}); }, addRecentlyViewedItem: function(name, url) { var founded = false; this.recentlyViewed.each(function(value, index) { if (value.url==url) { value.time = new Date().getTime(); founded = true; throw $break; } }, this); if (!founded) { var rv = { name: name, url: url, time: new Date().getTime() }; this.recentlyViewed.unshift(rv); } this.filterRecentlyViewed(); this.saveRecentlyViewed(); this.drawRecentlyViewed(); }, drawBookmarks: function(data) { this.bookmarks = data; $('bookmarks').innerHTML = TEMPLATES.BOOKMARKS.process(data); $j('#bookmarks a').click(this.hideFilters.bind(this)); $j('#bookmarks .bookmark-action[title]').tipsy({delayIn: 200}); }, unstarBookmark: function(filmId) { $j('#bookmarks li[mid=' + filmId + ']').remove(); $j('.bookmark[mid=' + filmId + ']').removeClass('on').attr("title", "Добавить в закладки"); var i = this.getBookmarkIndex(filmId); this.bookmarks.films.splice(i, 1); }, starBookmark: function(filmId) { $j('.bookmark[mid=' + filmId + ']').addClass('on').attr("title", "Удалить закладку"); }, getBookmarkIndex: function(filmId) { for (var i=0; i= threshold || s.id==self.currentGenre;}); items = items.slice(0, this.limitNavigationItems); items.unshift(allItem); data.genres.unshift(allItem); this._fillNavigation(items, $('genres')); if (items.length < data.genres.length) { this._fillNavigation(data.genres, $('genres_all')); $('genres_switcher').innerHTML = $('genres_switcher').readAttribute('data-default-text'); $('genres_switcher').show(); } else { $('genres_switcher').hide(); } $('genres').show(); $('genres_all').hide(); this.updateGenreWrapper(); }, drawCountries: function(data) { var self = this; data.countries.push({ name: 'Любая страна', id: null, count: '' }); for (var i=0; i= threshold || s.id==self.currentCountry;}); items = items.slice(0, this.limitNavigationItems); items.unshift(allItem); data.countries.unshift(allItem); this._fillNavigation(items, $('countries')); if (items.length < data.countries.length) { this._fillNavigation(data.countries, $('countries_all')); $('countries_switcher').innerHTML = $('countries_switcher').readAttribute('data-default-text'); $('countries_switcher').show(); } else { $('genres_switcher').hide(); } $('countries').show(); $('countries_all').hide(); this.updateCountryWrapper(); }, showGenres: function() { if ($j('#genres_menu_item').is('.active')) { this.overlay.close(); return; } this.overlay.close(); this.overlay.setTargetScroll($('genres_all')); this.overlay.show(); this.overlay.onClose = function() { $('genres_wrapper').hide(); $('genres_menu_item').removeClassName('active'); $('toolbar').removeClassName('active'); }; $('genres_wrapper').show(); $('genres_menu_item').addClassName('active'); $('toolbar').addClassName('active'); }, showCountries: function() { if ($j('#countries_menu_item').is('.active')) { this.overlay.close(); return; } this.overlay.close(); this.overlay.setTargetScroll($('countries_all')); this.overlay.show(); this.overlay.onClose = function() { $('countries_wrapper').hide(); $('countries_menu_item').removeClassName('active'); $('toolbar').removeClassName('active'); }; $('countries_wrapper').show(); $('countries_menu_item').addClassName('active'); $('toolbar').addClassName('active'); }, showSortMenu: function() { if ($j('#sort_menu_item').is('.active')) { this.overlay.close(); return; } this.overlay.close(); this.overlay.setTargetScroll(false); this.overlay.show(); this.overlay.onClose = function() { $('sort_wrapper').hide(); $('sort_menu_item').removeClassName('active'); $('toolbar').removeClassName('active'); }; $('sort_wrapper').show(); $('sort_menu_item').addClassName('active'); $('toolbar').addClassName('active'); }, showBookmarksMenu: function() { if ($j('#bookmarks_menu_item').is('.active')) { this.overlay.close(); return; } this.overlay.close(); this.overlay.setTargetScroll($('bookmarks')); this.overlay.show(); this.overlay.onClose = function() { $('bookmarks').hide(); $('bookmarks_menu_item').removeClassName('active'); $('toolbar').removeClassName('active'); }; $('bookmarks').show(); $('bookmarks_menu_item').addClassName('active'); $('toolbar').addClassName('active'); }, showMovieModerMenu: function() { if ($j('#movie_moder_menu_item').is('.active')) { this.overlay.close(); return; } this.overlay.close(); this.overlay.setTargetScroll(false); this.overlay.show(); this.overlay.onClose = function() { $('movie_moder_wrapper').hide(); $('movie_moder_menu_item').removeClassName('active'); $('toolbar').removeClassName('active'); }; $('movie_moder_wrapper').show(); $('movie_moder_menu_item').addClassName('active'); $('toolbar').addClassName('active'); }, showRecentlyViewedMenu: function() { if ($j('#recently_viewed_menu_item').is('.active')) { this.overlay.close(); return; } this.overlay.close(); this.overlay.setTargetScroll($('recently_viewed')); this.overlay.show(); this.overlay.onClose = function() { $('recently_viewed').hide(); $('recently_viewed_menu_item').removeClassName('active'); $j('.toolbar.top').removeClass('active'); }; $('recently_viewed').show(); $('recently_viewed_menu_item').addClassName('active'); $j('.toolbar.top').addClass('active'); }, hideFilters: function() { this.overlay.close(); }, switchFilter: function(el) { var wrapper = el.parentNode; Element.select(wrapper, '.pop').invoke('toggle'); Element.select(wrapper, '.all').invoke('toggle'); switch (el.innerHTML) { case el.readAttribute('data-default-text'): el.innerHTML = el.readAttribute('data-back-text'); break; case el.readAttribute('data-back-text'): el.innerHTML = el.readAttribute('data-default-text'); break; } }, highlightNavigator: function() { $$('#genres li.selected', '#genres_more li.selected').invoke('removeClassName', 'selected'); $$('#genres li[data-id='+this.currentGenre+']', '#genres_more li[data-id='+this.currentGenre+']').invoke('addClassName', 'selected'); $$('#countries li.selected', '#countries_more li.selected').invoke('removeClassName', 'selected'); $$('#countries li[data-id='+this.currentCountry+']', '#countries_more li[data-id='+this.currentCountry+']').invoke('addClassName', 'selected'); }, routeTo: function(newParams, name, reset) { if (Object.isUndefined(name)) { name = router.getAction(); } if (Object.isUndefined(reset)) { reset = false; } if (reset || name!=router.getAction()) { var currentParams = $H(); } else { var currentParams = router.getParams(); } var params = currentParams.merge(newParams); this.emit('route', name, params); }, updateOrder: function() { var order = this.currentOrder!=null? this.currentOrder : 0; var shortText = $j('#sort_wrapper a[data-order="' + order + '"]').attr('data-short-text'); $('sort').innerHTML = shortText; }, setOrder: function(order) { this.routeTo({order: order, page: 1}, 'catalog'); this.hideFilters(); }, setOffset: function(offset) { var page = this.offsetToPageNumber(offset); this.routeTo({page: page}, 'catalog'); return; var params = {}; params.genre = this.currentGenre; params.country = this.currentCountry; params.order = this.currentOrder; var page = this.offsetToPageNumber(offset); params.page = page; this.emit('route', 'catalog', params); }, onOffsetChanged: function(offset) { var params = {}; var page = this.offsetToPageNumber(offset); params.genre = this.currentGenre; params.country = this.currentCountry; params.order = this.currentOrder; params.page = page; var action = 'catalog'; var hash = router.url(action, params).substring(1); router.routedHash(hash); this.tabs.catalog.hash = hash; }, _mousewheelHandler: function() { if (this.mode=='catalog') { if ($j.browser.opera) { if (this.paginator.hasClassName('fixed')) { this.paginator.removeClassName('fixed') $j('.scroll-up').removeClass('visible'); } } } }, _scrollHandler: function() { if (this.mode=='catalog') { var top = $('catalog').cumulativeOffset().top; var scrollTop = document.viewport.getScrollOffsets().top; if (scrollTop>top) { if ($j.browser.opera) { var s = $j('.scroll-up'); if (s.hasClass('visible')) { s.hide().removeClass('visible'); } if (this.scrollTimeoutId) { clearTimeout(this.scrollTimeoutId); } this.scrollTimeoutId = setTimeout(function(){ if (!s.hasClass('visible')) { s.fadeIn('slow').addClass('visible'); } }, 200); } else { if (!this.paginator.hasClassName('fixed')) { this.paginator.addClassName('fixed'); $j('.scroll-up').fadeIn('slow').addClass('visible'); } } } else { if (this.paginator.hasClassName('fixed')) { this.paginator.removeClassName('fixed') $j('.scroll-up').hide().removeClass('visible'); } if ($j.browser.opera && this.scrollTimeoutId) { clearTimeout(this.scrollTimeoutId); } } var lastItem = $$('#catalog .item').pop(); var scrollBottom = scrollTop + document.viewport.getHeight(); var lastItemTop = lastItem.cumulativeOffset().top; if (lastItemTop1) { var offset = this.pages[0].offset; var page = null; for (var i=1; i0) { setTimeout(function(){ $('search_suggestion').show(); }, 300); } }); s.blur(function () { setTimeout(function(){ $('search_suggestion').hide(); }, 400); }); s.keydown(function (a) { if (a.keyCode == 38) { /* j.focus(); q();*/ return false } else if (a.keyCode == 40) { /*j.focus(); B();*/ return false } else if (a.keyCode == 13) { setTimeout(self.search.bind(self), 10); s.blur(); return false } else if (a.keyCode == 27) { /*I(); z();*/ return false } /* j.focus(); p = setTimeout(F, 0)*/ setTimeout(self.getSuggestion.bind(self), 10); }); }, search: function() { var query = $j('#search_query').val(); if (query.length>0) { this.routeTo({query: query}, 'search', true); } }, getSuggestion: function() { var text = $j('#search_query').val(); if (text.length>0) { if (this.lastSuggestionQuery!=text) { window.action.getSuggestion(text); } } else { $('search_suggestion').innerHTML = ''; } }, drawSuggestion: function(data) { if ((data.films.length || data.persones.length) && data.query==$j('#search_query').val()) { this.lastSuggestionQuery = data.query; $('search_suggestion').innerHTML = TEMPLATES.SEARCH_SUGGESTION.process(data); $('search_suggestion').show(); } }, catalogButtonHandler: function() { if (this.tabs.catalog.hash) { this.gotoTab('catalog'); } else { this.routeTo({}, 'catalog'); } }, searchButtonHandler: function() { if (this.tabs.catalog.hash) { this.gotoTab('search'); } }, setFavicon: function(url) { if (!url) { url = DEFAULT_FAVICON; } if (url!=this.getFavicon()) { $j('link[rel$=icon]').remove(); $j('head').append($j('').attr('href', url)); } }, getFavicon: function() { return $j('link[rel$=icon]').attr('href'); }, _setPersonalRating: function(value) { var w = 100*(value/10) + '%'; $j('#personal_rating .inner').width(w); $j('#personal_rating .value').text(value? value : ''); }, _setLocalRating: function(value, count) { var w = 100*(value/10) + '%'; $j('#local_rating .inner').width(w); $j('#local_rating .value').text(value); $j('#local_rating .starbar').attr('title', "Локальный рейтинг: " + value + " (" + count + " голосов)"); if (parseFloat(value)) { $j('#local_rating').show(); } else { $j('#local_rating').hide(); } }, rateMouseOverHandler: function(rating) { this._setPersonalRating(rating); }, rateMouseOutHandler: function() { var rating = parseInt($j('#personal_rating').attr('data-value')); if (!rating) { rating = 0; } this._setPersonalRating(rating); }, updateRating: function(data) { var rating = parseInt(data.rating_personal_value); $j('#personal_rating').attr('data-value', rating); this._setPersonalRating(rating); if (rating) { $j('#personal_rating .remove').show(); } else { $j('#personal_rating .remove').hide(); } this._setLocalRating(data.rating_local_value, data.rating_local_count); }, postComment: function(filmId) { var text = $('comment_text').value; window.action.postComment(filmId, text); }, beginEditComment: function (commentId) { var textElement = $j('#movie_comments .message[cid="' + commentId + '"] .text'); if (textElement.attr("contenteditable")!="true") { textElement.attr("contenteditable", true); textElement.data('original_text', this.textizeHtml(textElement.html())); var self = this; var cancelButton = $j('Отмена').click(function(){self.cancelEditComment(commentId)}); var okButton = $j('Сохранить').click(function(){self.saveComment(commentId)}); var actions = $j('
'); actions.append(cancelButton) .append(okButton) .insertAfter(textElement); textElement.focus(); } }, cancelEditComment: function (commentId) { var textElement = $j('#movie_comments .message[cid="' + commentId + '"] .text'); if (textElement.attr("contenteditable")=="true") { textElement.attr("contenteditable", false); var text = textElement.data('original_text'); textElement.html(this.htmlizeText(text)); $j('#movie_comments .message[cid="' + commentId + '"] .edit-buttons').remove(); } }, saveComment: function (commentId) { var textElement = $j('#movie_comments .message[cid="' + commentId + '"] .text'); if (textElement.attr("contenteditable")) { textElement.attr("contenteditable", false); var text = this.textizeHtml(textElement.html()); textElement.html(this.htmlizeText(text)); $j('#movie_comments .message[cid="' + commentId + '"] .edit-buttons').remove(); window.action.editComment(commentId, text); } }, deleteComment: function(commentId) { if (confirm('Удалить комментарий?')) { window.action.deleteComment(commentId); } }, postDeleteComment: function(commentId) { $j('.message[cid=' + commentId + ']').remove(); }, textizeHtml: function (html) { return html.replace(//gi, '\r\n') .replace(/]*?href=([^>\s]*)[^>]*>(.*?)<\/a>/gi, function(){ var href = arguments[2].match(/^https?:/)? arguments[2] : arguments[1]; return href.replace(/^["']+/, '').replace(/["']+$/, '').unescapeHTML(); }) .strip(); }, htmlizeText: function (text) { return text.replace(/(\r\n|\r|\n)/gi, '
') .replace(/((?:https?:\/\/|magnet:\?|ed2k:\/\/)[^\s<]+)/gi, '$1'); }, highlightElement: function (domId) { new Effect.Highlight(domId, {startcolor: '#ffebe8', restorecolor: true}); }, changePassword: function() { var oldPassword = $('password_old').value; if (!oldPassword) { this.highlightElement('password_old'); return; } var newPassword = $('password_new').value; if (!newPassword) { this.highlightElement('password_new'); return; } if (newPassword!= $('password_repeat').value) { this.emit('userError', 400, 'Пароли не совпадают!'); this.highlightElement('password_repeat'); return; } window.action.changePassword(oldPassword, newPassword); }, postChangePassword: function() { this.emit('userMessage', 'Пароль успешно сменен'); $('password_old').value = ''; $('password_new').value = ''; $('password_repeat').value = ''; }, initHacks: function() { if ($j.browser.msie && $j.browser.version<=7) { $j(window).resize(function() { $j('#container').width($j('body').width); }); $j(window).resize(); } if ($j.browser.opera) { $j('html').addClass('opera'); } }, selectSettingPage: function(page) { $j('#settings_wrapper .menu-item').removeClass('selected'); $j('#settings_wrapper .menu-item[data-page="'+page+'"]').addClass('selected'); $j('#settings_wrapper .content').hide(); $j('#settings_wrapper .content.' + page).show(); }, saveVideoplayerSettings: function() { var vp = $j('#videoplayer_settings input[name="videoplayer"]:checked').val(); $j.Storage.set("videoplayer", vp); this.emit('userMessage', 'Настройки сохранены'); $j.fancybox.close(); $j('#movie_wrapper a[rel="videoplayer"]').unbind('click.fb').each(function() { var href = $j(this).attr('href'); href = href.replace(/player=[^&]+/, 'player=' + vp); $j(this).attr('href', href); }); }, loadVideoplayerSettings: function() { var vp = $j.Storage.get("videoplayer"); if (vp) { $j('#settings_wrapper input[value="' + vp + '"]').attr('checked', 'checked'); } }, saveLinksSettings: function() { var links = {}; $j('#links_settings input[name="links"]').each(function(){ var type = $j(this).val(); links[type] = $j(this).is(':checked'); }); $j.Storage.set("links", JSON.stringify(links)); this.emit('userMessage', 'Настройки сохранены'); }, loadLinksSettings: function() { var self = this; $j('#settings_wrapper input[name="links"]').each(function(){ var type = $j(this).val(); if (self.isLinkTypeEnabled(type)) { $j(this).attr('checked', 'checked'); } else { $j(this).removeAttr('checked'); } }); }, isLinkTypeEnabled: function(type) { var links = $j.Storage.get("links"); links = links? JSON.parse(links) : {}; return (!Object.isUndefined(links[type]))? links[type] : SETTINGS.DOWNLOAD_DEFAULTS[type]; } };