Файловый менеджер - Редактировать - /var/www/html/views.zip
Ðазад
PK ! �e� postbox/file-preview.jsnu �[��� define('views/postbox/file-preview',[ 'sandbox', 'app', 'views/base', 'utils/ajax', 'utils/constants', 'utils/language' ], // definition // ---------- function( $, App, BaseView, ajax, constants, language ) { return BaseView.extend({ templates: { div: _.template( '<div class=joms-postbox-photo-preview> \ <ul class="joms-list clearfix"></ul> \ </div>' ), file: _.template( '<li id="<%= id %>" data-fileid="" class=joms-postbox-photo-item> \ <div class=img-wrapper> \ <svg viewBox="0 0 16 18" class="joms-icon">\ <use xlink:href="<%= window.joms_current_url %>#joms-icon-file-zip" class="joms-icon--svg-fixed joms-icon--svg-unmodified joms-icon--svg-unmodified"></use>\ </svg> \ <b class="joms-filename"><%= name %></b>\ </div> \ <div class=joms-postbox-photo-action style="display:none"> \ <span class=joms-postbox-photo-remove>×</span> \ </div> \ <div class=joms-postbox-file-progressbar> \ <div class=joms-postbox-file-progress></div> \ </div> \ </li>' ) }, events: { 'click .joms-postbox-photo-remove': 'onRemove' }, render: function() { this.$el.html( this.templates.div() ); this.$list = this.$el.find('ul.joms-list'); this.$form = this.$el.find('div.joms-postbox-photo-form'); }, add: function( file ) { this.$list.append( this.templates.file({ id: this.getFileId( file ), name: file.name, src: App.legacyUrl + '/assets/photo-upload-placeholder.png' }) ); var settings = constants.get('settings') || {}; if ( !settings.isMyProfile ) return; if ( this.select ) return; var albums = constants.get('album'), privs = language.get('privacy'), options = []; var privmap = { '0': 'public', '10': 'public', '20': 'site_members', '30': 'friends', '40': 'me' }; var icons = { '0': 'earth', '10': 'public', '20': 'users', '30': 'user', '40': 'lock' }; if ( !(albums && albums.length) ) return; this.albummap = {}; for ( var i = 0, album, permission; i < albums.length; i++ ) { album = albums[i]; permission = '' + album.permissions; this.albummap[ '' + album.id ] = permission; album = [ album.id, album.name, privs[ privmap[permission] || '0' ], icons[permission || '0'] ]; options[ +album['default'] ? 'unshift' : 'push' ]( album ); } }, value: function() { var settings = constants.get('settings') || {}, album_id, privacy, values; values = { id: this.files || [] }; return values; }, updateProgress: function( file ) { var id = this.getFileId( file ), elem = this.$list.find( '#'+ id ).find('.joms-postbox-file-progress'), percent; if ( elem && elem.length ) { percent = Math.min( 100, Math.floor( file.loaded / file.size * 100 ) ); elem.stop().animate({ width: percent + '%' }); } }, setFile: function( file, json ) { json || (json = {}); var elem = this.$list.find( '#' + this.getFileId(file) ), id = json.id; elem.find('.joms-filename').text(file.name); elem.attr('data-id', json.id); elem.find('.joms-postbox-photo-action').show(); elem.addClass('joms-postbox-photo-loaded'); elem.find('.joms-postbox-photo-progressbar').remove(); this.files || (this.files = []); this.files.push( '' + id ); this.trigger( 'update', this.files.length ); }, removeFailed: function() { this.$list.find('.joms-postbox-photo-item') .not('.joms-postbox-photo-loaded') .remove(); this.trigger( 'update', this.files && this.files.length || 0 ); }, // --------------------------------------------------------------------- // Thumbnail event handlers. // --------------------------------------------------------------------- onRemove: function( e ) { var li = $( e.target ).closest('li'), id = li.data('id'), num; li.remove(); this.files = $.without( this.files, '' + id ); num = this.files.length; this.ajaxRemove([ id ]); this.trigger( 'update', num ); }, remove: function() { this.files && this.files.length && this.ajaxRemove( this.files ); return BaseView.prototype.remove.apply( this, arguments ); }, ajaxRemove: function( files ) { var params = {}; params.option = 'community'; params.no_html = 1; params.task = 'azrul_ajax'; params.func = 'system,ajaxDeleteTempFile'; params[ window.jax_token_var ] = 1; if ( files && files.length ) params[ 'arg2[]' ] = files; $.ajax({ url: window.jax_live_site, type: 'post', dataType: 'json', data: params }); }, // --------------------------------------------------------------------- // Helper functions. // --------------------------------------------------------------------- getFileId: function( file ) { return 'postbox-preview-' + file.id; }, getNumFiles: function() { return this.$list.find('li').length; } }); }); PK ! ����3 3 postbox/poll-settings.jsnu �[��� define('views/postbox/poll-settings', [ 'sandbox', 'views/base', 'utils/language' ], function($, BaseView, language) { return BaseView.extend({ template: _.template( '<!--<div class="settings-item">\ <input type="checkbox" name="allow_add">\ <span style="cursor:pointer" class="settings-item--label">Allow any one to add options</span>\ </div>-->\ <div class="settings-item">\ <input type="checkbox" name="allow_multiple">\ <span style="cursor:pointer" class="settings-item--label"><%= language.allow_multiple_choices %></span>\ </div>' ), getTemplate: function() { var html = this.template({ language: language.get('poll') }); return $(html); }, render: function() { this.$el.html( this.getTemplate() ); }, events: $.extend({}, BaseView.prototype.events, { 'click .settings-item--label': 'toggleCheckbox', }), toggleCheckbox: function(e) { var $checkbox = $(e.currentTarget).siblings('input[type=checkbox]'); $checkbox.prop('checked', !$checkbox.prop('checked')); }, reset: function() { this.$el.html(''); this.render(); }, value: function() { var allow_add = this.$el.find('input[name=allow_add]'), allow_multiple = this.$el.find('input[name=allow_multiple]'); return { settings: { allow_add: allow_add.prop('checked'), allow_multiple: allow_multiple.prop('checked') } } } }) }); PK ! �@*� � postbox/layout.jsnu �[��� define('views/postbox/layout',[ 'sandbox', 'views/base', 'views/postbox/status', 'views/postbox/photo', 'views/postbox/video', 'views/postbox/event', 'views/postbox/file', 'views/postbox/poll', 'views/postbox/custom', 'utils/constants', 'utils/language' ], // definition // ---------- function( $, BaseView, StatusView, PhotoView, VideoView, EventView, FileView, PollView, CustomView, constants, language ) { return BaseView.extend({ subflags: {}, subviews: { status: StatusView, photo: PhotoView, video: VideoView, event: EventView, file: FileView, poll: PollView, custom: CustomView }, events: { 'click .joms-postbox-tab-root li': 'onChangeTab' }, initialize: function() { this.listenTo( $, 'postbox:status', this.onOpenStatusTab ); this.listenTo( $, 'postbox:photo', this.onOpenPhotoTab ); this.listenTo( $, 'postbox:video', this.onOpenVideoTab ); this.listenTo( $, 'postbox:file', this.onOpenFileTab ); this.listenTo( $, 'postbox:poll', this.onOpenPollTab ); }, render: function() { var settings = constants.get('settings') || {}, conf = constants.get('conf') || {}; if ( !settings.isAdmin || !conf.enablecustoms ) this.subviews = $.omit( this.subviews, 'custom' ); if ( settings.isProfile && !settings.isMyProfile ) this.subviews = $.pick( this.subviews, 'status', 'photo', 'video', 'file', 'poll' ); if ( settings.isEvent ) this.subviews = $.omit( this.subviews, 'event' ); if ( settings.isProfile || settings.isGroup || settings.isEvent || settings.isPage ) { conf.enablephotos || (this.subviews = $.omit( this.subviews, 'photo' )); conf.enablevideos || (this.subviews = $.omit( this.subviews, 'video' )); conf.enableevents || (this.subviews = $.omit( this.subviews, 'event' )); conf.enablefiles || (this.subviews = $.omit( this.subviews, 'file' )); conf.enablepolls || (this.subviews = $.omit( this.subviews, 'poll' )); } // cache subview keys this.subkeys = $.keys( this.subviews ); // cache elements this.$subviews = this.$('.joms-postbox-tabs'); this.$tab = this.$('.joms-postbox-tab-root').hide(); // remove unused tab var that = this; this.$tab.find('li').each(function() { var elem = $( this ), key = elem.data('tab'); if ( that.subkeys.indexOf( key ) < 0 ) elem.remove(); }); if ( this.subkeys && this.subkeys.length ) this.changeTab( this.subkeys[0] ); }, show: function() { this.$el[ $.isMobile ? 'show' : 'fadeIn' ](); }, changeTab: function( type ) { if ( !this.subviews[ type ] ) return; var elem = this.$tab.find( 'li[data-tab=' + type + ']' ); if ( elem && elem.length ) { elem.hasClass('active') || elem.addClass('active'); elem.siblings('.active').removeClass('active'); } if ( !this.subflags[ type ] ) this.initSubview( type ); for ( var prop in this.subflags ) if ( prop !== type ) this.subviews[ prop ].hide(); this.subviews[ type ].show(); this.type = type; $.trigger( 'postbox:tab:change', type ); }, // --------------------------------------------------------------------- // Event handlers. // --------------------------------------------------------------------- onChangeTab: function( e ) { this.changeTab( $( e.currentTarget ).data('tab') ); }, onOpenStatusTab: function() { this.changeTab('status'); }, onOpenPhotoTab: function() { this.changeTab('photo'); }, onOpenVideoTab: function() { this.changeTab('video'); }, onOpenFileTab: function() { this.changeTab('file'); }, onOpenPollTab: function() { this.changeTab('poll'); }, onShowInitialState: function() { if ( this.subkeys.length > 1 ) this.$tab.show(); }, onShowMainState: function() { this.$tab.hide(); }, // --------------------------------------------------------------------- // Lazy subview initialization. // --------------------------------------------------------------------- initSubview: function( type ) { if ( !this.subflags[ type ] ) { this.subviews[ type ] = new this.subviews[ type ]({ single: this.subkeys.length <= 1 }); this.assign( this.getSubviewElement(), this.subviews[ type ] ); this.listenTo( this.subviews[ type ], 'show:initial', this.onShowInitialState ); this.listenTo( this.subviews[ type ], 'show:main', this.onShowMainState ); this.subflags[ type ] = true; } }, getSubviewElement: function() { var div = $('<div>').hide().appendTo( this.$subviews ); return div; } }); });PK ! 9ԗ�� � postbox/gif-preview.jsnu �[��� define('views/postbox/gif-preview',[ 'views/postbox/photo-preview' ], // definition // ---------- function( PreviewView ) { return PreviewView.extend({ render: function() { PreviewView.prototype.render.apply( this, arguments ); this.$el.addClass('joms-postbox-gif-preview'); }, add: function() { PreviewView.prototype.add.apply( this, arguments ); this.$el.find('.joms-postbox-select-album').hide(); }, setImage: function( file, json ) { json || (json = {}); var elem = this.$list.find( '#' + this.getFileId(file) ), src = json.image, id = json.id; elem.find('img').attr( 'src', src ).data( 'id', id ); elem.find('img').attr( 'style', 'visibility:visible'); elem.find('.joms-postbox-photo-action').show(); elem.addClass('joms-postbox-photo-loaded'); elem.find('.joms-postbox-photo-progressbar').remove(); this.pics || (this.pics = []); this.pics.push( '' + id ); this.trigger( 'update', this.pics.length ); } }); });PK ! ,��ي � postbox/photo-preview.jsnu �[��� define('views/postbox/photo-preview',[ 'sandbox', 'app', 'views/base', 'views/widget/select-album', 'utils/ajax', 'utils/constants', 'utils/language' ], // definition // ---------- function( $, App, BaseView, SelectWidget, ajax, constants, language ) { return BaseView.extend({ templates: { div: joms.jst[ 'html/postbox/photo-preview' ], img: joms.jst[ 'html/postbox/photo-item' ] }, events: { 'click .joms-postbox-photo-remove': 'onRemove' }, render: function() { this.$el.html( this.templates.div() ); this.$list = this.$('ul'); this.$form = this.$('div.joms-postbox-photo-form'); }, add: function( file ) { this.$list.append( this.templates.img({ id: this.getFileId( file ), src: App.legacyUrl + '/assets/photo-upload-placeholder.png' }) ); var settings = constants.get('settings') || {}; if ( !settings.isMyProfile ) return; if ( this.select ) return; var albums = constants.get('album'), privs = language.get('privacy'), options = []; var privmap = { '0': 'public', '10': 'public', '20': 'site_members', '30': 'friends', '40': 'me' }; var icons = { '0': 'earth', '10': 'public', '20': 'users', '30': 'user', '40': 'lock' }; if ( !(albums && albums.length) ) return; this.albummap = {}; for ( var i = 0, album, permission; i < albums.length; i++ ) { album = albums[i]; permission = '' + album.permissions; this.albummap[ '' + album.id ] = permission; album = [ album.id, album.name, privs[ privmap[permission] || '0' ], icons[permission || '0'] ]; options[ +album['default'] ? 'unshift' : 'push' ]( album ); } this.select = new SelectWidget({ options: options }); var div = $('<div class="joms-postbox-select-album joms-select" style="padding:3px 0">').insertAfter( this.$form ); this.assign( div, this.select ); }, value: function() { var settings = constants.get('settings') || {}, album_id, privacy, values; values = { id: this.pics || [] }; if ( this.select && settings.isMyProfile ) { values.album_id = '' + this.select.value(); values.privacy = this.albummap[ album_id ]; } return values; }, updateProgress: function( file ) { var id = this.getFileId( file ), elem = this.$list.find( '#'+ id ).find('.joms-postbox-photo-progress'), percent; if ( elem && elem.length ) { percent = Math.min( 100, Math.floor( file.loaded / file.size * 100 ) ); elem.stop().animate({ width: percent + '%' }); } }, setImage: function( file, json ) { json || (json = {}); var elem = this.$list.find( '#' + this.getFileId(file) ), src = constants.get('juri.base') + json.thumbnail, id = json.id; elem.find('img').attr( 'src', src ).data( 'id', id ); elem.find('img').attr( 'style', 'visibility:visible'); elem.find('.joms-postbox-photo-action').show(); elem.addClass('joms-postbox-photo-loaded'); elem.find('.joms-postbox-photo-progressbar').remove(); this.pics || (this.pics = []); this.pics.push( '' + id ); this.trigger( 'update', this.pics.length ); }, removeFailed: function() { this.$list.find('.joms-postbox-photo-item') .not('.joms-postbox-photo-loaded') .remove(); this.trigger( 'update', this.pics && this.pics.length || 0 ); }, // --------------------------------------------------------------------- // Thumbnail event handlers. // --------------------------------------------------------------------- onRemove: function( e ) { var li = $( e.target ).closest('li'), id = li.find('img').data('id'), num; li.remove(); this.pics = $.without( this.pics, '' + id ); num = this.pics.length; if ( num <= 0 ) { this.select && this.select.remove(); } this.ajaxRemove([ id ]); this.trigger( 'update', num ); }, remove: function() { this.pics && this.pics.length && this.ajaxRemove( this.pics ); return BaseView.prototype.remove.apply( this, arguments ); }, ajaxRemove: function( pics ) { var params = {}; params.option = 'community'; params.no_html = 1; params.task = 'azrul_ajax'; params.func = 'system,ajaxDeleteTempImage'; params[ window.jax_token_var ] = 1; if ( pics && pics.length ) params[ 'arg2[]' ] = pics; $.ajax({ url: window.jax_live_site, type: 'post', dataType: 'json', data: params }); }, // --------------------------------------------------------------------- // Helper functions. // --------------------------------------------------------------------- getFileId: function( file ) { return 'postbox-preview-' + file.id; }, getNumPics: function() { return this.$list.find('li').length; } }); });PK ! ��p9 p9 postbox/status.jsnu �[��� define('views/postbox/status',[ 'sandbox', 'app', 'views/postbox/default', 'views/postbox/fetcher', 'views/inputbox/status', 'views/dropdown/mood', 'views/dropdown/location', 'views/dropdown/privacy', 'utils/constants', 'utils/language' ], // definition // ---------- function( $, App, DefaultView, FetcherView, InputboxView, MoodView, LocationView, PrivacyView, constants, language ) { return DefaultView.extend({ subviews: { mood: MoodView, location: LocationView, privacy: PrivacyView }, template: _.template( '<div class=joms-postbox-status>\ <div class=joms-postbox-fetched></div>\ <div class=joms-postbox-inputbox></div>\ <nav class="joms-postbox-tab selected">\ <ul class="joms-list inline">\ <li data-tab=mood><svg viewBox="0 0 16 18" class="joms-icon"><use xlink:href="<%= window.joms_current_url %>#joms-icon-happy"></use></svg></li>\ <li data-tab=location><svg viewBox="0 0 16 18" class="joms-icon"><use xlink:href="<%= window.joms_current_url %>#joms-icon-location"></use></svg></li>\ <li data-tab=privacy><svg viewBox="0 0 16 18" class="joms-icon"><use xlink:href="<%= window.joms_current_url %>#joms-icon-earth"></use></svg> </li>\ <% if (enablephoto) { %>\ <li data-tab=photo data-bypass=1><svg viewBox="0 0 16 18" class="joms-icon"><use xlink:href="<%= window.joms_current_url %>#joms-icon-camera"></use></svg></li>\ <% } %>\ <% if (enablevideo) { %>\ <li data-tab=video data-bypass=1><svg viewBox="0 0 16 18" class="joms-icon"><use xlink:href="<%= window.joms_current_url %>#joms-icon-play"></use></svg></li>\ <% } %>\ <% if (enablefile) { %>\ <li data-tab=file data-bypass=1><svg viewBox="0 0 16 18" class="joms-icon"><use xlink:href="<%= window.joms_current_url %>#joms-icon-file-zip"></use></svg></li>\ <% } %>\ <% if (enablepoll) { %>\ <li data-tab=poll data-bypass=1><svg viewBox="0 0 16 18" class="joms-icon"><use xlink:href="<%= window.joms_current_url %>#joms-icon-list"></use></svg></li>\ <% } %>\ </ul>\ <div class=joms-postbox-action>\ <button class=joms-postbox-cancel><%= language.postbox.cancel_button %></button>\ <button class=joms-postbox-save><%= language.postbox.post_button %></button>\ </div>\ <div class=joms-postbox-loading style="display:none;">\ <img src="<%= juri.root %>components/com_community/assets/ajax-loader.gif" alt="loader">\ <div>\ </nav>\ </div>' ), getTemplate: function() { var settings = constants.get('settings') || {}, conf = constants.get('conf') || {}, enablephoto = true, enablevideo = true, enablefile = true, enablepoll = true; if ( settings.isProfile || settings.isGroup || settings.isEvent || settings.isPage ) { conf.enablephotos || (enablephoto = false); conf.enablevideos || (enablevideo = false); conf.enablefiles || (enablefile = false); conf.enablepolls || (enablepoll = false); } var html = this.template({ juri: constants.get('juri'), enablephoto: enablephoto, enablevideo: enablevideo, enablefile: enablefile, enablepoll: enablepoll, language: { postbox: language.get('postbox') || {}, status: language.get('status') || {} } }); return $( html ).hide(); }, events: $.extend({}, DefaultView.prototype.events, { 'click li[data-tab=photo]': 'onAddPhoto', 'click li[data-tab=video]': 'onAddVideo', 'click li[data-tab=file]': 'onAddFile', 'click li[data-tab=poll]': 'onAddPoll' }), initialize: function() { var settings = constants.get('settings') || {}; if ( this.inheritPrivacy = (settings.isPage || settings.isGroup || settings.isEvent || !settings.isMyProfile)) this.subviews = $.omit( this.subviews, 'privacy' ); var moods = constants.get('moods'); this.enableMood = +constants.get('conf.enablemood') && moods && moods.length; if ( !this.enableMood ) this.subviews = $.omit( this.subviews, 'mood' ); this.enableLocation = +constants.get('conf.enablelocation'); if ( !this.enableLocation ) this.subviews = $.omit( this.subviews, 'location' ); DefaultView.prototype.initialize.apply( this ); }, render: function() { DefaultView.prototype.render.apply( this ); this.$inputbox = this.$('.joms-postbox-inputbox'); this.$fetcher = this.$('.joms-postbox-fetched'); this.$tabmood = this.$tabs.find('[data-tab=mood]'); this.$tablocation = this.$tabs.find('[data-tab=location]'); this.$tabprivacy = this.$tabs.find('[data-tab=privacy]'); if ( !this.enableMood ) this.$tabmood.remove(); if ( !this.enableLocation ) this.$tablocation.remove(); if ( this.inheritPrivacy ) { if ( this.$tabprivacy.next().length ) this.$tabprivacy.remove(); else this.$tabprivacy.css({ visibility: 'hidden' }); } // inputbox this.inputbox = new InputboxView({ attachment: true, charcount: true, status: true }); this.assign( this.$inputbox, this.inputbox ); this.listenTo( this.inputbox, 'focus', this.onInputFocus ); this.listenTo( this.inputbox, 'keydown', this.onInputUpdate ); this.listenTo( this.inputbox, 'paste', this.onInputUpdate ); this.listenTo( this.inputbox, 'change:type', this.onInputChangeType ); // init privacy var defaultPrivacy, settings; if ( !this.inheritPrivacy ) { settings = constants.get('settings') || {}; if ( settings.isProfile && settings.isMyProfile ) defaultPrivacy = constants.get('conf.profiledefaultprivacy'); this.initSubview('privacy', { privacylist: window.joms_privacylist, defaultPrivacy: defaultPrivacy || 'public' }); } if ( this.single ) this.listenTo( $, 'click', this.onDocumentClick ); return this; }, // --------------------------------------------------------------------- // Data validation and retrieval. // --------------------------------------------------------------------- reset: function() { DefaultView.prototype.reset.apply( this ); this.inputbox && this.inputbox.reset(); this.fetcher && this.fetcher.remove(); }, value: function() { this.data.text = this.inputbox.value() || ''; this.data.text = this.data.text.replace( /\n/g, '\\n' ); this.data.attachment = {}; if (this.inputbox.colorful) { this.data.attachment.colorful = true; this.data.attachment.bgid = this.inputbox.bgid; } var value; for ( var prop in this.subflags ) if ( value = this.subviews[ prop ].value() ) this.data.attachment[ prop ] = value; if ( this.fetcher ) this.data.attachment.fetch = this.fetcher.value(); return DefaultView.prototype.value.apply( this, arguments ); }, validate: $.noop, // --------------------------------------------------------------------- // Inputbox event handlers. // --------------------------------------------------------------------- onInputChangeType: function(type) { if (type) { this.$tabmood.attr('style', 'display: none !important'); this.$tablocation.attr('style', 'display: none !important'); } else { this.$tabmood.attr('style', ''); this.$tablocation.attr('style', ''); } }, onInputFocus: function() { this.showMainState(); }, onInputUpdate: function( text, key ) { var div; text = text || ''; this.togglePostButton( text ); if ( key === 32 || key === 13 ) { this.fetch( text ); } else { this.fetchProxy( text ); } }, // --------------------------------------------------------------------- // Fetching event handler. // --------------------------------------------------------------------- fetchProxy: $.debounce(function( text ) { this.fetch( text ); }, 1000 ), fetch: function( text ) { var div; if ( this.fetcher && (this.fetcher.fetching || this.fetcher.fetched) ) return; if ( this.fetcher ) this.fetcher.remove(); div = $('<div>').appendTo( this.$fetcher ); this.fetcher = new FetcherView(); this.fetcher.setElement( div ); this.listenTo( this.fetcher, 'fetch:start', this.onFetchStart ); this.listenTo( this.fetcher, 'fetch:done', this.onFetchDone ); this.listenTo( this.fetcher, 'remove', this.onFetchRemove ); this.fetcher.fetch( text.replace( /^\s+|\s+$/g, '' ) ); }, onFetchStart: function() { this.saving = true; this.$loading.show(); }, onFetchDone: function() { this.$loading.hide(); this.saving = false; }, onFetchRemove: function() { this.fetcher = false; }, onDocumentClick: function( elem ) { if ( elem.closest('.joms-postbox').length ) return; var text = this.inputbox.value(); text = text.replace( /^\s+|\s+$/g, '' ); if ( !text ) this.showInitialState(); }, // --------------------------------------------------------------------- // Dropdowns event handlers. // --------------------------------------------------------------------- onMoodSelect: function( mood ) { this.inputbox.updateAttachment( mood ); this.togglePostButton(); }, onMoodRemove: function() { this.inputbox.updateAttachment( false ); this.togglePostButton(); }, onLocationSelect: function( location ) { this.inputbox.updateAttachment( null, location ); this.togglePostButton(); }, onLocationRemove: function() { this.inputbox.updateAttachment( null, false ); this.togglePostButton(); }, onPrivacySelect: function( data ) { var icon = this.$tabprivacy.find('use'), href = icon.attr('xlink:href'); href = href.replace(/#.+$/, '#joms-icon-' + data.icon ); this.$tabprivacy.find('use').attr( 'xlink:href', href ); this.$tabprivacy.find('span').html( data.label ); }, // --------------------------------------------------------------------- // Add photo/video event handlers. // --------------------------------------------------------------------- onAddPhoto: function() { App.postbox || (App.postbox = {}); App.postbox.value = this.value( true ); App.postbox.value[0] = App.postbox.value[0].replace( /\\n/g, '\n' ); $.trigger( 'postbox:photo' ); }, onAddVideo: function() { App.postbox || (App.postbox = {}); App.postbox.value = this.value( true ); App.postbox.value[0] = App.postbox.value[0].replace( /\\n/g, '\n' ); $.trigger( 'postbox:video' ); }, onAddFile: function() { App.postbox || (App.postbox = {}); App.postbox.value = this.value( true ); App.postbox.value[0] = App.postbox.value[0].replace( /\\n/g, '\n' ); $.trigger( 'postbox:file' ); }, onAddPoll: function() { App.postbox || (App.postbox = {}); App.postbox.value = this.value( true ); App.postbox.value[0] = App.postbox.value[0].replace( /\\n/g, '\n' ); $.trigger( 'postbox:poll' ); }, // --------------------------------------------------------------------- // Helper functions. // --------------------------------------------------------------------- getStaticAttachment: function() { if ( this.staticAttachment ) return this.staticAttachment; this.staticAttachment = $.extend({}, constants.get('postbox.attachment') || {}, { type: 'message' } ); return this.staticAttachment; }, togglePostButton: function( text ) { var enabled = false; if ( text ) enabled = true; if ( !enabled && this.subflags.mood ) enabled = this.subviews.mood.value(); if ( !enabled && this.subflags.location ) enabled = this.subviews.location.value(); this.$save[ enabled ? 'show' : 'hide' ](); } }); });PK ! �-��S �S postbox/file.jsnu �[��� define('views/postbox/file',[ 'sandbox', 'app', 'views/postbox/default', 'views/postbox/file-preview', 'views/inputbox/file', 'views/dropdown/mood', 'views/dropdown/privacy', 'utils/constants', 'utils/language', 'utils/uploader' ], // definition // ---------- function( $, App, DefaultView, PreviewView, InputboxView, MoodView, PrivacyView, constants, language, Uploader ) { return DefaultView.extend({ subviews: { mood: MoodView, privacy: PrivacyView }, template: _.template( '<div class="joms-postbox-file-wrapper" style="position: relative;">\ <div class="joms-postbox--droparea" id="joms-postbox-file--droparea">\ <%= language.file.drop_to_upload %>\ </div>\ <div id=joms-postbox-file-upload style="position:absolute;top:0;left:0;width:1px;height:1px;overflow:hidden">\ <button id=joms-postbox-file-upload-btn>Upload</button>\ </div>\ <div class="joms-postbox-inner-panel" style="position:relative">\ <div class="joms-postbox-file-upload">\ <svg viewBox="0 0 16 18" class="joms-icon">\ <use xlink:href="<%=window.joms_current_url%>#joms-icon-file-zip" class="joms-icon--svg-fixed joms-icon--svg-unmodified"></use>\ </svg>\ <%= language.file.upload_button %>\ </div>\ </div>\ <div class="joms-postbox-file">\ <div class="joms-postbox-preview"></div>\ <div class=joms-postbox-inputbox></div>\ <nav class="joms-postbox-tab selected"> \ <ul class="joms-list inline"> \ <li data-tab=upload data-bypass=1>\ <svg viewBox="0 0 16 18" class="joms-icon"><use xlink:href="<%= window.joms_current_url %>#joms-icon-file-zip"></use></svg> \ <span class=visible-desktop><%= language.file.upload_button_more %></span>\ </li> \ <li data-tab=mood>\ <svg viewBox="0 0 16 18" class="joms-icon"><use xlink:href="<%= window.joms_current_url %>#joms-icon-happy"></use></svg> \ <span class=visible-desktop><%= language.status.mood %></span>\ </li> \ <li data-tab=privacy>\ <svg viewBox="0 0 16 18" class="joms-icon"><use xlink:href="<%= window.joms_current_url %>#joms-icon-earth"></use></svg> \ <span class=visible-desktop></span>\ </li>\ </ul> \ <div class=joms-postbox-action> \ <button class=joms-postbox-cancel><%= language.postbox.cancel_button %></button> \ <button class=joms-postbox-save><%= language.postbox.post_button %></button> \ </div> \ <div class=joms-postbox-loading style="display:none;"> \ <img src="<%= juri.root%>components/com_community/assets/ajax-loader.gif" alt="loader"> \ </div> \ </nav>\ </div>\ </div>' ), getTemplate: function() { var html = this.template({ juri: constants.get('juri'), language: { postbox: language.get('postbox') || {}, status: language.get('status') || {}, file: language.get('file') || {}, privacy: language.get('privacy') || {} } }); return $( html ).hide(); }, events: $.extend({}, DefaultView.prototype.events, { 'click .joms-postbox-file-upload': 'onFileAdd', 'click li[data-tab=upload]': 'onFileAdd', 'dragenter': 'onDragEnter', 'dragleave #joms-postbox-file--droparea': 'onDragLeave', 'drop #joms-postbox-file--droparea': 'onFileDrop' }), initialize: function() { var moods = constants.get('moods'); this.enableMood = +constants.get('conf.enablemood') && moods && moods.length; if ( !this.enableMood ) this.subviews = $.omit( this.subviews, 'mood' ); var settings = constants.get('settings') || {}; if ( this.inheritPrivacy = (settings.isPage || settings.isGroup || settings.isEvent || !settings.isMyProfile)) this.subviews = $.omit( this.subviews, 'privacy' ); DefaultView.prototype.initialize.apply( this ); }, render: function() { DefaultView.prototype.render.apply( this ); this.$initial = this.$('.joms-postbox-inner-panel'); this.$main = this.$('.joms-postbox-file'); this.$inputbox = this.$('.joms-postbox-inputbox'); this.$preview = this.$('.joms-postbox-preview'); this.$tabupload = this.$tabs.find('[data-tab=upload]'); this.$tabmood = this.$tabs.find('[data-tab=mood]'); this.$tabprivacy = this.$tabs.find('[data-tab=privacy]'); this.$dropArea = this.$el.find('#joms-postbox-file--droparea'); if ( !this.enableMood ) this.$tabmood.remove(); this.$uploader = this.$('#joms-postbox-photo-upload'); this.$uploaderParent = this.$uploader.parent(); // inputbox this.inputbox = new InputboxView({ attachment: true, charcount: true }); this.assign( this.$inputbox, this.inputbox ); this.listenTo( this.inputbox, 'focus', this.onInputFocus ); this.uploading = []; // initialize uploader var url = joms.BASE_URL + 'index.php?option=com_community&view=files&task=multiUpload&type=activities', settings = constants.get('settings') || {}; if ( settings.isGroup ) url += '&no_html=1&tmpl=component&groupid=' + ( constants.get('groupid') || '' ); if ( settings.isEvent ) url += '&no_html=1&tmpl=component&eventid=' + ( constants.get('eventid') || '' ); if ( settings.isPage ) url += '&no_html=1&tmpl=component&pageid=' + ( constants.get('pageid') || '' ); if ( this.inheritPrivacy ) this.$tabprivacy.css({ visibility: 'hidden' }); // init privacy var defaultPrivacy, settings; if ( !this.inheritPrivacy ) { settings = constants.get('settings') || {}; if ( settings.isProfile && settings.isMyProfile ) defaultPrivacy = constants.get('conf.profiledefaultprivacy'); this.initSubview('privacy', { privacylist: window.joms_privacylist, defaultPrivacy: defaultPrivacy || 'public' }); } if ( $.ie ) { this.$uploader.appendTo( document.body ); this.$uploader.show(); } var conf = constants.get('conf') || {}; this.maxFileSize = 1; this.maxFileSize = +constants.get('settings.isProfile') ? conf.file_sharing_activity_max : this.maxFileSize; this.maxFileSize = +constants.get('settings.isPage') ? conf.file_sharing_page_max : this.maxFileSize; this.maxFileSize = +constants.get('settings.isGroup') ? conf.file_sharing_group_max : this.maxFileSize; this.maxFileSize = +constants.get('settings.isEvent') ? conf.file_sharing_event_max : this.maxFileSize; this.ext = 'zip'; this.ext = +constants.get('settings.isProfile') ? conf.file_activity_ext : this.ext; this.ext = +constants.get('settings.isPage') ? conf.file_page_ext : this.ext; this.ext = +constants.get('settings.isGroup') ? conf.file_group_ext : this.ext; this.ext = +constants.get('settings.isEvent') ? conf.file_event_ext : this.ext; var upConfig = { container: 'joms-postbox-file-upload', drop_element: 'joms-postbox-file--droparea', browse_button: 'joms-postbox-file-upload-btn', url: url, filters: [{ title: 'File files', extensions: this.ext }], max_file_size: this.maxFileSize + 'mb' }; // resizing on mobile cause errors on android stock browser! if ( !$.mobile ) upConfig.resize = { width: 2100, height: 2100, quality: 90 }; this.uploader = new Uploader( upConfig ); this.uploader.onAdded = $.bind( this.onFileAdded, this ); this.uploader.onError = $.bind( this.onFileError, this ); this.uploader.onProgress = $.bind( this.onFileProgress, this ); this.uploader.onUploaded = $.bind( this.onFileUploaded, this ); this.uploader.init(); if ( $.ie ) { this.$uploader.hide(); this.$uploader.appendTo( this.$uploaderParent ); } return this; }, showInitialState: function() { this.$main.hide(); this.$initial.show(); $.ie && ($.ieVersion < 10) && this.ieUploadButtonFix( true ); this.inputbox && this.inputbox.single(); this.preview && this.preview.remove(); this.preview = false; this.showMoreButton(); DefaultView.prototype.showInitialState.apply( this ); }, showMainState: function() { DefaultView.prototype.showMainState.apply( this ); this.$action.hide(); this.$initial.hide(); this.$main.show(); this.$save.show(); $.ie && ($.ieVersion < 10) && this.ieUploadButtonFix(); if ( App.postbox && App.postbox.value && App.postbox.value.length ) { this.inputbox.set( App.postbox.value[0] ); App.postbox.value = false; } }, showMoreButton: function() { this.$tabupload.removeClass('hidden invisible'); }, hideMoreButton: function() { this.$tabupload.addClass( this.subviews.mood ? 'hidden' : 'invisible' ); }, // --------------------------------------------------------------------- // Data validation and retrieval. // --------------------------------------------------------------------- reset: function() { DefaultView.prototype.reset.apply( this ); this.inputbox && this.inputbox.reset(); this.preview && this.preview.remove(); this.preview = false; this.uploading = []; }, value: function() { this.data.text = this.inputbox.value() || ''; this.data.attachment = {}; this.data.text = this.data.text.replace( /\n/g, '\\n' ); var value; for ( var prop in this.subflags ) if ( value = this.subviews[ prop ].value() ) this.data.attachment[ prop ] = value; if ( this.preview ) { $.extend( this.data.attachment, this.preview.value() ); } return DefaultView.prototype.value.apply( this, arguments ); }, validate: function() { var value = this.value( true ), attachment = value[1] || {}; if ( !attachment.id && attachment.id.length ) return 'No image selected.'; }, onPrivacySelect: function( data ) { var icon = this.$tabprivacy.find('use'), href = icon.attr('xlink:href'); href = href.replace(/#.+$/, '#joms-icon-' + data.icon ); this.$tabprivacy.find('use').attr( 'xlink:href', href ); this.$tabprivacy.find('span').html( data.label ); }, // --------------------------------------------------------------------- // File preview event handlers. // --------------------------------------------------------------------- onFileAdd: function() { if ( this.uploading.length ) return; var conf = constants.get('conf') || {}, limit = +conf.limitfile, uploaded = +conf.uploadedfile, num_file_per_upload = +conf.num_file_per_upload, curr = this.preview ? this.preview.getNumFiles() : 0; if ( curr >= num_file_per_upload ) { window.alert( language.get('file.batch_notice') ); return; } uploaded += curr; if ( uploaded >= limit ) { window.alert( language.get('photo.upload_limit_exceeded') || 'You have reached the upload limit.' ); return; } // Opera 12 and lower (Presto engine), and IE 10, cannot open File Dialog without clicking the input[type=file] element. if ( window.opera || ($.ie && $.ieVersion === 10) ) this.$('#joms-postbox-photo-upload').find('input[type=file]').click(); else this.uploader.open(); }, onFileAdded: function( up, files ) { if ( this.uploading.length ) return; if ( !(files && files.length) ) return; var exts = this.ext, maxFileSize = this.maxFileSize; files = _.filter( files, function(file) { var ex = file.name.split('.').pop(); return _.contains( exts.split(','), ex ); }); files = _.filter( files, function(file) { return file.size <= ( maxFileSize * 1024 * 1024 ); }); var conf = constants.get('conf') || {}, num_file_per_upload = +conf.num_file_per_upload, limit = +conf.limitfile, uploaded = +conf.uploadedfile, curr = this.preview ? this.preview.getNumFiles() : 0, self = this; if ( curr + files.length > num_file_per_upload ) { window.alert( language.get('file.batch_notice') ); _.each( files, function(file) { up.removeFile(file); }) return; } uploaded += curr; if ( uploaded >= limit ) { window.alert( language.get('photo.upload_limit_exceeded') || 'You have reached the upload limit.' ); _.each( files, function(file) { up.removeFile(file); }) return; } var removed; if ( uploaded + files.length > limit ) { removed = uploaded + files.length - limit; files.splice( 0 - removed, removed ); up.splice( 0 - removed, removed ); } var div; if ( !this.preview ) { div = $('<div>').appendTo( this.$preview ); this.preview = new PreviewView(); this.assign( div, this.preview ); this.listenTo( this.preview, 'update', function( num ) { if ( !num || num <= 0 ) { this.showInitialState(); this.inputbox.single(); this.uploading = []; return; } else if ( num >= 8 ) { this.hideMoreButton(); } else { this.showMoreButton(); } this.inputbox[ num > 1 ? 'multiple' : 'single' ](); } ); } this.showMainState(); for ( var i = 0; i < files.length; i++ ) { this.preview.add( files[i] ); } _.each( files, function(file) { self.uploading.push(file.id); }); this.$action.hide(); up.start(); up.refresh(); }, onFileError: function( up, file ) { if ( +file.code === +plupload.FILE_EXTENSION_ERROR ) { window.alert( language.get('file.file_type_not_permitted') ); } else if ( +file.code === +plupload.FILE_SIZE_ERROR ) { var msg = '"' + file.file.name + '": ' + language.get('file.max_upload_size_error').replace( '##maxsize##', this.maxFileSize ); window.alert( msg ); } else { console.log( file.message ); } }, onFileProgress: function( up, file ) { this.preview && this.preview.updateProgress( file ); }, onFileUploaded: function( up, file, info ) { var json; try { json = JSON.parse( info.response ); } catch ( e ) {} json || (json = {}); // onerror if ( !json.id ) { up.stop(); up.splice(); window.alert( json && json.msg || 'Undefined error.' ); this.uploading = []; this.$action.show(); this.preview && this.preview.removeFailed(); return; } this.uploading = _.without( this.uploading, file.id); this.uploading.length === 0 && this.$action.show(); this.preview && this.preview.setFile( file, json ); }, // --------------------------------------------------------------------- // Drag and drops event handlers. // --------------------------------------------------------------------- onDragEnter: function( e ) { e.preventDefault(); this.$dropArea.show(); this.$dropArea.css('line-height', this.$dropArea.height() + 'px'); }, onDragLeave: function( e ) { e.preventDefault(); this.$dropArea.hide(); }, onFileDrop: function( e ) { e.preventDefault(); this.$dropArea.hide(); }, // --------------------------------------------------------------------- // Dropdowns event handlers. // --------------------------------------------------------------------- onMoodSelect: function( mood ) { this.inputbox.updateAttachment( mood ); }, onMoodRemove: function() { this.inputbox.updateAttachment( false ); }, getStaticAttachment: function() { if ( this.staticAttachment ) return this.staticAttachment; this.staticAttachment = $.extend({}, constants.get('postbox.attachment') || {}, { type: 'file' } ); return this.staticAttachment; }, ieUploadButtonFix: function( initialState ) { if ( !this.ieUploadButtonFix.init ) { this.ieUploadButtonFix.init = true; this.$uploader.css({ display: 'block', position: 'absolute', opacity: 0, width: '', height: '' }).children('button,form').css({ display: 'block', position: 'absolute', width: '', height: '', top: 0, right: 0, bottom: 0, left: 0 }).children('input').css({ cursor: 'pointer', height: '100%' }); } if ( initialState ) { this.$uploader.appendTo( this.$uploaderParent ); this.$uploader.css({ top: 12, right: 12, bottom: 12, left: 12 }).children('form').css({ width: '100%', height: '100%' }); } else { this.$uploader.appendTo( this.$tabupload ); this.$uploader.css({ top: 0, right: 0, bottom: 0, left: 0 }); } } }); }); PK ! w�(?� � postbox/fetcher.jsnu �[��� define('views/postbox/fetcher',[ 'sandbox', 'views/base', 'utils/ajax', 'utils/image', 'utils/language' ], // definition // ---------- function( $, BaseView, ajax, image, language ) { return BaseView.extend({ template: joms.jst[ 'html/postbox/fetcher' ], events: { 'click .joms-fetched-close': 'onClose', 'click .joms-fetched-field span': 'onFocus', 'keyup .joms-fetched-field input': 'onKeyup', 'keyup .joms-fetched-field textarea': 'onKeyup', 'blur .joms-fetched-field input': 'onBlur', 'blur .joms-fetched-field textarea': 'onBlur', 'click .joms-fetched-previmg': 'prevImage', 'click .joms-fetched-nextimg': 'nextImage' }, initialize: function() { var lang = language.get('fetch') || {}; this.titlePlaceholder = lang.title_hint || ''; this.descPlaceholder = lang.description_hint || ''; }, fetch: function( text ) { var rUrl = /^(|.*\s)((https?:\/\/|www\.)([a-z0-9-]+\.)+[a-z]{2,18}(:\d+)?(\/.*)?)(\s.*|)$/i, isFetchable = text.match( rUrl ); if ( this.fetching || !isFetchable ) return; text = isFetchable[2]; this.fetching = true; this.fetched = false; delete this.url; this.trigger('fetch:start'); ajax({ fn: 'system,ajaxGetFetchUrl', data: [ text ], success: $.bind( this.render, this ), complete: $.noop }); }, render: function( json ) { json || (json = {}); this.fetched = true; this.url = json.url || ''; var data = { title: json.title || '', titlePlaceholder: this.titlePlaceholder, description: json.description || '', descPlaceholder: this.descPlaceholder, image: ( json.image || [] ).concat( json['og:image'] || [] ), lang: { prev: ( language.get('prev') || '' ).toLowerCase(), next: ( language.get('next') || '' ).toLowerCase(), cancel: ( language.get('cancel') || '' ).toLowerCase() } }; // normalize url if ( !this.url.match( /^https?:\/\//i ) ) this.url = 'http://' + this.url; // normalize images for ( var i = 0; i < data.image.length; i++ ) if ( !data.image[i].match( /^(http:|https:)?\/\//i ) ) data.image[i] = '//' + data.image[i]; // preload images image.preload( data.image, $.bind(function( images ) { data.image = images; this.$el.html( this.template( data ) ); this.$images = this.$('.joms-fetched-images').find('img'); this.$title = this.$('.joms-fetched-title').find('input'); this.$description = this.$('.joms-fetched-description').find('textarea'); this.fetching = false; this.trigger('fetch:done'); }, this ) ); }, change: function( el ) { var input = $( el ), span = input.prev('span'), val = input.val().replace( /^\s+|\s+$/g, '' ); if ( !val ) { val = input.parent().hasClass('joms-fetched-title') ? this.titlePlaceholder : this.descPlaceholder; } input.hide(); span.text( val ).show(); }, remove: function() { delete this.url; BaseView.prototype.remove.apply( this ); this.trigger('remove'); }, prevImage: function() { var currImg = this.$images.filter(':visible'), prevImg = currImg.prev(); if ( prevImg.length ) { currImg.hide(); prevImg.show(); } }, nextImage: function() { var currImg = this.$images.filter(':visible'), nextImg = currImg.next(); if ( nextImg.length ) { currImg.hide(); nextImg.show(); } }, value: function() { if ( this.fetching || !this.url ) return; return [ this.url, this.$images && this.$images.filter(':visible').attr('src'), this.$title && this.escapeValue( this.$title.val() ), this.$description && this.escapeValue( this.$description.val() ) ]; }, // --------------------------------------------------------------------- // Event handlers. // --------------------------------------------------------------------- onClose: function() { this.remove(); }, onFocus: function( e ) { var span = $( e.currentTarget ), input = span.next('input,textarea'); span.hide(); input.show(); setTimeout(function() { input[0].focus(); }, 300 ); }, onKeyup: function( e ) { if ( e.keyCode === 13 ) { this.change( e.currentTarget ); } }, onBlur: function( e ) { this.change( e.currentTarget ); }, // --------------------------------------------------------------------- // Ajax response parser. // --------------------------------------------------------------------- parseResponse: function( resp ) { resp = resp && resp[2] && resp[2][3] && resp[2][3][0] || false; if ( !resp ) return; var json; try { json = JSON.parse( resp ); } catch ( e ) {} return json; }, escapeValue: function( value ) { if ( typeof value !== 'string' ) return value; return value .replace( /\\/g, '\' ) .replace( /\t/g, '\\t' ) .replace( /\n/g, '\\n' ) .replace( /"/g, '"' ); } }); });PK ! �O�� � postbox/fetcher-video.jsnu �[��� define('views/postbox/fetcher-video',[ 'sandbox', 'views/base', 'views/widget/select', 'utils/ajax', 'utils/language' ], // definition // ---------- function( $, BaseView, SelectWidget, ajax, language ) { return BaseView.extend({ template: joms.jst[ 'html/postbox/fetcher-video' ], events: { 'click .joms-fetched-close': 'onClose', 'click .joms-fetched-field span': 'onFocus', 'keyup .joms-fetched-field input': 'onKeyup', 'keyup .joms-fetched-field textarea': 'onKeyup', 'blur .joms-fetched-field input': 'onBlur', 'blur .joms-fetched-field textarea': 'onBlur' }, initialize: function() { var lang = language.get('fetch') || {}; this.titlePlaceholder = lang.title_hint || ''; this.descPlaceholder = lang.description_hint || ''; lang = language.get('video'); this.categoryLabel = lang.category_label; }, fetch: function( text ) { var rUrl = /^(|.*\s)(https?:\/\/|www\.)([a-z0-9-]+\.)+[a-z]{2,18}(:\d+)?(\/.*)?(\s.*|)$/i, isFetchable = text.match( rUrl ); if ( this.fetching || !isFetchable ) return; this.id = false; this.url = text; this.fetching = true; this.fetched = false; this.trigger('fetch:start'); // TODO video limit... var that = this; ajax({ fn: 'videos,ajaxLinkVideoPreview', data: [ text ], complete: function() { that.fetching = false; that.trigger('fetch:done'); }, success: $.bind( this.render, this ) }); }, render: function( resp ) { resp = this.parseResponse( resp ); if ( !resp ) { this.trigger( 'fetch:failed' ); return; } var video = resp && resp.video, categories = this.sortCategories( resp && resp.category || [] ); if ( !(video && video.id) ) { this.trigger( 'fetch:failed', resp ); return; } this.video_id = video.id; this.fetched = true; var data = { title: video.title || '', titlePlaceholder: this.titlePlaceholder, description: video.description || '', descPlaceholder: this.descPlaceholder, image: video.thumb || false, lang: { cancel: ( language.get('cancel') || '' ).toLowerCase() } }; this.select && this.select.remove(); this.$el.html( this.template( data ) ); this.$image = this.$('.joms-fetched-images').find('img'); this.$title = this.$('.joms-fetched-title').find('input'); this.$description = this.$('.joms-fetched-description').find('textarea'); this.$category = this.$('.joms-fetched-category'); var options = []; for ( var i = 0; i < categories.length; i++ ) { options.push([ categories[i].id, this.categoryLabel + ': ' + categories[i].name ]); } this.select = new SelectWidget({ options: options }); this.assign( this.$category, this.select ); return this; }, change: function( el ) { var input = $( el ), span = input.prev('span'), val = input.val().replace( /^\s+|\s+$/g, '' ); if ( !val ) { if ( input.parent().hasClass('joms-fetched-title') ) val = this.titlePlaceholder; else val = this.descPlaceholder; } input.hide(); span.text( val ).show(); }, remove: function() { BaseView.prototype.remove.apply( this ); this.trigger('remove'); }, value: function() { if ( this.fetching ) return []; return [ this.video_id, this.url, this.$image && this.$image.attr('src'), this.$title && this.escapeValue( this.$title.val() ), this.$description && this.escapeValue( this.$description.val() ), this.select && this.select.value() ]; }, // --------------------------------------------------------------------- // Event handlers. // --------------------------------------------------------------------- onClose: function() { this.remove(); }, onFocus: function( e ) { var span = $( e.currentTarget ), input = span.next('input,textarea'); span.hide(); input.show(); setTimeout(function() { input[0].focus(); }, 300 ); }, onKeyup: function( e ) { if ( e.keyCode === 13 ) { this.change( e.currentTarget ); } }, onBlur: function( e ) { this.change( e.currentTarget ); }, // --------------------------------------------------------------------- // Ajax response parser. // --------------------------------------------------------------------- parseResponse: function( resp ) { var json; if ( resp && resp.length ) { for ( var i = 0; i < resp.length; i++ ) { if ( resp[i][1] === '__throwError' ) { json = { msg: resp[i][3] }; break; } else if ( resp[i][1] === '__callback' ) { json = resp[i][3][0]; break; } } } return json; }, // --------------------------------------------------------------------- // Helper functions. // --------------------------------------------------------------------- sortCategories: function( categories, parent, prefix ) { if ( !categories || !categories.length ) return []; parent || (parent = 0); prefix || (prefix = ''); var options = []; for ( var i = 0, id, name; i < categories.length; i++ ) { if ( +categories[i].parent === parent ) { id = +categories[i].id; name = prefix + categories[i].name; options.push({ id: id, name: name }); options = options.concat( this.sortCategories( categories, id, name + ' › ' ) ); } } return options; }, escapeValue: function( value ) { if ( typeof value !== 'string' ) return value; return value .replace( /\\/g, '\' ) .replace( /\t/g, '\\t' ) .replace( /\n/g, '\\n' ) .replace( /"/g, '"' ); } }); }); PK ! �0O �O postbox/photo.jsnu �[��� define('views/postbox/photo',[ 'sandbox', 'app', 'views/postbox/default', 'views/postbox/photo-preview', 'views/postbox/gif-preview', 'views/inputbox/photo', 'views/dropdown/mood', 'views/widget/select', 'utils/constants', 'utils/language', 'utils/uploader' ], // definition // ---------- function( $, App, DefaultView, PreviewView, GifPreviewView, InputboxView, MoodView, SelectWidget, constants, language, Uploader ) { return DefaultView.extend({ subviews: { mood: MoodView }, template: joms.jst[ 'html/postbox/photo' ], events: $.extend({}, DefaultView.prototype.events, { 'click .joms-postbox-photo-upload': 'onPhotoAdd', 'click li[data-tab=upload]': 'onPhotoAdd', 'click .joms-postbox-gif-upload': 'onGifAdd', 'dragenter': 'onDragEnter', 'dragleave #joms-postbox-photo--droparea': 'onDragLeave', 'drop #joms-postbox-photo--droparea': 'onFileDrop' }), initialize: function() { var moods = constants.get('moods'); this.enableMood = +constants.get('conf.enablemood') && moods && moods.length; if ( !this.enableMood ) this.subviews = $.omit( this.subviews, 'mood' ); this.enableGif = +constants.get('conf.enablephotosgif'); DefaultView.prototype.initialize.apply( this ); }, render: function() { DefaultView.prototype.render.apply( this ); this.$el.find(".joms-icon--emoticon").data('editor', this); this.$initial = this.$('.joms-postbox-inner-panel'); this.$main = this.$('.joms-postbox-photo'); this.$inputbox = this.$('.joms-postbox-inputbox'); this.$preview = this.$('.joms-postbox-preview'); this.$tabupload = this.$tabs.find('[data-tab=upload]'); this.$tabmood = this.$tabs.find('[data-tab=mood]'); this.$dropArea = this.$el.find('#joms-postbox-photo--droparea'); if ( !this.enableMood ) this.$tabmood.remove(); this.$uploader = this.$('#joms-postbox-photo-upload'); this.$uploaderParent = this.$uploader.parent(); // inputbox this.inputbox = new InputboxView({ attachment: true, charcount: true }); this.assign( this.$inputbox, this.inputbox ); this.listenTo( this.inputbox, 'focus', this.onInputFocus ); // initialize uploader var url = joms.BASE_URL + 'index.php?option=com_community&view=photos&task=ajaxPreview', settings = constants.get('settings') || {}; if ( settings.isGroup ) url += '&no_html=1&tmpl=component&groupid=' + ( constants.get('groupid') || '' ); if ( settings.isEvent ) url += '&no_html=1&tmpl=component&eventid=' + ( constants.get('eventid') || '' ); if ( settings.isPage ) url += '&no_html=1&tmpl=component&pageid=' + ( constants.get('pageid') || '' ); if ( $.ie ) { this.$uploader.appendTo( document.body ); this.$uploader.show(); } this.maxFileSize = +constants.get('conf.maxuploadsize') || 0; this.uploading = []; var upConfig = { container: 'joms-postbox-photo-upload', drop_element: 'joms-postbox-photo--droparea', browse_button: 'joms-postbox-photo-upload-btn', url: url, filters: [{ title: 'Image files', extensions: 'jpg,jpeg,png,gif' }], max_file_size: this.maxFileSize + 'mb' }; // resizing on mobile cause errors on android stock browser! if ( !$.mobile ) upConfig.resize = { width: 2100, height: 2100, quality: 90 }; this.uploader = new Uploader( upConfig ); this.uploader.onAdded = $.bind( this.onPhotoAdded, this ); this.uploader.onError = $.bind( this.onPhotoError, this ); this.uploader.onProgress = $.bind( this.onPhotoProgress, this ); this.uploader.onUploaded = $.bind( this.onPhotoUploaded, this ); this.uploader.init(); if ( $.ie ) { this.$uploader.hide(); this.$uploader.appendTo( this.$uploaderParent ); } if ( this.enableGif ) { var gifConfig = { container: 'joms-postbox-gif-upload', browse_button: 'joms-postbox-gif-upload-btn', url: url + '&gifanimation=1', filters: [{ title: 'Image files', extensions: 'gif' }], max_file_size: this.maxFileSize + 'mb', multi_selection: false }; this.gifuploader = new Uploader( gifConfig ); this.gifuploader.onAdded = $.bind( this.onGifAdded, this ); this.gifuploader.onError = $.bind( this.onGifError, this ); this.gifuploader.onProgress = $.bind( this.onGifProgress, this ); this.gifuploader.onUploaded = $.bind( this.onGifUploaded, this ); this.gifuploader.init(); } return this; }, showInitialState: function() { this.$main.hide(); this.$initial.show(); $.ie && ($.ieVersion < 10) && this.ieUploadButtonFix( true ); this.inputbox && this.inputbox.single(); this.preview && this.preview.remove(); this.preview = false; this.gifPreview && this.gifPreview.remove(); this.gifPreview = false; this.showMoreButton(); DefaultView.prototype.showInitialState.apply( this ); }, showMainState: function() { DefaultView.prototype.showMainState.apply( this ); this.$action.hide(); this.$initial.hide(); this.$main.show(); this.$save.show(); $.ie && ($.ieVersion < 10) && this.ieUploadButtonFix(); if ( App.postbox && App.postbox.value && App.postbox.value.length ) { this.inputbox.set( App.postbox.value[0] ); App.postbox.value = false; } }, showMoreButton: function() { this.$tabupload.removeClass('hidden invisible'); }, hideMoreButton: function() { this.$tabupload.addClass( this.subviews.mood ? 'hidden' : 'invisible' ); }, // --------------------------------------------------------------------- // Data validation and retrieval. // --------------------------------------------------------------------- reset: function() { DefaultView.prototype.reset.apply( this ); this.inputbox && this.inputbox.reset(); this.preview && this.preview.remove(); this.preview = false; this.gifPreview && this.gifPreview.remove(); this.gifPreview = false; this.uploading = []; }, value: function() { this.data.text = this.inputbox.value() || ''; this.data.attachment = {}; this.data.text = this.data.text.replace( /\n/g, '\\n' ); var value; for ( var prop in this.subflags ) if ( value = this.subviews[ prop ].value() ) this.data.attachment[ prop ] = value; if ( this.preview ) { $.extend( this.data.attachment, this.preview.value() ); } else if ( this.gifPreview ) { $.extend( this.data.attachment, this.gifPreview.value() ); } return DefaultView.prototype.value.apply( this, arguments ); }, validate: function() { var value = this.value( true ), attachment = value[1] || {}; if ( !attachment.id && attachment.id.length ) return 'No image selected.'; }, // --------------------------------------------------------------------- // Photo preview event handlers. // --------------------------------------------------------------------- onPhotoAdd: function() { if ( this.uploading.length ) return; var conf = constants.get('conf') || {}, limit = +conf.limitphoto, uploaded = +conf.uploadedphoto, num_photo_per_upload = +conf.num_photo_per_upload, curr = this.preview ? this.preview.getNumPics() : 0 ; if ( curr >= num_photo_per_upload ) { window.alert( language.get('photo.batch_notice') ); return; } uploaded += curr; if ( uploaded >= limit ) { window.alert( language.get('photo.upload_limit_exceeded') || 'You have reached the upload limit.' ); return; } // Opera 12 and lower (Presto engine), and IE 10, cannot open File Dialog without clicking the input[type=file] element. if ( window.opera || ($.ie && $.ieVersion === 10) ) this.$('#joms-postbox-photo-upload').find('input[type=file]').click(); else this.uploader.open(); }, onPhotoAdded: function( up, files ) { if ( this.uploading.length ) return; if ( !(files && files.length) ) return; var exts = 'jpg,jpeg,png,gif,JPG,JPEG,PNG,GIF', maxFileSize = this.maxFileSize; files = _.filter( files, function(file) { var ex = file.name.split('.').pop(); return _.contains( exts.split(','), ex ); }); files = _.filter( files, function(file) { return file.size <= ( maxFileSize * 1024 * 1024 ); }); // daily limit checking var conf = constants.get('conf') || {}, limit = +conf.limitphoto, uploaded = +conf.uploadedphoto, num_photo_per_upload = +conf.num_photo_per_upload, curr = this.preview ? this.preview.getNumPics() : 0; if ( curr + files.length > num_photo_per_upload ) { window.alert( language.get('photo.batch_notice') ); _.each( files, function(file) { up.removeFile(file); }) return; } uploaded += curr; if ( uploaded >= limit ) { window.alert( language.get('photo.upload_limit_exceeded') || 'You have reached the upload limit.' ); _.each( files, function(file) { up.removeFile(file); }) return; } var removed; if ( uploaded + files.length > limit ) { removed = uploaded + files.length - limit; files.splice( 0 - removed, removed ); up.splice( 0 - removed, removed ); } var div; if ( !this.preview ) { div = $('<div>').appendTo( this.$preview ); this.preview = new PreviewView(); this.assign( div, this.preview ); this.listenTo( this.preview, 'update', function( num ) { if ( !num || num <= 0 ) { this.showInitialState(); this.inputbox.single(); this.uploading = []; return; } else if ( num >= num_photo_per_upload ) { this.hideMoreButton(); } else { this.showMoreButton(); } this.inputbox[ num > 1 ? 'multiple' : 'single' ](); } ); } this.showMainState(); for ( var i = 0; i < files.length; i++ ) this.preview.add( files[i] ); var self = this; _.each( files, function(file) { self.uploading.push(file.id); }); this.$action.hide(); up.start(); up.refresh(); }, onPhotoError: function( up, file ) { if ( +file.code === +plupload.FILE_EXTENSION_ERROR ) { window.alert( 'Photos: Selected file type is not permitted.' ); } else if ( +file.code === +plupload.FILE_SIZE_ERROR ) { window.alert( language.get('photo.max_upload_size_error') ); } else { console.log( file.message ); } }, onPhotoProgress: function( up, file ) { this.preview && this.preview.updateProgress( file ); }, onPhotoUploaded: function( up, file, info ) { var json; try { json = JSON.parse( info.response ); } catch ( e ) {} json || (json = {}); // onerror if ( !json.thumbnail ) { up.stop(); up.splice(); window.alert( json && json.msg || 'Undefined error.' ); this.uploading = []; this.$action.show(); this.preview && this.preview.removeFailed(); return; } this.uploading = _.without( this.uploading, file.id); this.uploading.length === 0 && this.$action.show(); this.preview && this.preview.setImage( file, json ); }, // --------------------------------------------------------------------- // GIF preview event handlers. // --------------------------------------------------------------------- onGifAdd: function() { this.hideMoreButton(); this.gifuploader.open(); }, onGifAdded: function( up, files ) { var div; if ( !this.gifPreview ) { div = $('<div>').appendTo( this.$preview ); this.gifPreview = new GifPreviewView(); this.assign( div, this.gifPreview ); this.listenTo( this.gifPreview, 'update', function( num ) { if ( !num || num <= 0 ) { this.showInitialState(); this.inputbox.single(); this.uploading = []; return; } this.hideMoreButton(); this.inputbox.single(); } ); } this.showMainState(); this.gifPreview.add( files[0] ); up.start(); up.refresh(); }, onGifError: function( up, file ) { if ( +file.code === +plupload.FILE_EXTENSION_ERROR ) { window.alert( 'Gifs: Selected file type is not permitted.' ); } else if ( +file.code === +plupload.FILE_SIZE_ERROR ) { window.alert( language.get('photo.max_upload_size_error') ); } else { console.log( file.message ); } }, onGifProgress: function( up, file ) { this.gifPreview.updateProgress( file ); }, onGifUploaded: function( up, file, info ) { var json; try { json = JSON.parse( info.response ); } catch ( e ) {} json || (json = {}); // onerror if ( !json.image ) { up.stop(); up.splice(); window.alert( json && json.msg || 'Undefined error.' ); this.$action.show(); this.gifPreview && this.gifPreview.removeFailed(); return; } this.$action.show(); if ( this.gifPreview ) this.gifPreview.setImage( file, json ); }, // --------------------------------------------------------------------- // Drop event handlers. // --------------------------------------------------------------------- onDragEnter: function(e) { e.preventDefault(); this.$dropArea.show(); this.$dropArea.css('line-height', this.$dropArea.height() + 'px'); }, onDragLeave: function(e) { e.preventDefault(); this.$dropArea.hide(); }, onFileDrop: function(e) { e.preventDefault(); this.$dropArea.hide(); }, // --------------------------------------------------------------------- // Dropdowns event handlers. // --------------------------------------------------------------------- onMoodSelect: function( mood ) { this.inputbox.updateAttachment( mood ); }, onMoodRemove: function() { this.inputbox.updateAttachment( false ); }, // --------------------------------------------------------------------- // Helper functions. // --------------------------------------------------------------------- getTemplate: function() { var html = this.template({ juri: constants.get('juri'), allowgif: constants.get('conf.enablephotosgif') || false, language: { postbox: language.get('postbox') || {}, status: language.get('status') || {}, photo: language.get('photo') || {} } }); return $( html ).hide(); }, getStaticAttachment: function() { if ( this.staticAttachment ) return this.staticAttachment; this.staticAttachment = $.extend({}, constants.get('postbox.attachment') || {}, { type: 'photo' } ); return this.staticAttachment; }, ieUploadButtonFix: function( initialState ) { if ( !this.ieUploadButtonFix.init ) { this.ieUploadButtonFix.init = true; this.$uploader.css({ display: 'block', position: 'absolute', opacity: 0, width: '', height: '' }).children('button,form').css({ display: 'block', position: 'absolute', width: '', height: '', top: 0, right: 0, bottom: 0, left: 0 }).children('input').css({ cursor: 'pointer', height: '100%' }); } if ( initialState ) { this.$uploader.appendTo( this.$uploaderParent ); this.$uploader.css({ top: 12, right: 12, bottom: 12, left: 12 }).children('form').css({ width: '100%', height: '100%' }); } else { this.$uploader.appendTo( this.$tabupload ); this.$uploader.css({ top: 0, right: 0, bottom: 0, left: 0 }); } } }); });PK ! ����* �* postbox/event.jsnu �[��� define('views/postbox/event',[ 'sandbox', 'views/postbox/default', 'views/inputbox/eventtitle', 'views/inputbox/eventdesc', 'views/dropdown/event', 'utils/constants', 'utils/format', 'utils/language' ], // definition // ---------- function( $, DefaultView, TitleView, InputboxView, EventView, constants, format, language ) { return DefaultView.extend({ subviews: { event: EventView }, template: joms.jst[ 'html/postbox/event' ], events: $.extend({}, DefaultView.prototype.events, { 'click .joms-postbox-event-title': 'onFocus' }), render: function() { DefaultView.prototype.render.apply( this ); this.$title = this.$('.joms-postbox-title'); this.$inputbox = this.$('.joms-postbox-inputbox'); this.$category = this.$('.joms-postbox-event-label-category'); this.$location = this.$('.joms-postbox-event-label-location'); this.$date = this.$('.joms-postbox-event-label-date'); // title this.title = new TitleView(); this.assign( this.$title, this.title ); this.listenTo( this.title, 'focus', this.onInputFocus ); this.listenTo( this.title, 'keydown', this.onNewInputUpdate ); // inputbox this.inputbox = new InputboxView({ charcount: true }); this.assign( this.$inputbox, this.inputbox ); this.listenTo( this.inputbox, 'focus', this.onInputFocus ); this.listenTo( this.inputbox, 'keydown', this.onNewInputUpdate ); return this; }, // --------------------------------------------------------------------- // Data validation and retrieval. // --------------------------------------------------------------------- reset: function() { DefaultView.prototype.reset.apply( this ); this.title && this.title.reset(); this.inputbox && this.inputbox.reset(); this.$category && this.onEventSelect({}); }, value: function() { this.data.text = this.inputbox.value() || ''; this.data.attachment = {}; var value; for ( var prop in this.subflags ) if ( value = this.subviews[ prop ].value() ) this.data.attachment[ prop ] = value; var starttime = (this._data.starttime || '').split(':'); var endtime = (this._data.endtime || '').split(':'); $.extend( this.data.attachment, { title: this.title.value(), catid: this._data.category && this._data.category[0] || null, location: this._data.location, startdate: this._data.startdate, enddate: this._data.enddate, allday: false, 'starttime-hour': starttime[0] || null, 'starttime-min': starttime[1] || null, 'endtime-hour': endtime[0] || null, 'endtime-min': endtime[1] || null }); return DefaultView.prototype.value.apply( this, arguments ); }, validate: function() { var value = this.value( true ), text = value[0]; if ( !text ) return 'Event description cannot be empty.'; }, // --------------------------------------------------------------------- // Inputbox event handlers. // --------------------------------------------------------------------- onInputFocus: function() { this.showMainState(); }, onInputUpdate: $.debounce(function() { var value = this.value( true ), text = value[0], attachment = value[1], show = true; if ( !this.trim( attachment.title ) ) show = false; else if ( !this.trim( text ) ) show = false; else if ( !attachment.catid ) show = false; else if ( !attachment.location ) show = false; else if ( !attachment.startdate ) show = false; else if ( !attachment.enddate ) show = false; else if ( !attachment['starttime-hour'] && !attachment['starttime-min'] ) show = false; else if ( !attachment['endtime-hour'] && !attachment['endtime-min'] ) show = false; this.$save[ show ? 'show' : 'hide' ](); }, 300 ), onNewInputUpdate: $.debounce(function() { var value = this.value( true ), text = value[0], attachment = value[1], show = true; if ( !this.trim( attachment.title ) ) show = false; else if ( !this.trim( text ) ) show = false; else if ( !attachment.catid ) show = false; else if ( !attachment.location ) show = false; else if ( !attachment.startdate ) show = false; else if ( !attachment.enddate ) show = false; else if ( !attachment['starttime-hour'] && !attachment['starttime-min'] ) show = false; else if ( !attachment['endtime-hour'] && !attachment['endtime-min'] ) show = false; this.$save[ show ? 'show' : 'hide' ](); }, 300 ), onPost: function() { var conf = constants.get('conf') || {}, limit = +conf.limitevent, created = +conf.createdevent, message; if ( created >= limit ) { message = language.get('event.create_limit_exceeded') || 'You have reached the event creation limit.'; message = message.replace( '%1$s', limit ); window.alert( message ); return; } DefaultView.prototype.onPost.apply( this, arguments ); }, onPostSuccess: function() { DefaultView.prototype.onPostSuccess.apply( this, arguments ); var conf = constants.get('conf') || {}; conf.createdevent = +conf.createdevent + 1; }, // --------------------------------------------------------------------- // Dropdowns event handlers. // --------------------------------------------------------------------- onEventSelect: function( data ) { if ( !data.category ) { this.$category.hide(); } else { this.$category.find('.joms-input-text').html( data.category && data.category[1] ); this.$category.show(); } if ( !data.location ) { this.$location.hide(); } else { this.$location.find('.joms-input-text').html( data.location ); this.$location.show(); } var str = []; if ( !data.startdate || !data.enddate ) { this.$date.hide(); } else { str.push( data.startdate[1] + ' ' + data.starttime[1] ); str.push( data.enddate[1] + ' ' + data.endtime[1] ); this.$date.find('.joms-input-text').html( str.join(' — ') ); this.$date.show(); } data.startdate && (data.startdate = data.startdate[0]); data.starttime && (data.starttime = data.starttime[0]); data.enddate && (data.enddate = data.enddate[0]); data.endtime && (data.endtime = data.endtime[0]); this._data = data; this.onInputUpdate(); }, onPrivacySelect: function( data ) { var icon = this.$tabprivacy.find('use'), href = icon.attr('xlink:href'); href = href.replace(/#.+$/, '#joms-icon-' + data.icon ); this.$tabprivacy.find('use').attr( 'xlink:href', href ); this.$tabprivacy.find('span').html( data.label ); }, // --------------------------------------------------------------------- // Ajax response parser. // --------------------------------------------------------------------- parseResponse: function( response ) { var elid = 'activity-stream-container', data, temp; if ( response && response.length ) { for ( var i = 0; i < response.length; i++ ) { if ( response[i][1] === elid ) { data = response[i][3]; } if ( response[i][0] === 'al' ) { temp = response[i][3]; window.alert( $.isArray( temp ) ? temp.join('. ') : temp ); } if ( response[i][1] === '__throwError' ) { temp = response[i][3]; window.alert( $.isArray( temp ) ? temp.join('. ') : temp ); } if ( response[i][0] === 'cs' ) { try { eval( response[i][1] ); } catch (e) {} } } } return data; }, // --------------------------------------------------------------------- // Helper functions. // --------------------------------------------------------------------- getTemplate: function() { var lang = language.get('event') || {}; if ( lang.event_detail ) lang.event_detail = lang.event_detail.toLowerCase(); var html = this.template({ juri: constants.get('juri'), language: { postbox: language.get('postbox') || {}, event: lang } }); return $( html ).hide(); }, getStaticAttachment: function() { if ( this.staticAttachment ) return this.staticAttachment; this.staticAttachment = $.extend({}, constants.get('postbox.attachment') || {}, { type: 'event' } ); return this.staticAttachment; }, trim: function( text ) { return (text || '').replace( /^\s+|\s+$/g, '' ); } }); });PK ! X���. . postbox/custom.jsnu �[��� define('views/postbox/custom',[ 'sandbox', 'views/postbox/default', 'views/dropdown/privacy', 'utils/ajax', 'utils/constants', 'utils/language' ], // definition // ---------- function( $, DefaultView, PrivacyView, ajax, constants, language ) { return DefaultView.extend({ subviews: { privacy: PrivacyView }, template: joms.jst[ 'html/postbox/custom' ], events: $.extend({}, DefaultView.prototype.events, { 'click .joms-postbox-predefined-message': 'onCustomPredefined', 'click .joms-postbox-custom-message': 'onCustomCustom', 'keyup [name=custom]': 'onTextareaUpdate' }), initialize: function() { var settings = constants.get('settings') || {}; if ( this.inheritPrivacy = (settings.isPage || settings.isGroup || settings.isEvent || !settings.isMyProfile)) this.subviews = $.omit( this.subviews, 'privacy' ); DefaultView.prototype.initialize.apply( this ); this.attachment = { type: 'custom' }; $.extend( this.attachment, constants.get('postbox.attachment') || {} ); }, render: function() { DefaultView.prototype.render.apply( this ); this.$initial = this.$el.children('.joms-postbox-inner-panel'); this.$main = this.$el.children('.joms-postbox-custom'); this.$statepredefined = this.$('.joms-postbox-custom-state-predefined'); this.$statecustom = this.$('.joms-postbox-custom-state-custom'); this.$predefined = this.$('[name=predefined]'); this.$custom = this.$('[name=custom]'); this.$divs = this.$('.joms-postbox-dropdown').hide(); this.$tabprivacy = this.$tabs.find('[data-tab=privacy]'); if ( this.inheritPrivacy ) this.$tabprivacy.css({ visibility: 'hidden' }); // init privacy if ( !this.inheritPrivacy ) { this.initSubview('privacy', { privacylist: [ 'public', 'site_members' ] }); this.subviews.privacy.setPrivacy('public'); } return this; }, showInitialState: function() { this.$main.hide(); this.$initial.show(); DefaultView.prototype.showInitialState.apply( this ); }, showMainState: function( predefined ) { DefaultView.prototype.showMainState.apply( this ); predefined ? this.showPredefinedState() : this.showCustomState(); }, showPredefinedState: function() { this.$initial.hide(); this.$statepredefined.show(); this.$statecustom.hide(); this.$main.show(); this.$save.show(); this.predefined = true; }, showCustomState: function() { this.$initial.hide(); this.$statepredefined.hide(); this.$statecustom.show(); this.$main.show(); this.predefined = false; }, // --------------------------------------------------------------------- // Data validation and retrieval. // --------------------------------------------------------------------- reset: function() { DefaultView.prototype.reset.apply( this ); this.$predefined && this.$predefined.val( this.$predefined.find('option:first').val() ); this.$custom && this.$custom.val(''); }, value: function() { var data = []; if ( this.predefined ) { data.push( this.$predefined.val() ); data.push( this.$predefined.find('option:selected').text() ); } else { data.push( 'system.message' ); data.push( this.$custom.val().replace( /\n/g, '\\n' ) ); } if ( 'privacy' in this.subflags ) data.push( this.subviews.privacy.value() ); return data; }, validate: function() { var value = this.value(), error; if ( this.predefined ) { value[0] || (error = 'Predefined message cannot be empty.'); } else { value[1] || (error = 'Custom message cannot be empty.'); } return error; }, // --------------------------------------------------------------------- // Textare event handlers. // --------------------------------------------------------------------- onTextareaUpdate: function() { var value = this.$custom.val(); value = value.replace( /^\s+|\s+$/g, '' ); this.$save[ value ? 'show' : 'hide' ](); }, // --------------------------------------------------------------------- // Panel event handlers. // --------------------------------------------------------------------- onCustomPredefined: function() { this.showMainState('predefined'); }, onCustomCustom: function() { this.showMainState(); }, onPost: function() { if ( this.saving ) return; var error = this.validate(); if ( error ) { window.alert( error ); return; } this.saving = true; this.$loading.show(); var that = this; ajax({ fn: 'activities,ajaxAddPredefined', data: this.value(), success: $.bind( this.onPostSuccess, this ), complete: function() { that.$loading.hide(); that.saving = false; that.showInitialState(); } }); }, // --------------------------------------------------------------------- // Dropdowns event handlers. // --------------------------------------------------------------------- onPrivacySelect: function( data ) { var icon = this.$tabprivacy.find('use'), href = icon.attr('xlink:href'); href = href.replace(/#.+$/, '#joms-icon-' + data.icon ); this.$tabprivacy.find('use').attr( 'xlink:href', href ); this.$tabprivacy.find('span').html( data.label ); }, // --------------------------------------------------------------------- // Helper functions. // --------------------------------------------------------------------- getTemplate: function() { var obj = constants.get('customActivities') || {}, messages = []; for ( var prop in obj ) messages.push([ prop, obj[ prop ] ]); var html = this.template({ juri: constants.get('juri'), messages: messages, language: { postbox: language.get('postbox'), custom: language.get('custom') } }); return $( html ).hide(); } }); }); PK ! G�M�&