2016-08-18 20:39:31 +00:00
$ ( function ( ) { $ ( window ) . on ( "resize" , function ( ) { CHV . fn . uploader . boxSizer ( ) ; if ( typeof user _background _full _fix == "function" ) { user _background _full _fix ( ) ; }
CHV . fn . bindSelectableItems ( ) ; } ) ; if ( $ ( "#home-cover, #maintenance-wrapper" ) . exists ( ) ) { if ( $ ( "#maintenance-wrapper" ) . exists ( ) ) { var landing _src = $ ( "#maintenance-wrapper" ) . css ( "background-image" ) . slice ( 4 , - 1 ) . replace ( /^\"|\"$/g , "" ) ; } else { var landing _src = $ ( ".home-cover-img" , "#home-cover-slideshow" ) . first ( ) . attr ( "data-src" ) ; }
function showHomeCover ( ) { $ ( "body" ) . addClass ( "load" ) ; if ( ! $ ( "#maintenance-wrapper" ) . exists ( ) ) { $ ( ".home-cover-img" , "#home-cover-slideshow" ) . first ( ) . css ( "background-image" , "url(" + landing _src + ")" ) . addClass ( "animate-in--alt" ) . removeAttr ( "data-src" ) ; }
setTimeout ( function ( ) { $ ( "body" ) . addClass ( "loaded" ) ; setTimeout ( function ( ) { showHomeSlideshow ( ) ; } , 7000 ) ; } , 400 * 1.5 ) ; }
var showHomeSlideshowInterval = function ( ) { setTimeout ( function ( ) { showHomeSlideshow ( ) ; } , 8000 ) ; } ; function showHomeSlideshow ( ) { var $image = $ ( ".home-cover-img[data-src]" , "#home-cover-slideshow" ) . first ( ) ; var $images = $ ( ".home-cover-img" , "#home-cover-slideshow" ) ; if ( $image . length == 0 ) { if ( $images . length == 1 ) return ; $images . first ( ) . removeClass ( "animate-in" ) ; $ ( "#home-cover-slideshow" ) . append ( $images . first ( ) ) ; setTimeout ( function ( ) { $ ( ".home-cover-img:last" , "#home-cover-slideshow" ) . addClass ( "animate-in" ) ; } , 20 ) ; setTimeout ( function ( ) { $ ( ".home-cover-img:not(:last)" , "#home-cover-slideshow" ) . removeClass ( "animate-in" ) ; } , 4000 ) ; showHomeSlideshowInterval ( ) ; } else { var src = $image . attr ( "data-src" ) ; $ ( "<img/>" ) . attr ( "src" , src ) . on ( "load error" , function ( ) { $ ( this ) . remove ( ) ; $image . css ( "background-image" , "url(" + src + ")" ) . addClass ( "animate-in" ) . removeAttr ( "data-src" ) ; setTimeout ( function ( ) { $ ( ".home-cover-img:not(:last)" , "#home-cover-slideshow" ) . removeClass ( "animate-end animate-in--alt" ) ; } , 2000 ) ; showHomeSlideshowInterval ( ) ; } ) ; } }
if ( landing _src ) { $ ( "<img/>" ) . attr ( "src" , landing _src ) . on ( "load error" , function ( ) { $ ( this ) . remove ( ) ; showHomeCover ( ) ; } ) ; } else { showHomeCover ( ) ; } }
var anywhere _upload = CHV . fn . uploader . selectors . root , anywhere _upload _queue = CHV . fn . uploader . selectors . queue , $anywhere _upload = $ ( anywhere _upload ) , $anywhere _upload _queue = $ ( anywhere _upload _queue ) ; $ ( document ) . on ( "click" , "[data-action=top-bar-upload]" , function ( e ) { CHV . fn . uploader . toggle ( ) ; } ) ; $ ( "[data-action=close-upload], [data-action=cancel-upload]" , $anywhere _upload ) . click ( function ( ) { if ( $anywhere _upload . is ( ":animated" ) ) return ; $ ( "[data-action=top-bar-upload]" , "#top-bar" ) . click ( ) ; } ) ; $ ( "[data-action=cancel-upload-remaining]" , $anywhere _upload ) . click ( function ( ) { $ ( "[data-action=cancel]" , $anywhere _upload _queue ) . click ( ) ; CHV . fn . uploader . is _uploading = false ; if ( CHV . fn . uploader . results . success . length > 0 ) { CHV . fn . uploader . displayResults ( ) ; return ; } else { CHV . fn . uploader . reset ( ) ; } } ) ; $ ( document ) . on ( "click" , "[data-action=upload-privacy]:not(disabled)" , function ( e ) { if ( e . isDefaultPrevented ( ) ) return ; current _privacy = $ ( this ) . data ( "privacy" ) ; target _privacy = current _privacy == "public" ? "private" : "public" ; this _lock = $ ( ".icon" , this ) . data ( "lock" ) ; this _unlock = $ ( ".icon" , this ) . data ( "unlock" ) ; $ ( ".icon" , this ) . removeClass ( this _lock + " " + this _unlock ) . addClass ( current _privacy == "public" ? this _lock : this _unlock ) ; $ ( this ) . data ( "privacy" , target _privacy ) ; $ ( "[data-action=upload-privacy-copy]" ) . html ( $ ( "[data-action=upload-privacy]" ) . html ( ) ) ; $upload _button = $ ( "[data-action=upload]" , $anywhere _upload ) ; $upload _button . text ( $upload _button . data ( target _privacy ) ) ; $ ( this ) . tipTip ( "hide" ) ; } ) ; $ ( CHV . fn . uploader . selectors . file + ", " + CHV . fn . uploader . selectors . camera ) . on ( "change" , function ( e ) { if ( ! $ ( CHV . fn . uploader . selectors . root ) . data ( "shown" ) ) { CHV . fn . uploader . toggle ( { callback : function ( e ) { CHV . fn . uploader . add ( e ) ; } } , e ) ; } else { CHV . fn . uploader . add ( e ) ; } } ) . on ( "click" , function ( e ) { if ( $ ( this ) . data ( 'login-needed' ) && ! PF . fn . is _user _logged ( ) ) { return ; } } ) ; function isFileTransfer ( e ) { var e = e . originalEvent , isFileTransfer = false ; if ( e . dataTransfer . types ) { for ( var i = 0 ; i < e . dataTransfer . types . length ; i ++ ) { if ( e . dataTransfer . types [ i ] == "Files" ) { isFileTransfer = true ; break ; } } }
return isFileTransfer ; }
if ( $ ( CHV . fn . uploader . selectors . root ) . exists ( ) ) { $ ( "body" ) . on ( { dragenter : function ( e ) { e . preventDefault ( ) ; if ( ! isFileTransfer ( e ) ) { return false ; }
if ( ! $ ( CHV . fn . uploader . selectors . dropzone ) . exists ( ) ) { $ ( "body" ) . append ( $ ( '<div id="' + CHV . fn . uploader . selectors . dropzone . replace ( "#" , "" ) + '"/>' ) . css ( { width : "100%" , height : "100%" , position : "fixed" , zIndex : 1000 , left : 0 , top : 0 } ) ) ; } } } ) ; $ ( document ) . on ( { dragover : function ( e ) { e . preventDefault ( ) ; if ( ! isFileTransfer ( e ) ) { return false ; }
if ( ! $ ( CHV . fn . uploader . selectors . root ) . data ( "shown" ) ) { CHV . fn . uploader . toggle ( { reset : false } ) ; } } , dragleave : function ( e ) { $ ( CHV . fn . uploader . selectors . dropzone ) . remove ( ) ; if ( $ . isEmptyObject ( CHV . fn . uploader . files ) ) { CHV . fn . uploader . toggle ( ) ; } } , drop : function ( e ) { e . preventDefault ( ) ; CHV . fn . uploader . add ( e ) ; $ ( CHV . fn . uploader . selectors . dropzone ) . remove ( ) ; } , } , CHV . fn . uploader . selectors . dropzone ) ; }
$ ( document ) . on ( "keyup change" , "[data-action=resize-combo-input]" , function ( e ) { var $parent = $ ( this ) . closest ( "[data-action=resize-combo-input]" ) ; var $input _width = $ ( "[name=form-width]" , $parent ) ; var $input _height = $ ( "[name=form-height]" , $parent ) ; var ratio = $input _width . data ( "initial" ) / $input _height . data ( "initial" ) ; if ( $ ( e . target ) . is ( $input _width ) ) { $input _height . prop ( "value" , Math . round ( Math . round ( $input _width . prop ( "value" ) / ratio ) ) ) ; } else { $input _width . prop ( "value" , Math . round ( Math . round ( $input _height . prop ( "value" ) * ratio ) ) ) ; } } )
$ ( document ) . on ( "click" , anywhere _upload _queue + " [data-action=edit]" , function ( ) { var $item = $ ( this ) . closest ( "li" ) , $queue = $item . closest ( "ul" ) , id = $item . data ( "id" ) , file = CHV . fn . uploader . files [ id ] ; var modal = PF . obj . modal . selectors . root ; var queueObject = $ . extend ( { } , file . formValues || file . parsedMeta ) ; if ( typeof queueObject . category _id == typeof undefined ) { var upload _category = $ ( "[name=upload-category-id]" , CHV . fn . uploader . selectors . root ) . prop ( "value" ) || null ; queueObject . category _id = upload _category ; }
if ( typeof queueObject . nsfw == typeof undefined ) { var upload _nsfw = $ ( "[name=upload-nsfw]:checked" , CHV . fn . uploader . selectors . root ) . prop ( "value" ) || null ; queueObject . nsfw = upload _nsfw ; }
PF . fn . modal . call ( { type : "html" , template : $ ( "#anywhere-upload-edit-item" ) . html ( ) , callback : function ( ) { $ . each ( queueObject , function ( i , v ) { var name = "[name=form-" + i . replace ( /_/g , "-" ) + "]" ; var $input = $ ( name , modal ) ; if ( ! $input . exists ( ) ) return true ; if ( $input . is ( ":checkbox" ) ) { $input . prop ( "checked" , $input . attr ( "value" ) == v ) ; } else if ( $input . is ( "select" ) ) { var $option = $input . find ( "[value=" + v + "]" ) ; if ( ! $option . exists ( ) ) { $option = $input . find ( "option:first" ) ; }
$option . prop ( "selected" , true ) ; } else { $input . prop ( "value" , v ) ; }
if ( i == "width" || i == "height" ) { $input . prop ( "max" , file . parsedMeta [ i ] ) . data ( "initial" , file . parsedMeta [ i ] ) ; } } ) ; if ( file . parsedMeta . mimetype !== "image/gif" ) { $ ( "[ data-content=animated-gif-warning]" , modal ) . remove ( ) ; }
$ ( ".image-preview" , modal ) . append ( $ ( '<canvas/>' , { 'class' : 'canvas' } ) ) ; var source _canvas = $ ( ".queue-item[data-id=" + id + "] .preview .canvas" ) [ 0 ] ; var target _canvas = $ ( ".image-preview .canvas" , modal ) [ 0 ] ; target _canvas . width = source _canvas . width ; target _canvas . height = source _canvas . height ; var target _canvas _ctx = target _canvas . getContext ( '2d' ) ; target _canvas _ctx . drawImage ( source _canvas , 0 , 0 ) ; } , confirm : function ( ) { if ( ! PF . fn . form _modal _has _changed ( ) ) { PF . fn . modal . close ( ) ; return ; }
var errors = false ; $ . each ( [ "width" , "height" ] , function ( i , v ) { var $input = $ ( "[name=form-" + v + "]" , modal ) ; var input _val = parseInt ( $input . val ( ) ) ; var min _val = parseInt ( $input . attr ( "min" ) ) ; var max _val = parseInt ( $input . attr ( "max" ) ) ; if ( input _val > max _val || input _val < min _val ) { $input . highlight ( ) ; errors = true ; return true ; } } ) ; if ( errors ) { PF . fn . growl . expirable ( PF . fn . _s ( "Check the errors in the form to continue." ) ) ; return false ; }
if ( typeof file . formValues == typeof undefined ) { file . formValues = { title : null , category _id : null , width : null , height : null , nsfw : null , expiration : null , description : null , } ; }
$ ( ":input[name]" , modal ) . each ( function ( i , v ) { var key = $ ( this ) . attr ( "name" ) . replace ( "form-" , "" ) . replace ( /-/g , "_" ) ; if ( typeof file . formValues [ key ] == typeof undefined ) return true ; file . formValues [ key ] = $ ( this ) . is ( ":checkbox" ) ? ( $ ( this ) . is ( ":checked" ) ? $ ( this ) . prop ( "value" ) : null ) : $ ( this ) . prop ( "value" ) ; } ) ; CHV . fn . uploader . files [ id ] . formValues = file . formValues ; return true ; } } ) ; } ) ; $ ( document ) . on ( "click" , anywhere _upload _queue + " [data-action=cancel]" , function ( ) { var $item = $ ( this ) . closest ( "li" ) , $queue = $item . closest ( "ul" ) , id = $item . data ( "id" ) , queue _height = $queue . height ( ) , item _xhr _cancel = false ; if ( $item . hasClass ( "completed" ) || $item . hasClass ( "failed" ) ) { return ; }
$ ( "#tiptip_holder" ) . hide ( ) ; $item . tipTip ( "destroy" ) . remove ( ) ; if ( queue _height !== $queue . height ( ) ) { CHV . fn . uploader . boxSizer ( ) ; }
if ( ! $ ( "li" , $anywhere _upload _queue ) . exists ( ) ) { $ ( "[data-group=upload-queue-ready], [data-group=upload-queue], [data-group=upload-queue-ready]" , $anywhere _upload ) . css ( "display" , "" ) ; }
if ( CHV . fn . uploader . files [ id ] && typeof CHV . fn . uploader . files [ id ] . xhr !== "undefined" ) { CHV . fn . uploader . files [ id ] . xhr . abort ( ) ; item _xhr _cancel = true ; }
if ( typeof CHV . fn . uploader . files [ id ] !== typeof undefined && typeof CHV . fn . uploader . files [ id ] . fromClipboard !== typeof undefined ) { var c _md5 = CHV . fn . uploader . files [ id ] . md5 ; var c _index = CHV . fn . uploader . clipboardImages . indexOf ( c _md5 ) ; if ( c _index > - 1 ) { CHV . fn . uploader . clipboardImages . splice ( c _index , 1 ) ; } }
delete CHV . fn . uploader . files [ id ] ; CHV . fn . uploader . queueSize ( ) ; if ( Object . size ( CHV . fn . uploader . files ) == 0 ) { if ( CHV . fn . uploader . results . success . length == 0 && CHV . fn . uploader . results . error . length == 0 ) { CHV . fn . uploader . reset ( ) ; } } else { if ( item _xhr _cancel ) { if ( $ ( "li.waiting" , $queue ) . first ( ) . length !== 0 ) { CHV . fn . uploader . upload ( $ ( "li.waiting" , $queue ) . first ( ) ) ; } else if ( CHV . fn . uploader . results . success . length !== 0 || CHV . fn . uploader . results . error . length !== 0 ) { CHV . fn . uploader . displayResults ( ) ; } } } } ) ; $ ( document ) . on ( "click" , "[data-action=upload]" , function ( ) { $ ( "[data-group=upload], [data-group=upload-queue-ready]" , $anywhere _upload ) . hide ( ) ; $ ( "[data-group=uploading]" , $anywhere _upload ) . show ( ) ; CHV . fn . uploader . queueSize ( ) ; CHV . fn . uploader . can _add = false ; $queue _items = $ ( "li" , $anywhere _upload _queue ) ; $queue _items . addClass ( "uploading waiting" ) ; CHV . fn . uploader . timestamp = new Date ( ) . getTime ( ) ; CHV . fn . uploader . upload ( $queue _items . first ( "li" ) ) ; } ) ; if ( $ ( "body#user" ) . exists ( ) ) { if ( PF . obj . listing . query _string . page > 1 ) { var State = History . getState ( ) ; console . log ( State . data )
if ( State . data && typeof State . data . scrollTop !== "undefined" ) { if ( $ ( window ) . scrollTop ( ) !== State . data . scrollTop ) { $ ( window ) . scrollTop ( State . data . scrollTop ) ; } } else { var scrollTop = $ ( "#background-cover" ) . height ( ) - 160 ; $ ( "html, body" ) . animate ( { scrollTop : scrollTop } , 0 ) ; } } }
if ( ! PF . fn . isDevice ( 'phone' ) ) { if ( $ ( "#top-bar-shade" ) . exists ( ) ) { if ( $ ( "#top-bar-shade" ) . css ( "opacity" ) ) { $ ( "#top-bar-shade" ) . data ( "initial-opacity" , Number ( $ ( "#top-bar-shade" ) . css ( "opacity" ) ) ) ; } }
$ ( window ) . scroll ( function ( ) { var Y = $ ( window ) . scrollTop ( ) ; var is _slim _shady = $ ( "#top-bar-shade" ) . exists ( ) && ! $ ( "html" ) . hasClass ( "top-bar-box-shadow-none" ) ; if ( Y < 0 ) return ; var $top _bar = $ ( "#top-bar" ) ; var rate = Number ( Y / ( $ ( "#background-cover, [data-content=follow-scroll-opacity]" ) . height ( ) - $top _bar . height ( ) ) ) ; if ( rate > 1 ) rate = 1 ; if ( is _slim _shady ) { if ( $ ( "#top-bar-shade" ) . data ( "initial-opacity" ) ) { rate += $ ( "#top-bar-shade" ) . data ( "initial-opacity" ) ; }
$ ( "#top-bar-shade" ) . css ( { opacity : rate } ) ; }
if ( rate == 1 ) return ; $ ( "#background-cover-src" ) . css ( { transform : "translate(0, " + Y * 0.8 + "px" + ")" } ) ; } ) ; }
CHV . fn . bindSelectableItems ( ) ; if ( $ ( "body#image" ) . exists ( ) ) { if ( $ ( CHV . obj . image _viewer . selector + " [data-load=full]" ) . length > 0 ) { $ ( document ) . on ( "click" , CHV . obj . image _viewer . loader , function ( e ) { CHV . fn . viewerLoadImage ( ) ; } ) ; var image _size = $ ( CHV . obj . image _viewer . loader ) . data ( "size" ) ; if ( image _size > "3 MB" . getBytes ( ) || ( image _size > "500 KB" . getBytes ( ) && PF . fn . isDevice ( [ "phone" , "phablet" ] ) ) ) { $ ( CHV . obj . image _viewer . loader ) . css ( "display" , "block" ) ; } else { CHV . fn . viewerLoadImage ( ) ; }
$ ( document ) . bind ( "DOMSubtreeModified" , function ( ) { if ( $ ( "html" ) . height ( ) > $ ( window ) . innerHeight ( ) && ! $ ( "html" ) . hasClass ( "scrollbar-y" ) ) { $ ( "html" ) . addClass ( "scrollbar-y" ) ; $ ( document ) . data ( { width : $ ( this ) . width ( ) , height : $ ( this ) . height ( ) } ) ; CHV . fn . image _viewer _full _fix ( ) ; } } ) ; $ ( window ) . on ( "resize" , function ( ) { CHV . fn . image _viewer _full _fix ( ) ; } ) ; $ ( document ) . on ( "keyup" , function ( e ) { var $this = $ ( e . target ) , key = e . charCode || e . keyCode ; if ( $this . is ( ":input" ) ) { return ; } else { if ( CHV . obj . image _viewer . $navigation . exists ( ) && ( key == 37 || key == 39 ) ) { var navigation _jump _url = $ ( "[data-action=" + ( key == 37 ? "prev" : "next" ) + "]" , CHV . obj . image _viewer . $navigation ) . attr ( "href" ) ; if ( typeof navigation _jump _url !== "undefined" && navigation _jump _url !== "" ) { window . location = $ ( "[data-action=" + ( key == 37 ? "prev" : "next" ) + "]" , CHV . obj . image _viewer . $navigation ) . attr ( "href" ) ; } } } } ) ; } else { CHV . fn . viewerImageZoomClass ( ) ; } }
$ ( document ) . on ( "click" , CHV . obj . image _viewer . container , function ( e ) { if ( ! ( $ ( this ) . hasClass ( "cursor-zoom-in" ) || $ ( this ) . hasClass ( "cursor-zoom-out" ) ) ) return ; var zoom _in = $ ( this ) . hasClass ( "cursor-zoom-in" ) ; $ ( this ) . removeClass ( "cursor-zoom-in cursor-zoom-out" ) ; if ( zoom _in ) { var width = $ ( this ) [ 0 ] . getBoundingClientRect ( ) . width , height = $ ( this ) [ 0 ] . getBoundingClientRect ( ) . height , ratio = $ ( "img" , this ) . attr ( "width" ) / $ ( "img" , this ) . attr ( "height" ) , new _width ; if ( typeof $ ( this ) . data ( "dimentions" ) == typeof undefined ) { $ ( this ) . data ( { dimentions : { width : width , height : height } , ratio : ratio } ) ; }
if ( $ ( "img" , this ) . attr ( "width" ) > $ ( window ) . width ( ) ) { $ ( this ) . css ( { width : "100%" } ) ; new _width = $ ( this ) . width ( ) ; $ ( this ) . css ( { width : width } ) ; } else { new _width = $ ( "img" , this ) . attr ( "width" ) ; }
$ ( this ) . addClass ( "cursor-zoom-out" ) . css ( { width : new _width , height : ( new _width / ratio ) + "px" } ) ; } else { $ ( this ) . addClass ( "cursor-zoom-in" ) . css ( $ ( this ) . data ( "dimentions" ) ) ; }
e . preventDefault ( ) ; } ) . on ( "contextmenu" , CHV . obj . image _viewer . container , function ( e ) { if ( ! CHV . obj . config . image . right _click ) { e . preventDefault ( ) ; return false ; } } ) ; $ ( document ) . on ( "click" , "[data-action=test-email]" , function ( e ) { e . preventDefault ( ) ; var $email = $ ( "input[name=test-email]" ) ; if ( $email . prop ( "disabled" ) ) { return ; }
var $parent = $ ( this ) . closest ( ".input-label" ) ; var email = $email . val ( ) ; if ( ! email . isEmail ( ) ) { PF . fn . growl . expirable ( PF . fn . _s ( "Please provide a valid email address" ) ) ; return ; }
$email . prop ( "disabled" , true ) ; PF . fn . loading . inline ( $ ( '.loading' , $parent ) , { size : "small" , valign : "middle" } ) ; $parent . find ( ".btn .text" ) . hide ( ) ; $ . ajax ( { data : { action : "test" , test : { object : "email" } , email : email } , cache : false } ) . complete ( function ( XHR ) { var response = XHR . responseJSON ; $email . prop ( "disabled" , false ) ; $ ( '.loading' , $parent ) . empty ( ) ; $parent . find ( ".btn .text" ) . show ( ) ; PF . fn . growl . call ( response [ response . status _code == 200 ? "success" : "error" ] . message ) ; } ) ; } ) ; $ ( document ) . on ( "click" , ".list-item, [data-action=list-tools] [data-action]" , function ( e ) { var $this = $ ( e . target ) , $list _item = $this . closest ( ".list-item" ) ; if ( $list _item && $list _item . find ( "[data-action=select]" ) . exists ( ) && ( e . ctrlKey || e . metaKey ) && e . altKey ) { CHV . fn . list _editor . toggleSelectItem ( $list _item , ! $list _item . hasClass ( "selected" ) ) ; e . preventDefault ( ) ; e . stopPropagation ( ) ; } } ) ; PF . fn . listing . ajax . callback = function ( XHR ) { if ( XHR . status !== 200 ) return ; CHV . fn . list _editor . listMassActionSet ( "select" ) ; } ; $ ( document ) . on ( "click" , "[data-action=list-select-all]" , function ( ) { CHV . fn . list _editor . selectItem ( $ ( ".list-item:visible:not(.selected)" ) ) ; CHV . fn . list _editor . listMassActionSet ( "clear" ) ; } ) ; $ ( document ) . on ( "click" , "[data-action=list-clear-all]" , function ( ) { PF . fn . close _pops ( ) ; CHV . fn . list _editor . clearSelection ( ) ; } ) ; $ ( document ) . on ( "click" , "[data-action=list-tools] [data-action]" , function ( e ) { if ( e . isPropagationStopped ( ) ) return false ; var $this _list _item = $ ( this ) . closest ( PF . obj . listing . selectors . list _item ) , $this _list _item _tools = $ ( this ) . closest ( "[data-action=list-tools]" ) ; var $this _icon , this _add _class , this _remove _class , this _label _text , dealing _with ; if ( typeof $this _list _item . data ( "type" ) !== "undefined" ) { dealing _with = $this _list _item . data ( "type" ) ; } else { console . log ( "Error: data-type not defined" ) ; return ; }
switch ( $ ( this ) . data ( "action" ) ) { case "select" : CHV . fn . list _editor . toggleSelectItem ( $this _list _item , ! $this _list _item . hasClass ( "selected" ) ) ; break ; case "edit" : var modal _source = "[data-modal=form-edit-single]" ; switch ( dealing _with ) { case "image" : $ ( "[name=form-image-title]" , modal _source ) . attr ( "value" , $this _list _item . data ( "title" ) ) ; $ ( "[name=form-image-description]" , modal _source ) . html ( PF . fn . htmlEncode ( $this _list _item . data ( "description" ) ) ) ; $ ( "[name=form-album-id]" , modal _source ) . find ( "option" ) . removeAttr ( "selected" ) ; $ ( "[name=form-album-id]" , modal _source ) . find ( "[value=" + $this _list _item . data ( dealing _with == "image" ? "album-id" : "id" ) + "]" ) . attr ( "selected" , true ) ; $ ( "[name=form-category-id]" , modal _source ) . find ( "option" ) . removeAttr ( "selected" ) ; $ ( "[name=form-category-id]" , modal _source ) . find ( "[value=" + $this _list _item . data ( "category-id" ) + "]" ) . attr ( "selected" , true ) ; $ ( "[name=form-nsfw]" , modal _source ) . attr ( "checked" , $this _list _item . data ( "flag" ) == "unsafe" ) ; $ ( "[name=form-album-name]" , modal _source ) . attr ( "value" , "" ) ; $ ( "[name=form-album-description]" , modal _source ) . html ( "" ) ; $ ( "[name=form-privacy]" , modal _source ) . find ( "option" ) . removeAttr ( "selected" ) ; break ; case "album" : $ ( "[data-action=album-switch]" , modal _source ) . remove ( ) ; $ ( "[name=form-album-name]" , modal _source ) . attr ( "value" , $this _list _item . data ( "name" ) ) ; $ ( "[name=form-album-description]" , modal _source ) . html ( PF . fn . htmlEncode ( $this _list _item . data ( "description" ) ) ) ; $ ( "[name=form-privacy]" , modal _source ) . find ( "option" ) . removeAttr ( "selected" ) ; $ ( "[name=form-privacy]" , modal _source ) . find ( "[value=" + $this _list _item . data ( "privacy" ) + "]" ) . attr ( "selected" , true ) ; if ( $this _list _item . data ( "privacy" ) == 'password' ) { $ ( "[data-combo-value=password]" ) . show ( ) ; $ ( "[name=form-album-password]" , modal _source ) . attr ( "value" , $this _list _item . data ( "password" ) ) ; } else { $ ( "[data-combo-value=password]" ) . hide ( ) ; $ ( "[name=form-album-password]" , modal _source ) . attr ( "value" , "" ) ; }
break ; }
PF . fn . modal . call ( { type : "html" , template : $ ( modal _source ) . html ( ) , ajax : { url : PF . obj . config . json _api , deferred : { success : function ( XHR ) { CHV . fn . list _editor . updateItem ( "[data-id=" + $this _list _item . data ( "id" ) + "]" , XHR . responseJSON [ dealing _with ] , "edit" ) ; } } } , confirm : function ( ) { var $modal = $ ( PF . obj . modal . selectors . root ) ; if ( ( dealing _with == "image" || dealing _with == "album" ) && $ ( "[data-content=form-new-album]" , $modal ) . is ( ":visible" ) && $ ( "[name=form-album-name]" , $modal ) . val ( ) == "" ) { PF . fn . growl . call ( PF . fn . _s ( "You must enter the album name." ) ) ; $ ( "[name=form-album-name]" , $modal ) . highlight ( ) ; return false ; }
if ( ! PF . fn . form _modal _has _changed ( ) ) { PF . fn . modal . close ( ) ; return ; }
PF . obj . modal . form _data = { action : "edit" , edit : $this _list _item . data ( "type" ) , single : true , owner : CHV . obj . resource . user . id , editing : { id : $this _list _item . data ( "id" ) , description : $ ( "[name=form-" + dealing _with + "-description]" , $modal ) . val ( ) } } ; switch ( dealing _with ) { case "image" : PF . obj . modal . form _data . editing . title = $ ( "[name=form-image-title]" , $modal ) . val ( ) ; PF . obj . modal . form _data . editing . category _id = $ ( "[name=form-category-id]" , $modal ) . val ( ) || null ; PF . obj . modal . form _data . editing . nsfw = $ ( "[name=form-nsfw]" , $modal ) . prop ( "checked" ) ? 1 : 0 ; break ; case "album" : PF . obj . modal . form _data . editing . name = $ ( "[name=form-album-name]" , $modal ) . val ( ) ; PF . obj . modal . form _data . editing . privacy = $ ( "[name=form-privacy]" , $modal ) . val ( ) ; if ( PF . obj . modal . form _data . editing . privacy == "password" ) { PF . obj . modal . form _data . editing . password = $ ( "[name=form-album-password]" , $modal ) . val ( ) ; }
break ; }
PF . obj . modal . form _data . editing . new _album = $ ( "[data-content=form-new-album]" , $modal ) . is ( ":visible" ) ; if ( PF . obj . modal . form _data . editing . new _album ) { PF . obj . modal . form _data . editing . album _name = $ ( "[name=form-album-name]" , $modal ) . val ( ) ; PF . obj . modal . form _data . editing . album _privacy = $ ( "[name=form-privacy]" , $modal ) . val ( ) ; if ( PF . obj . modal . form _data . editing . album _privacy == "password" ) { PF . obj . modal . form _data . editing . album _password = $ ( "[name=form-album-password]" , $modal ) . val ( ) ; }
PF . obj . modal . form _data . editing . album _description = $ ( "[name=form-album-description]" , $modal ) . val ( ) ; } else { PF . obj . modal . form _data . editing . album _id = $ ( "[name=form-album-id]" , $modal ) . val ( ) ; }
return true ; } } ) ; break ; case "move" : var modal _source = "[data-modal=form-move-single]" ; $ ( "[name=form-album-id]" , modal _source ) . find ( "option" ) . removeAttr ( "selected" ) ; $ ( "[name=form-album-id]" , modal _source ) . find ( "[value=" + $this _list _item . data ( dealing _with == "image" ? "album-id" : "id" ) + "]" ) . attr ( "selected" , true ) ; $ ( "[name=form-album-name]" , modal _source ) . attr ( "value" , "" ) ; $ ( "[name=form-album-description]" , modal _source ) . html ( "" ) ; $ ( "[name=form-privacy]" , modal _source ) . find ( "option" ) . removeAttr ( "selected" ) ; PF . fn . modal . call ( { type : "html" , template : $ ( modal _source ) . html ( ) , ajax : { url : PF . obj . config . json _api , deferred : { success : function ( XHR ) { CHV . fn . list _editor . updateMoveItemLists ( XHR . responseJSON , dealing _with , $this _list _item ) ; } } } , confirm : function ( ) { var $modal = $ ( PF . obj . modal . selectors . root ) ; if ( $ ( "[data-content=form-new-album]" , $modal ) . is ( ":visible" ) && $ ( "[name=form-album-name]" , $modal ) . val ( ) == "" ) { PF . fn . growl . call ( PF . fn . _s ( "You must enter the album name." ) ) ; $ ( "[name=form-album-name]" , $modal ) . highlight ( ) ; return false ; }
if ( ! PF . fn . form _modal _has _changed ( ) ) { PF . fn . modal . close ( ) ; return ; }
PF . obj . modal . form _data = { action : "edit" , edit : $this _list _item . data ( "type" ) , single : true , owner : CHV . obj . resource . user . id , editing : { id : $this _list _item . data ( "id" ) } } ; PF . obj . modal . form _data . editing . new _album = $ ( "[data-content=form-new-album]" , $modal ) . is ( ":visible" ) ; if ( PF . obj . modal . form _data . editing . new _album ) { PF . obj . modal . form _data . editing . album _name = $ ( "[name=form-album-name]" , $modal ) . val ( ) ; PF . obj . modal . form _data . editing . album _privacy = $ ( "[name=form-privacy]" , $modal ) . val ( ) ; if ( PF . obj . modal . form _data . editing . album _privacy == "password" ) { PF . obj . modal . form _data . editing . album _password = $ ( "[name=form-album-password]" , $modal ) . val ( ) ; }
PF . obj . modal . form _data . editing . album _description = $ ( "[name=form-album-description]" , $modal ) . val ( ) ; } else { PF . obj . modal . form _data . editing . album _id = $ ( "[name=form-album-id]" , $modal ) . val ( ) ; }
return true ; } } ) ; break ; case "delete" : PF . fn . modal . call ( { type : "html" , template : $ ( "[data-modal=form-delete-single]" ) . html ( ) , button _submit : PF . fn . _s ( "Confirm" ) , ajax : { url : PF . obj . config . json _api , deferred : { success : function ( XHR ) { if ( dealing _with == "album" ) { $ ( "[name=form-album-id]" , "[data-modal]" ) . find ( "[value=" + $this _list _item . data ( "id" ) + "]" ) . remove ( ) ; CHV . fn . list _editor . updateUserCounters ( "image" , XHR . responseJSON . success . affected , "-" ) ; }
CHV . fn . list _editor . deleteFromList ( $this _list _item ) ; CHV . fn . queuePixel ( ) ; } } } , confirm : function ( ) { PF . obj . modal . form _data = { action : "delete" , single : true , delete : $this _list _item . data ( "type" ) , deleting : { id : $this _list _item . data ( "id" ) } } ; return true ; } } ) ; break ; case "flag" : $ . ajax ( { type : "POST" , data : { action : 'edit' , edit : 'image' , single : true , editing : { id : $this _list _item . data ( "id" ) , nsfw : $this _list _item . data ( "flag" ) == "unsafe" ? 0 : 1 } } } ) . complete ( function ( XHR ) { var response = XHR . responseJSON , flag = response . image . nsfw == 1 ? "unsafe" : "safe" ; $this _list _item . removeClass ( "safe unsafe" ) . addClass ( flag ) . attr ( "data-flag" , flag ) . data ( "flag" , flag ) ; CHV . fn . list _editor . selectionCount ( ) ; } ) ; break ; } } ) ; $ ( ".pop-box-menu a" , "[data-content=list-selection]" ) . click ( function ( e ) { var $content _listing = $ ( PF . obj . listing . selectors . content _listing _visible ) ; if ( typeof $content _listing . data ( "list" ) !== "undefined" ) { dealing _with = $content _listing . data ( "list" ) ; } else { console . log ( "Error: data-list not defined" ) ; return ; }
var $targets = $ ( PF . obj . listing . selectors . list _item + ".selected" , $content _listing ) , ids = $ . map ( $targets , function ( e , i ) { return $ ( e ) . data ( "id" ) ; } ) ; $ ( this ) . closest ( ".pop-btn" ) . click ( ) ; switch ( $ ( this ) . data ( "action" ) ) { case "get-embed-codes" : var template = "[data-modal=form-embed-codes]" ; $ ( "textarea" , template ) . html ( "" ) , objects = [ ] ; $targets . each ( function ( ) { objects . push ( { image : $ . parseJSON ( decodeURIComponent ( $ ( this ) . data ( "object" ) ) ) } ) ; } ) ; CHV . fn . fillEmbedCodes ( objects , template , "html" ) ; PF . fn . modal . call ( { type : "html" , template : $ ( template ) . html ( ) , buttons : false } ) ; break ; case "clear" : CHV . fn . list _editor . clearSelection ( ) ; e . stopPropagation ( ) ; break ; case "move" : case "create-album" : var template = $ ( this ) . data ( "action" ) == "move" ? "form-move-multiple" : "form-create-album" , modal _source = "[data-modal=" + template + "]" , dealing _id _data = ( /image/ . test ( dealing _with ) ? "album-id" : "id" ) ; $ ( "[name=form-album-id]" , modal _source ) . find ( "[value=null]" ) . remove ( ) ; $ ( "[name=form-album-id]" , modal _source ) . find ( "option" ) . removeAttr ( "selected" ) ; $ ( "[name=form-album-name]" , modal _source ) . attr ( "value" , "" ) ; $ ( "[name=form-album-description]" , modal _source ) . html ( "" ) ; $ ( "[name=form-privacy]" , modal _source ) . find ( "option" ) . removeAttr ( "selected" ) ; var album _id = $targets . first ( ) . data ( dealing _id _data ) , same _album = true ; $targets . each ( function ( ) { if ( $ ( this ) . data ( dealing _id _data ) !== album _id ) { same _album = false ; return false ; } } ) ; if ( ! same _album ) { $ ( "[name=form-album-id]" , modal _source ) . prepend ( '<option value="null">' + PF . fn . _s ( 'Select existing album' ) + '</option>' ) ; }
$ ( "[name=form-album-id]" , modal _source ) . find ( "[value=" + ( same _album ? $targets . first ( ) . data ( dealing _id _data ) : "null" ) + "]" ) . attr ( "selected" , true ) ; PF . fn . modal . call ( { type : "html" , template : $ ( modal _source ) . html ( ) , ajax : { url : PF . obj . config . json _api , deferred : { success : function ( XHR ) { CHV . fn . list _editor . updateMoveItemLists ( XHR . responseJSON , dealing _with , $targets ) ; } } } , confirm : function ( ) { var $modal = $ ( PF . obj . modal . selectors . root ) , new _album = false ; if ( $ ( "[data-content=form-new-album]" , $modal ) . is ( ":visible" ) && $ ( "[name=form-album-name]" , $modal ) . val ( ) == "" ) { PF . fn . growl . call ( PF . fn . _s ( "You must enter the album name." ) ) ; $ ( "[name=form-album-name]" , $modal ) . highlight ( ) ; return false ; }
if ( $ ( "[data-content=form-new-album]" , $modal ) . is ( ":visible" ) ) { new _album = true ; }
if ( ! PF . fn . form _modal _has _changed ( ) ) { PF . fn . modal . close ( ) ; return ; }
var album _object = new _album ? "creating" : "moving" ; PF . obj . modal . form _data = { action : new _album ? "create-album" : "move" , type : dealing _with , owner : CHV . obj . resource . user . id , multiple : true , album : { ids : ids , "new" : new _album } } ; if ( new _album ) { PF . obj . modal . form _data . album . name = $ ( "[name=form-album-name]" , $modal ) . val ( ) ; PF . obj . modal . form _data . album . privacy = $ ( "[name=form-privacy]" , $modal ) . val ( ) ; if ( PF . obj . modal . form _data . album . privacy == "password" ) { PF . obj . modal . form _data . album . password = $ ( "[name=form-album-password]" , $modal ) . val ( ) ; }
PF . obj . modal . form _data . album . description = $ ( "[name=form-album-description]" , $modal ) . val ( ) ; } else { PF . obj . modal . form _data . album . id = $ ( "[name=form-album-id]" , $modal ) . val ( ) ; }
return true ; } } ) ; break ; case "delete" : PF . fn . modal . call ( { template : $ ( "[data-modal=form-delete-multiple]" ) . html ( ) , button _submit : PF . fn . _s ( "Confirm" ) , ajax : { url : PF . obj . config . json _api , deferred : { success : function ( XHR ) { if ( dealing _with == "albums" ) { $targets . each ( function ( ) { $ ( "[name=form-album-id]" , "[data-modal]" ) . find ( "[value=" + $ ( this ) . data ( "id" ) + "]" ) . remove ( ) ; } ) ; CHV . fn . list _editor . updateUserCounters ( "image" , XHR . responseJSON . success . affected , "-" ) ; }
CHV . fn . list _editor . deleteFromList ( $targets ) ; CHV . fn . queuePixel ( ) ; } } } , confirm : function ( ) { PF . obj . modal . form _data = { action : "delete" , from : "list" , "delete" : dealing _with , multiple : true , deleting : { ids : ids } } ; return true ; } } ) ; break ; case "assign-category" : var category _id = $targets . first ( ) . data ( "category-id" ) , same _category = true ; $targets . each ( function ( ) { if ( $ ( this ) . data ( "category-id" ) !== category _id ) { same _category = false ; return false ; } } ) ; PF . fn . modal . call ( { type : "html" , template : $ ( "[data-modal=form-assign-category]" ) . html ( ) , forced : true , ajax : { url : PF . obj . config . json _api , deferred : { success : function ( XHR ) { $targets . each ( function ( ) { var response = XHR . responseJSON ; $ ( this ) . data ( "category-id" , response . category _id ) } ) ; CHV . fn . list _editor . clearSelection ( ) ; } } } , confirm : function ( ) { var $modal = $ ( PF . obj . modal . selectors . root ) , form _category = $ ( "[name=form-category-id]" , $modal ) . val ( ) || null ; if ( same _category && category _id == form _category ) { PF . fn . modal . close ( function ( ) { CHV . fn . list _editor . clearSelection ( ) ; } ) ; return false ; }
PF . obj . modal . form _data = { action : "edit-category" , from : "list" , multiple : true , editing : { ids : ids , category _id : form _category } } ; return true ; } } ) ; break ; case "flag-safe" : case "flag-unsafe" : var action = $ ( this ) . data ( "action" ) , flag = action == "flag-safe" ? "safe" : "unsafe" ; PF . fn . modal . call ( { template : $ ( "[data-modal=form-" + action + "]" ) . html ( ) , button _submit : PF . fn . _s ( "Confirm" ) , ajax : { url : PF . obj . config . json _api , deferred : { success : function ( XHR ) { $targets . each ( function ( ) { $ ( this ) . removeClass ( "safe unsafe" ) . addClass ( flag ) . removeAttr ( "data-flag" ) . attr ( "data-flag" , flag ) . data ( "flag" , flag ) ; } ) ; CHV . fn . list _editor . clearSelection ( ) ; } } } , confirm : function ( ) { PF . obj . modal . form _data = { action : action , from : "list" , multiple : true , editing : { ids : ids , nsfw : action == "flag-safe" ? 0 : 1 } } ; return true ; } } ) ; break ; }
if ( PF . fn . isDevice ( [ "phone" , "phablet" ] ) ) { return false ; } } ) ; if ( $ ( "body#image" ) . exists ( ) ) { $ ( window ) . scroll ( function ( ) { CHV . obj . topBar . transparencyScrollToggle ( ) ; } ) ; }
$ ( document ) . on ( "click" , "[data-action=disconnect]" , function ( ) { var $this = $ ( this ) , connection = $this . data ( "connection" ) ; PF . fn . modal . confirm ( { message : $this . data ( "confirm-message" ) , ajax : { data : { action : 'disconnect' , disconnect : connection , user _id : CHV . obj . resource . user . id } , deferred : { success : function ( XHR ) { var response = XHR . responseJSON ; $ ( "[data-connection=" + connection + "]" ) . fadeOut ( function ( ) { $ ( $ ( "[data-connect=" + connection + "]" ) ) . fadeIn ( ) ; $ ( this ) . remove ( ) ; if ( $ ( "[data-connection]" ) . length == 0 ) { $ ( "[data-content=empty-message]" ) . show ( ) ; }
PF . fn . growl . expirable ( response . success . message ) ; } ) ; } , error : function ( XHR ) { var response = XHR . responseJSON ; PF . fn . growl . call ( response . error . message ) ; } } } } ) ; } ) ; $ ( document ) . on ( "click" , "[data-action=delete-avatar]" , function ( ) { var $parent = $ ( ".user-settings-avatar" ) , $loading = $ ( ".loading-placeholder" , $parent ) , $top = $ ( "#top-bar" ) ; $loading . removeClass ( "hidden" ) ; PF . fn . loading . inline ( $loading , { center : true } ) ; $ . ajax ( { type : "POST" , data : { action : "delete" , delete : "avatar" , owner : CHV . obj . resource . user . id } } ) . complete ( function ( XHR ) { $loading . addClass ( "hidden" ) . empty ( ) ; if ( XHR . status == 200 ) { if ( CHV . obj . logged _user . id == CHV . obj . resource . user . id ) { $ ( "img.user-image" , $top ) . hide ( ) ; $ ( ".default-user-image" , $top ) . removeClass ( "hidden" ) ; }
$ ( ".default-user-image" , $parent ) . removeClass ( "hidden" ) . css ( { opacity : 0 } ) ; $ ( ".btn-alt" , $parent ) . closest ( "div" ) . hide ( ) ; $ ( "img.user-image" , $parent ) . fadeOut ( function ( ) { $ ( ".default-user-image" , $parent ) . animate ( { opacity : 1 } ) ; } ) ; } else { PF . fn . growl . expirable ( PF . fn . _s ( "An error occurred. Please try again later." ) ) ; } } ) ; } ) ; $ ( document ) . on ( "change" , "[data-content=user-avatar-upload-input]" , function ( e ) { e . preventDefault ( ) ; e . stopPropagation ( ) ; var $this = $ ( this ) , $parent = $ ( ".user-settings-avatar" ) , $loading = $ ( ".loading-placeholder" , ".user-settings-avatar" ) , $top = $ ( "#top-bar" ) , user _avatar _file = $ ( this ) [ 0 ] . files [ 0 ] ; if ( $this . data ( "uploading" ) ) { return ; }
if ( /^image\/.*$/ . test ( user _avatar _file . type ) == false ) { PF . fn . growl . call ( PF . fn . _s ( "Please select a valid image file type." ) ) ; return ; }
if ( user _avatar _file . size > CHV . obj . config . user . avatar _max _filesize . getBytes ( ) ) { PF . fn . growl . call ( PF . fn . _s ( "Please select a picture of at most %s size." , CHV . obj . config . user . avatar _max _filesize ) ) ; return ; }
$loading . removeClass ( "hidden" ) ; PF . fn . loading . inline ( $loading , { center : true } ) ; $this . data ( "uploading" , true ) ; var user _avatar _fd = new FormData ( ) ; user _avatar _fd . append ( "source" , user _avatar _file ) ; user _avatar _fd . append ( "action" , "upload" ) ; user _avatar _fd . append ( "type" , "file" ) ; user _avatar _fd . append ( "what" , "avatar" ) ; user _avatar _fd . append ( "owner" , CHV . obj . resource . user . id ) ; user _avatar _fd . append ( "auth_token" , PF . obj . config . auth _token ) ; avatarXHR = new XMLHttpRequest ( ) ; avatarXHR . open ( "POST" , PF . obj . config . json _api , true ) ; avatarXHR . send ( user _avatar _fd ) ; avatarXHR . onreadystatechange = function ( ) { if ( this . readyState == 4 ) { var response = this . responseType !== "json" ? JSON . parse ( this . response ) : this . response , image = response . success . image ; $loading . addClass ( "hidden" ) . empty ( ) ; if ( this . status == 200 ) { change _avatar = function ( parent ) { $ ( "img.user-image" , parent ) . attr ( "src" , image . url ) . removeClass ( "hidden" ) . show ( ) ; } ; hide _default = function ( parent ) { $ ( ".default-user-image" , parent ) . addClass ( "hidden" ) ; } ; hide _default ( $parent ) ; $ ( ".btn-alt" , $parent ) . closest ( "div" ) . show ( ) ; change _avatar ( $parent ) ; if ( CHV . obj . logged _user . id == CHV . obj . resource . user . id ) { change _avatar ( $top ) ; hide _default ( $top ) ; }
PF . fn . growl . expirable ( PF . fn . _s ( "Profile image updated." ) ) ; } else { PF . fn . growl . expirable ( PF . fn . _s ( "An error occurred. Please try again later." ) ) ; }
$this . data ( "uploading" , false ) ; } } } ) ; $ ( document ) . on ( "change" , "[data-content=user-background-upload-input]" , function ( e ) { e . preventDefault ( ) ; e . stopPropagation ( ) ; var $this = $ ( this ) , $parent = $ ( "[data-content=user-background-cover]" ) , $src = $ ( "[data-content=user-background-cover-src]" ) , $loading = $ ( ".loading-placeholder" , $parent ) , $top = $ ( "#top-bar" ) , user _file = $ ( this ) [ 0 ] . files [ 0 ] ; if ( $this . data ( "uploading" ) ) { return ; }
if ( /^image\/.*$/ . test ( user _file . type ) == false ) { PF . fn . growl . call ( PF . fn . _s ( "Please select a valid image file type." ) ) ; return ; }
if ( user _file . size > CHV . obj . config . user . background _max _filesize . getBytes ( ) ) { PF . fn . growl . call ( PF . fn . _s ( "Please select a picture of at most %s size." , CHV . obj . config . user . background _max _filesize ) ) ; return ; }
$loading . removeClass ( "hidden" ) ; PF . fn . loading . inline ( $loading , { center : true , size : 'big' , color : '#FFF' } ) ; $this . data ( "uploading" , true ) ; var user _picture _fd = new FormData ( ) ; user _picture _fd . append ( "source" , user _file ) ; user _picture _fd . append ( "action" , "upload" ) ; user _picture _fd . append ( "type" , "file" ) ; user _picture _fd . append ( "what" , "background" ) ; user _picture _fd . append ( "owner" , CHV . obj . resource . user . id ) ; user _picture _fd . append ( "auth_token" , PF . obj . config . auth _token ) ; avatarXHR = new XMLHttpRequest ( ) ; avatarXHR . open ( "POST" , PF . obj . config . json _api , true ) ; avatarXHR . send ( user _picture _fd ) ; avatarXHR . onreadystatechange = function ( ) { if ( this . readyState == 4 ) { var response = this . responseType !== "json" ? JSON . parse ( this . response ) : this . response , image = response . success . image ; if ( this . status == 200 ) { var $img = $ ( "<img/>" ) ; $img . attr ( 'src' , image . url ) . imagesLoaded ( function ( ) { $loading . addClass ( "hidden" ) . empty ( ) ; $src . css ( "background-image" , "url(" + image . url + ")" ) . hide ( ) . fadeIn ( ) ; $ ( "[data-content=user-change-background]" , $parent ) . removeClass ( "hidden" ) ; $parent . removeClass ( "no-background" ) ; $ ( "[data-content=user-upload-background]" ) . hide ( ) ; $ ( "[data-content=user-change-background]" ) . show ( ) ; PF . fn . growl . expirable ( PF . fn . _s ( "Profile background image updated." ) ) ; $img . remove ( ) ; if ( typeof user _background _full _fix == "function" ) { user _background _full _fix ( ) ; } } ) ; } else { $loading . addClass ( "hidden" ) . empty ( ) ; PF . fn . growl . expirable ( PF . fn . _s ( "An error occurred. Please try again later." ) ) ; }
$this . data ( "uploading" , false ) ; } } } ) ; CHV . fn . user _background = { delete : { submit : function ( ) { PF . obj . modal . form _data = { action : "delete" , delete : "background" , owner : CHV . obj . resource . user . id } ; return true ; } , deferred : { success : { before : function ( XHR ) { $ ( "[data-content=user-background-cover-src]" ) . css ( "background-image" , "none" ) ; $ ( "[data-content=user-background-cover]" ) . addClass ( "no-background" ) . height ( "" ) ; $ ( "[data-content=user-upload-background]" ) . removeClass ( "hidden" ) . show ( ) ; $ ( "[data-content=user-change-background]" ) . hide ( ) ; $ ( "#top-bar" ) . removeClass ( "transparent background-transparent" ) ; $ ( "#top-bar-shade" ) . remove ( ) ; } , done : function ( XHR ) { PF . fn . modal . close ( function ( ) { PF . fn . growl . expirable ( PF . fn . _s ( "Profile background image deleted." ) ) ; } ) ; } } , error : function ( XHR ) { PF . fn . growl . expirable ( PF . fn . _s ( "Error deleting profile background image." ) ) ; } } } } ; CHV . str . mainform = "[data-content=main-form]" ; CHV . obj . timezone = { 'selector' : "[data-content=timezone]" , 'input' : "#timezone-region" } ; $ ( document ) . on ( "keyup change" , CHV . str . mainform + " :input" , function ( ) { if ( $ ( this ) . is ( "[name=username]" ) ) { $ ( "[data-text=username]" ) . text ( $ ( this ) . val ( ) ) ; } } ) ; $ ( document ) . on ( "change" , CHV . obj . timezone . input , function ( ) { var value = $ ( this ) . val ( ) , $timezone _combo = $ ( "#timezone-combo-" + value ) ; $timezone _combo . find ( "option:first" ) . prop ( "selected" , true ) ; $ ( CHV . obj . timezone . selector ) . val ( $timezone _combo . val ( ) ) . change ( ) ; } ) ; $ ( document ) . on ( "change" , "[id^=timezone-combo-]" , function ( ) { var value = $ ( this ) . val ( ) ; $ ( CHV . obj . timezone . selector ) . val ( value ) . change ( ) ; } ) ; $ ( document ) . on ( "keyup change blur" , "[name^=new-password]" , function ( ) { var $new _password = $ ( "[name=new-password]" ) , $new _password _confirm = $ ( "[name=new-password-confirm]" ) , hide = $new _password . val ( ) == $new _password _confirm . val ( ) , $warning = $new _password _confirm . closest ( ".input-password" ) . find ( ".input-warning" ) ; if ( $ ( this ) . is ( $new _password _confirm ) ) { $new _password _confirm . data ( "touched" , true ) ; }
if ( $new _password _confirm . data ( "touched" ) ) { $warning . text ( ! hide ? $warning . data ( "text" ) : "" ) [ ! hide ? 'removeClass' : 'addClass' ] ( 'hidden-visibility' ) ; } } ) ; $ ( document ) . on ( "submit" , CHV . obj . mainform , function ( ) { switch ( $ ( this ) . data ( "type" ) ) { case "password" : var $p1 = $ ( "[name=new-password]" , this ) , $p2 = $ ( "[name=new-password-confirm]" , this ) ; if ( $p1 . val ( ) !== "" || $p2 . val ( ) !== "" ) { if ( $p1 . val ( ) !== $p2 . val ( ) ) { $p1 . highlight ( ) ; $p2 . highlight ( ) ; PF . fn . growl . expirable ( PF . fn . _s ( "Passwords don't match" ) ) ; return false ; } }
break ; } } ) ; $ ( document ) . on ( "change" , "[name=theme_tone]" , function ( ) { $ ( "html" ) [ 0 ] . className = $ ( "html" ) [ 0 ] . className . replace ( /\btone-[\w-]+\b/g , '' ) ; $ ( "html" ) . addClass ( "tone-" + $ ( this ) . val ( ) ) ; } ) ; $ ( document ) . on ( "change" , "[name=theme_top_bar_color]" , function ( ) { $ ( "#top-bar, .top-bar" ) . removeClass ( "black white" ) . addClass ( $ ( this ) . val ( ) ) ; } ) ; $ ( document ) . on ( "click" , "[data-action=check-for-updates]" , function ( ) { PF . fn . loading . fullscreen ( ) ; CHV . fn . system . checkUpdates ( function ( XHR ) { PF . fn . loading . destroy ( "fullscreen" ) ; if ( XHR . status !== 200 ) { PF . fn . growl . call ( PF . fn . _s ( "An error occurred. Please try again later." ) ) ; return ; }
2016-09-03 18:35:50 +00:00
var data = XHR . responseJSON . software ; if ( PF . fn . versionCompare ( CHV . obj . system _info . version , data . current _version ) == - 1 ) { PF . fn . modal . simple ( { title : PF . fn . _s ( "Update available v%s" , data . current _version ) , message : '<p>' + PF . fn . _s ( 'There is an update available for your system. You can automatic download and install this update or go to %s to proceed to download the file.' , '<a href="' + PF . obj . config . github _url + '" target="_blank">GitHub</a>' ) + '<p>' + PF . fn . _s ( 'The release notes for this update are:' ) + '</p>' + '<textarea class="r4 resize-vertical">' + data . release _notes + '</textarea>' + '<div class="btn-container margin-bottom-0"><a href="' + PF . obj . config . base _url + '/update' + '" class="btn btn-input default">' + PF . fn . _s ( 'Update now' ) + '</a> <span class="btn-alt">' + PF . fn . _s ( 'or' ) + ' <a data-action="cancel">' + PF . fn . _s ( 'cancel' ) + '</a></span></div>' , html : true } ) ; } else { PF . fn . growl . call ( PF . fn . _s ( "Your website is running the latest version of Chevereto." ) . replace ( "Chevereto" , "Chevereto Free" ) ) ; } } ) ; } ) ; if ( typeof PF . fn . get _url _var ( "checkUpdates" ) !== typeof undefined ) { $ ( "[data-action=check-for-updates]" ) . click ( ) ; }
2016-08-18 20:39:31 +00:00
if ( $ ( "body#image" ) . exists ( ) && window . scrollY > 0 ) { $ ( "#top-bar" ) . removeClass ( "transparent" ) ; }
$ ( document ) . on ( "click" , "[data-action=toggle-storage-https]" , function ( ) { CHV . fn . storage . toggleHttps ( $ ( this ) . closest ( "[data-content=storage]" ) . data ( 'storage-id' ) ) ; } ) ; $ ( document ) . on ( "click" , "[data-action=toggle-storage-active]" , function ( ) { CHV . fn . storage . toggleActive ( $ ( this ) . closest ( "[data-content=storage]" ) . data ( 'storage-id' ) ) ; } ) ; if ( $ ( CHV . fn . uploader . selectors . root ) . exists ( ) ) { CHV . fn . uploader . $pasteCatcher = $ ( "<div />" , { contenteditable : "true" , id : CHV . fn . uploader . selectors . paste . replace ( /#/ , "" ) } ) ; $ ( "body" ) . append ( CHV . fn . uploader . $pasteCatcher ) ; $ ( document ) . keydown ( function ( e ) { var key = e . keyCode ; var ctrlDown = e . ctrlKey || e . metaKey ; if ( ctrlDown && key == 86 && ! $ ( e . target ) . is ( ":input" ) ) { CHV . fn . uploader . $pasteCatcher . focus ( ) ; } } ) ; window . addEventListener ( "paste" , CHV . fn . uploader . pasteImageHandler ) ; }
$ ( document ) . on ( "click" , "[data-action=like]" , function ( ) { if ( ! PF . fn . is _user _logged ( ) ) { PF . fn . modal . call ( { type : "login" } ) ; return ; }
var $this = $ ( this ) ; if ( $this . data ( "XHR" ) ) return ; $this . data ( "XHR" , true ) ; var $object = $ ( this ) . is ( "[data-liked]" ) ? $ ( this ) : $ ( this ) . closest ( "[data-liked]" ) ; var isSingle = ! $object . closest ( "[data-list]" ) . exists ( ) && typeof CHV . obj . resource !== typeof undefined ; var liked = $object . is ( "[data-liked=1]" ) ; var action = ! liked ? 'like' : 'dislike' ; var content = { id : isSingle ? CHV . obj . resource . id : $ ( this ) . closest ( "[data-id]" ) . data ( "id" ) , type : isSingle ? CHV . obj . resource . type : $ ( this ) . closest ( "[data-type]" ) . data ( "type" ) } ; var ajax = { data : { action : action } , cache : false } ; ajax . data [ action ] = { object : content . type , id : content . id , } ; $ . ajax ( ajax ) . complete ( function ( XHR ) { var response = XHR . responseJSON ; $this . data ( "XHR" , false ) ; if ( response . status _code !== 200 ) { PF . fn . growl . expirable ( PF . fn . _s ( "An error occurred. Please try again later." ) ) ; return ; }
if ( isSingle && typeof response . content !== typeof undefined ) { $ ( "[data-text=likes-count]" ) . html ( response . content . likes ) ; }
$object . attr ( "data-liked" , liked ? 0 : 1 ) ; } ) ; } ) ; $ ( document ) . on ( "click" , "[data-action=follow]" , function ( ) { if ( ! PF . fn . is _user _logged ( ) ) { PF . fn . modal . call ( { type : "login" } ) ; return ; }
var $this = $ ( this ) ; if ( $this . data ( "XHR" ) ) return ; $this . data ( "XHR" , true ) ; var $object = $ ( this ) . is ( "[data-followed]" ) ? $ ( this ) : $ ( this ) . closest ( "[data-followed]" ) ; var isSingle = typeof CHV . obj . resource !== typeof undefined ; var followed = $object . is ( "[data-followed=1]" ) ; var action = ! followed ? 'follow' : 'unfollow' ; var content = { id : isSingle ? CHV . obj . resource . id : $ ( this ) . closest ( "[data-id]" ) . data ( "id" ) , type : isSingle ? CHV . obj . resource . type : $ ( this ) . closest ( "[data-type]" ) . data ( "type" ) } ; var ajax = { data : { action : action } , cache : false } ; ajax . data [ action ] = { object : content . type , id : content . id , } ; $ . ajax ( ajax ) . complete ( function ( XHR ) { var response = XHR . responseJSON ; $this . data ( "XHR" , false ) ; if ( response . status _code !== 200 ) { PF . fn . growl . expirable ( PF . fn . _s ( "An error occurred. Please try again later." ) ) ; return ; }
if ( isSingle ) { if ( typeof response . user _followed !== typeof undefined ) { var $followersLabel = $ ( "[data-text=followers-label]" ) ; var label = { single : $followersLabel . data ( 'label-single' ) , plural : $followersLabel . data ( 'label-plural' ) } ; $ ( "[data-text=followers-count]" ) . html ( response . user _followed . followers ) ; $followersLabel . html ( PF . fn . _n ( label . single , label . plural , response . user _followed . followers ) ) ; } }
$object . attr ( "data-followed" , followed ? 0 : 1 ) ; } ) ; } ) ; function notifications _scroll ( ) { if ( PF . fn . isDevice ( [ "phone" , "phablet" ] ) ) return ; var $visible _list = $ ( ".top-bar-notifications-list ul" , ".top-bar:visible" ) ; var height ; var height _auto ; $visible _list . css ( "height" , "" ) ; height = $visible _list . height ( ) ; $visible _list . data ( "height" , height ) . css ( "height" , "auto" ) ; height _auto = $visible _list . height ( ) ; if ( height _auto > height ) { $visible _list . height ( height ) ; $visible _list . closest ( ".antiscroll-wrap" ) . antiscroll ( ) ; } }
$ ( document ) . on ( "click" , "[data-action=top-bar-notifications]" , function ( e ) { var _this = this ; var $this = $ ( this ) ; var $container = $ ( ".top-bar-notifications-container" , $this ) ; var $list = $ ( ".top-bar-notifications-list" , $this ) ; var $ul = $ ( "ul" , $list ) ; var $loading = $ ( ".loading" , $container ) ; if ( $this . data ( "XHR" ) ) { return ; } else { $loading . removeClass ( "hidden" ) ; PF . fn . loading . inline ( $loading , { size : "small" , message : PF . fn . _s ( "loading" ) } ) ; }
$ . ajax ( { data : { action : "notifications" } , cache : false } ) . complete ( function ( XHR ) { var response = XHR . responseJSON ; if ( response . status _code !== 200 ) { PF . fn . growl . expirable ( PF . fn . _s ( "An error occurred. Please try again later." ) ) ; $this . data ( "XHR" , false ) ; $loading . addClass ( "hidden" ) . html ( "" ) ; return ; }
$this . data ( "XHR" , true ) ; $loading . remove ( ) ; if ( ! response . html ) { $ ( ".empty" , $container ) . removeClass ( "hidden" ) ; return ; }
$list . removeClass ( "hidden" ) ; $ul . html ( response . html ) ; notifications _scroll ( ) ; var $li = $ ( "li.new" , $ul ) ; $li . addClass ( "transition" ) ; setTimeout ( function ( ) { $li . removeClass ( "new" ) ; $ ( "[data-content=notifications-counter]" , _this ) . removeClass ( "on" ) . html ( "0" ) ; setTimeout ( function ( ) { $li . removeClass ( "transition" ) ; } , 150 ) ; } , 1500 ) ; } ) } ) ; if ( $ ( "#g-recaptcha" ) . is ( ':empty' ) && CHV . obj . config . recaptcha . enabled && CHV . obj . config . recaptcha . sitekey ) { reCaptchaCallback = function ( ) { grecaptcha . render ( "g-recaptcha" , { "sitekey" : CHV . obj . config . recaptcha . sitekey } ) ; }
$ . getScript ( "https://www.google.com/recaptcha/api.js?onload=reCaptchaCallback&render=explicit" ) ; }
$ ( document ) . on ( "click" , ".list-item a.image-container" , function ( e ) { var $parent = $ ( this ) . closest ( ".list-item" ) ; var $loadBtn = $parent . find ( "[data-action=load-image]" ) ; if ( $loadBtn . length > 0 ) { loadImageListing ( $loadBtn )
e . preventDefault ( ) ; }
return ; } ) ; $ ( document ) . on ( "click" , ".list-item [data-action=load-image]" , function ( e ) { loadImageListing ( $ ( this ) ) ; e . preventDefault ( ) ; e . stopPropagation ( ) ; return ; } ) ; function loadImageListing ( $this ) { console . log ( "a" )
$this . addClass ( "list-item-play-gif--loading" ) ; var $parent = $this . closest ( ".list-item" ) ; var $imageContainer = $ ( ".image-container" , $parent ) ; console . log ( $imageContainer )
var $image = $ ( "img" , $imageContainer ) ; var md = ".md" ; var imageSrc = $image . attr ( "src" ) ; var mdIndex = imageSrc . lastIndexOf ( md ) ; var loadSrc = imageSrc . substr ( 0 , mdIndex ) + imageSrc . substr ( mdIndex + md . length , imageSrc . length ) ; $imageContainer . append ( $imageContainer . html ( ) ) ; $load = $parent . find ( ".image-container img" ) . eq ( 1 ) . attr ( "src" , loadSrc ) . addClass ( "hidden" ) ; $load . imagesLoaded ( function ( ) { $this . remove ( ) ; $image . remove ( ) ; $ ( this . elements ) . removeClass ( "hidden" ) ; } ) ; } } ) ; if ( typeof CHV == "undefined" ) { CHV = { obj : { } , fn : { } , str : { } } ; }
2016-09-03 18:35:50 +00:00
CHV . obj . image _viewer = { selector : "#image-viewer" , container : "#image-viewer-container" , navigation : ".image-viewer-navigation" , loading : "#image-viewer-loading" , loader : "#image-viewer-loader" , } ; CHV . obj . image _viewer . $container = $ ( CHV . obj . image _viewer . container ) ; CHV . obj . image _viewer . $navigation = $ ( CHV . obj . image _viewer . navigation ) ; CHV . obj . image _viewer . $loading = $ ( CHV . obj . image _viewer . loading ) ; CHV . fn . system = { checkUpdates : function ( callback ) { $ . ajax ( { url : "https://chevereto.com/api/get/info/free/" , data : null , cache : false } ) . always ( function ( data , status , XHR ) { if ( typeof callback == "function" ) { callback ( XHR ) ; } } ) ; } } ; CHV . fn . bindSelectableItems = function ( ) { var el = 'content-listing-wrapper' ; if ( ! $ ( "#" + el ) . exists ( ) ) { $ ( "[data-content=list-selection]" ) . closest ( ".content-width" ) . wrap ( "<div id='" + el + "' />" ) ; }
2016-08-18 20:39:31 +00:00
if ( ! $ ( "[data-content=list-selection]" ) . exists ( ) || PF . fn . isDevice ( [ "phone" , "phablet" ] ) ) { return ; }
$ ( "#content-listing-wrapper" ) . selectable ( { filter : PF . obj . listing . selectors . list _item , cancel : ".content-empty, .header, #tab-share, #tab-full-info, .viewer-title, .header-link, .top-bar, .content-listing-pagination *, #fullscreen-modal, #top-user, #background-cover, .list-item-desc, .list-item-image-tools, [data-action=load-image]" , delay : 5 , selecting : function ( event , ui ) { var $this = $ ( ui . selecting ) ; var unselect = $this . hasClass ( "selected" ) ; CHV . fn . list _editor [ ( unselect ? "unselect" : "select" ) + "Item" ] ( $this ) ; } , unselecting : function ( event , ui ) { CHV . fn . list _editor . unselectItem ( $ ( ui . unselecting ) ) ; } } ) ; } ; CHV . fn . isCachedImage = function ( src ) { var image = new Image ( ) ; image . src = src ; return image . complete || image . width + image . height > 0 ; } ; CHV . fn . viewerImageZoomClass = function ( ) { if ( CHV . obj . image _viewer . $container . hasClass ( "jscursor-zoom-in" ) ) { CHV . obj . image _viewer . $container . addClass ( "cursor-zoom-in" ) . removeClass ( "jscursor-zoom-in" ) ; } } ; CHV . fn . viewerLoadImage = function ( ) { if ( CHV . obj . image _viewer . $loading . exists ( ) ) { CHV . obj . image _viewer . $loading . removeClass ( "soft-hidden" ) . css ( { zIndex : 2 } ) ; PF . fn . loading . inline ( CHV . obj . image _viewer . $loading , { color : "white" , size : "small" , center : true , valign : true } ) ; CHV . obj . image _viewer . $loading . hide ( ) . fadeIn ( "slow" ) ; }
$ ( CHV . obj . image _viewer . loader ) . remove ( ) ; CHV . obj . image _viewer . image . html = CHV . obj . image _viewer . $container . html ( ) ; CHV . obj . image _viewer . $container . prepend ( $ ( CHV . obj . image _viewer . image . html ) . css ( { top : 0 , zIndex : 0 } ) ) ; CHV . obj . image _viewer . $container . find ( "img" ) . eq ( 0 ) . css ( "zIndex" , 1 ) ; CHV . obj . image _viewer . $container . find ( "img" ) . eq ( 1 ) . attr ( "src" , CHV . obj . image _viewer . image . url ) . css ( { width : "100%" , height : "auto" } ) ; CHV . obj . image _viewer . $container . find ( "img" ) . eq ( 1 ) . imagesLoaded ( function ( ) { CHV . obj . image _viewer . $container . find ( "img" ) . eq ( 1 ) . css ( { width : "" , height : "" } ) ; CHV . obj . image _viewer . $container . find ( "img" ) . eq ( 0 ) . remove ( ) ; PF . fn . loading . destroy ( CHV . obj . image _viewer . $loading ) ; } ) ; } ; CHV . obj . embed _tpl = { } ; CHV . obj . topBar = { transparencyScrollToggle : function ( ) { var Y = $ ( window ) . scrollTop ( ) ; $ ( "#top-bar" ) [ ( Y > 0 ? "remove" : "add" ) + "Class" ] ( "transparent" ) ; } } ; CHV . fn . uploader = { options : { image _types : [ "png" , "jpg" , "jpeg" , "gif" , "bmp" ] , max _filesize : "2 MB" } , selectors : { root : "#anywhere-upload" , queue : "#anywhere-upload-queue" , queue _complete : ".queue-complete" , queue _item : ".queue-item" , close _cancel : "[data-button=close-cancel]" , file : "#anywhere-upload-input" , camera : "#anywhere-upload-input-camera" , upload _item _template : "#anywhere-upload-item-template" , item _progress _bar : "[data-content=progress-bar]" , item _progress _percent : "[data-text=progress-percent]" , failed _result : "[data-content=failed-upload-result]" , fullscreen _mask : "#fullscreen-uploader-mask" , dropzone : "#uploader-dropzone" , paste : "#anywhere-upload-paste" , } , is _uploading : false , can _add : true , queue _status : "ready" , files : { } , results : { success : [ ] , error : [ ] } , toggleWorking : 0 , toggle : function ( options , args ) { var $switch = $ ( "[data-action=top-bar-upload]" , ".top-bar" ) ; var show = ! $ ( CHV . fn . uploader . selectors . root ) . data ( "shown" ) ; var options = $ . extend ( { callback : null , reset : true } , options ) ; PF . fn . growl . close ( true ) ; PF . fn . close _pops ( ) ; if ( this . toggleWorking == 1 || $ ( CHV . fn . uploader . selectors . root ) . is ( ":animated" ) || CHV . fn . uploader . is _uploading || ( $switch . data ( 'login-needed' ) && ! PF . fn . is _user _logged ( ) ) ) return ; this . toggleWorking = 1 ; var uploadBoxHeight = $ ( CHV . fn . uploader . selectors . root ) . outerHeight ( ) + "px" ; var uploadBoxTop = $ ( CHV . fn . uploader . selectors . root ) . css ( "top" ) ; var uploadBoxPush = ( parseInt ( uploadBoxHeight ) + parseInt ( uploadBoxTop ) ) + "px" ; var animation = { core : ! show ? ( "-" + uploadBoxPush ) : uploadBoxPush , time : 500 , } , callbacks = function ( ) { if ( options . reset ) { CHV . fn . uploader . reset ( ) ; }
if ( PF . obj . follow _scroll . $node . exists ( ) ) { PF . obj . follow _scroll . $node . removeClass ( "fixed" ) ; PF . obj . follow _scroll . set ( ) ; }
if ( ! show ) { $ ( CHV . fn . uploader . selectors . root ) . css ( { visibility : "hidden" } ) . addClass ( "hidden-visibility" ) ; }
PF . fn . topMenu . hide ( ) ; if ( typeof options . callback == "function" ) { options . callback ( args ) ; }
CHV . fn . uploader . boxSizer ( ) ; CHV . fn . uploader . toggleWorking = 0 ; } ; if ( show ) { $ ( CHV . fn . uploader . selectors . root ) . data ( "initial-height" , uploadBoxHeight ) ; $ ( "html" ) . data ( { "followed-scroll" : $ ( "html" ) . hasClass ( "followed-scroll" ) , "top-bar-box-shadow-prevent" : true } ) . removeClass ( "followed-scroll" ) . addClass ( "top-bar-box-shadow-none" ) ; $ ( "#top-bar" ) . data ( { "stock_classes" : $ ( "#top-bar" ) . attr ( "class" ) } ) ; var top _bar _color = $ ( "#top-bar" ) . hasClass ( "white" ) ? "white" : "black" ; var is _slim _shady = $ ( "#top-bar-shade" ) . exists ( ) ; if ( ! is _slim _shady ) { $ ( "<div/>" , { id : "top-bar-shade" , "class" : "top-bar " + top _bar _color } ) . insertBefore ( "#top-bar" ) ; }
var shade _target _opacity = 1 ; if ( $ ( "body" ) . hasClass ( "landing" ) || $ ( "body" ) . hasClass ( "split_landing" ) ) { shade _target _opacity = 0 ; }
if ( PF . fn . isDevice ( "phone" ) ) { $ ( "#top-bar-shade" ) . css ( { opacity : shade _target _opacity } ) ; } else { $ ( "#top-bar-shade" ) . animate ( { opacity : shade _target _opacity } , animation . time / 2 , animation . easing ) ; }
$ ( ".current[data-nav]" , ".top-bar" ) . each ( function ( ) { if ( $ ( this ) . is ( "[data-action=top-bar-menu-full]" ) ) return ; $ ( this ) . removeClass ( "current" ) . attr ( "data-current" , 1 ) ; } ) ; $ ( CHV . fn . uploader . selectors . root ) . removeClass ( "hidden-visibility" ) . css ( { visibility : "visible" , top : "-" + uploadBoxHeight } ) ; if ( PF . fn . isDevice ( "mobile" ) ) { var $upload _heading = $ ( ".upload-box-heading" , $ ( CHV . fn . uploader . selectors . root ) ) ; $upload _heading . css ( { position : "relative" , top : 0.5 * ( $ ( window ) . height ( ) - $upload _heading . height ( ) ) + "px" } ) ; }
$ ( CHV . fn . uploader . selectors . root ) . css ( { transform : "translate(0," + animation . core + ")" } ) ; CHV . fn . uploader . focus ( function ( ) { setTimeout ( function ( ) { callbacks ( ) ; if ( PF . fn . isDevice ( [ "phone" , "phablet" ] ) ) { $ ( "html" ) . addClass ( "overflow-hidden" ) ; } } , animation . time ) ; } ) ; } else { $ ( "[data-nav][data-current=1]" , ".top-bar" ) . each ( function ( ) { $ ( this ) . addClass ( "current" ) ; } ) ; var fade _slim _shady = function ( ) { if ( PF . fn . isDevice ( "phone" ) ) { $ ( "#top-bar-shade" ) . remove ( ) ; return ; }
$ ( "#top-bar-shade" ) . animate ( { opacity : 0 } , animation . time , animation . easing , function ( ) { if ( ! is _slim _shady ) { $ ( this ) . remove ( ) ; } } ) ; }
if ( ! $ ( "#top-bar" ) . hasClass ( "transparent" ) ) { fade _slim _shady ( ) }
$ ( CHV . fn . uploader . selectors . fullscreen _mask ) . css ( { opacity : 0 } ) ; setTimeout ( function ( ) { $ ( CHV . fn . uploader . selectors . fullscreen _mask ) . remove ( ) ; if ( $ ( "html" ) . data ( "followed-scroll" ) ) { $ ( "html" ) . addClass ( "followed-scroll" ) ; } } , 250 ) ; var _uploadBoxHeight = $ ( CHV . fn . uploader . selectors . root ) . outerHeight ( ) ; var _uploadBoxPush = ( _uploadBoxHeight - parseInt ( $ ( CHV . fn . uploader . selectors . root ) . data ( "initial-height" ) ) ) + "px" ; $ ( CHV . fn . uploader . selectors . root ) . css ( { transform : "translate(0,-" + _uploadBoxPush + ")" } ) ; setTimeout ( function ( ) { $ ( "#top-bar" ) . attr ( "class" , $ ( "#top-bar" ) . data ( "stock_classes" ) ) ; $ ( "html" ) . removeClass ( ( $ ( ".follow-scroll-wrapper.position-fixed" ) . exists ( ) ? "" : "top-bar-box-shadow-none" ) ) ; } , animation . time * 1 / 3 ) ; setTimeout ( function ( ) { $ ( CHV . fn . uploader . selectors . root ) . css ( { top : "" } ) ; if ( $ ( "#top-bar-shade" ) . exists ( ) ) { fade _slim _shady ( ) }
if ( $ ( "body#image" ) . exists ( ) ) { CHV . obj . topBar . transparencyScrollToggle ( ) ; }
callbacks ( ) ; $ ( "html" ) . removeClass ( "overflow-hidden" ) . data ( { "top-bar-box-shadow-prevent" : false } ) ; } , animation . time ) ; }
$ ( CHV . fn . uploader . selectors . root ) . data ( "shown" , show ) ; $switch . toggleClass ( "current" ) . removeClass ( "opened" ) ; } , reset : function ( ) { this . files = { } ; this . is _uploading = false ; this . can _add = true ; this . results = { success : [ ] , error : [ ] } ; this . queue _status = "ready" ; $ ( "li" , this . selectors . queue ) . remove ( ) ; $ ( this . selectors . anywhere ) . height ( "" ) . css ( { "overflow-y" : "" , "overflow-x" : "" } ) ; $ ( this . selectors . queue ) . removeClass ( this . selectors . queue _complete . substring ( 1 ) ) ; $ ( "[data-group=upload-result] textarea" , this . selectors . anywhere ) . prop ( "value" , "" ) ; $ . each ( [ 'upload-queue-ready' , 'uploading' , 'upload-result' , 'upload-queue-ready' , 'upload-queue' ] , function ( i , v ) { $ ( "[data-group=" + v + "]" ) . hide ( ) ; } ) ; $ ( "[data-group=upload]" , this . selectors . anywhere ) . show ( ) ; $ ( "[name=upload-category-id]" , this . selectors . root ) . val ( "" ) ; $ ( "[name=upload-nsfw]" , this . selectors . root ) . prop ( "checked" , this . defaultChecked ) ; $ ( this . selectors . close _cancel , this . selectors . anywhere ) . hide ( ) . each ( function ( ) { if ( $ ( this ) . data ( "action" ) == "close-upload" ) $ ( this ) . show ( ) ; } ) ; this . boxSizer ( true ) ; } , focus : function ( callback ) { if ( $ ( this . selectors . fullscreen _mask ) . exists ( ) ) return ; $ ( "body" ) . append ( $ ( "<div/>" , { id : ( this . selectors . fullscreen _mask . replace ( "#" , "" ) ) , class : "fullscreen soft-black" , } ) . css ( { top : PF . fn . isDevice ( "phone" ) ? 0 : $ ( CHV . fn . uploader . selectors . root ) . data ( "top" ) } ) ) ; setTimeout ( function ( ) { $ ( CHV . fn . uploader . selectors . fullscreen _mask ) . css ( { opacity : 1 } )
setTimeout ( function ( ) { if ( typeof callback == "function" ) { callback ( ) ; } } , PF . fn . isDevice ( [ "phone" , "phablet" ] ) ? 0 : 250 ) ; } , 1 ) ; } , boxSizer : function ( forced ) { if ( $ ( this . selectors . root ) . css ( "visibility" ) == "visible" ) { $ ( "html" ) [ ( PF . fn . isDevice ( [ "phone" , "phablet" ] ) ? "add" : "remove" ) + "Class" ] ( "overflow-hidden" ) ; }
var doit = $ ( this . selectors . root ) . css ( "visibility" ) == "visible" || forced ; if ( ! doit ) return ; $ ( this . selectors . root ) . height ( "" ) ; if ( $ ( this . selectors . root ) . height ( ) + $ ( "#top-bar" ) . outerHeight ( true ) > $ ( window ) . height ( ) ) { $ ( this . selectors . root ) . height ( $ ( window ) . height ( ) - $ ( "#top-bar" ) . outerHeight ( true ) ) . css ( { "overflow-y" : "scroll" , "overflow-x" : "auto" } ) ; $ ( "body" ) . addClass ( "overflow-hidden" ) ; } else { $ ( this . selectors . root ) . css ( "overflow-y" , "" ) ; $ ( "body" ) . removeClass ( "overflow-hidden" ) ; } } , pasteURL : function ( ) { var urlvalues = $ ( "[name=urls]" , "#fullscreen-modal" ) . val ( ) ; if ( urlvalues ) { CHV . fn . uploader . add ( { } , urlvalues ) ; } } , pasteImageHandler : function ( e ) { if ( $ ( e . target ) . is ( ":input" ) ) { return ; }
if ( typeof e . clipboardData !== typeof undefined && e . clipboardData . items ) { var items = e . clipboardData . items ; } else { setTimeout ( function ( ) { e . clipboardData = { } ; e . clipboardData . items = [ ] ; $ . each ( $ ( "img" , CHV . fn . uploader . $pasteCatcher ) , function ( i , v ) { e . clipboardData . items . push ( PF . fn . dataURItoBlob ( $ ( this ) . attr ( "src" ) ) ) ; } ) ; $ ( CHV . fn . uploader . selectors . paste ) . html ( "" ) ; return CHV . fn . uploader . pasteImageHandler ( e ) ; } , 1 ) ; }
if ( items ) { for ( var i = 0 ; i < items . length ; i ++ ) { if ( items [ i ] . type . indexOf ( "image" ) !== - 1 ) { var file = items [ i ] instanceof Blob ? items [ i ] : items [ i ] . getAsFile ( ) ; var reader = new FileReader ( ) ; reader . onload = function ( evt ) { var uploaderIsVisible = $ ( CHV . fn . uploader . selectors . root ) . data ( "shown" ) ; file . name = PF . fn . _s ( 'Clipboard image' ) + ' ' + PF . fn . getDateTime ( ) ; var file _evt = { originalEvent : { dataTransfer : { files : [ file ] } , preventDefault : function ( ) { } , stopPropagation : function ( ) { } , clipboard : true , dataURL : evt . target . result , name : file . name } } ; if ( ! uploaderIsVisible ) { CHV . fn . uploader . toggle ( { callback : function ( ) { CHV . fn . uploader . add ( file _evt ) ; } } ) ; } else { CHV . fn . uploader . add ( file _evt ) ; } } ; reader . readAsDataURL ( file ) ; } } } } , item _add _id : 0 , clipboardImages : [ ] , add : function ( e , urls ) { var md5 ; if ( typeof CHV . obj . config !== "undefined" && typeof CHV . obj . config . image !== "undefined" && CHV . obj . config . image . max _filesize !== "undefined" ) { this . options . max _filesize = CHV . obj . config . image . max _filesize ; }
if ( ! this . can _add ) { var e = e . originalEvent ; e . preventDefault ( ) ; e . stopPropagation ( ) ; return false ; } ; $fileinput = $ ( this . selectors . file ) ; $fileinput . replaceWith ( $fileinput = $fileinput . clone ( true ) ) ; var item _queue _template = $ ( this . selectors . upload _item _template ) . html ( ) ; var files = [ ] ; if ( typeof urls == typeof undefined ) { var e = e . originalEvent ; e . preventDefault ( ) ; e . stopPropagation ( ) ; files = e . dataTransfer || e . target ; files = $ . makeArray ( files . files ) ; if ( e . clipboard ) { md5 = PF . fn . md5 ( e . dataURL ) ; if ( $ . inArray ( md5 , this . clipboardImages ) != - 1 ) { return null ; }
this . clipboardImages . push ( md5 ) ; }
var failed _files = [ ] ; for ( var i = 0 ; i < files . length ; i ++ ) { var file = files [ i ] ; var image _type _str ; if ( typeof file . type == "undefined" || file . type == "" ) { image _type _str = file . name . substr ( file . name . lastIndexOf ( '.' ) + 1 ) . toLowerCase ( ) ; } else { image _type _str = file . type . replace ( "image/" , "" ) ; }
if ( file . size > CHV . obj . config . image . max _filesize . getBytes ( ) ) { failed _files . push ( { uid : i , name : file . name . truncate _middle ( ) + " - " + PF . fn . _s ( "File too big." ) } ) ; continue ; }
if ( CHV . fn . uploader . options . image _types . indexOf ( image _type _str ) == - 1 && /android/i . test ( navigator . userAgent ) == false ) { failed _files . push ( { uid : i , name : file . name . truncate _middle ( ) + " - " + PF . fn . _s ( "Invalid or unsupported file format." ) } ) ; continue ; }
if ( md5 ) { file . md5 = md5 ; }
file . fromClipboard = e . clipboard == true ; file . uid = i ; }
for ( var i = 0 ; i < failed _files . length ; i ++ ) { var failed _file = failed _files [ i ] ; files . splice ( failed _file . id , 1 ) }
if ( failed _files . length > 0 && files . length == 0 ) { var failed _message = '' ; for ( var i = 0 ; i < failed _files . length ; i ++ ) { failed _message += "<li>" + failed _files [ i ] . name + "</li>" ; }
PF . fn . modal . simple ( { title : PF . fn . _s ( "Some files couldn't be added" ) , message : "<ul>" + "<li>" + failed _message + "</ul>" } ) ; return ; }
if ( files . length == 0 ) { return ; } } else { files = urls . match _urls ( ) ; if ( ! files ) return ; files = files . array _unique ( ) ; files = $ . map ( files , function ( file , i ) { return { uid : i , name : file , url : file } ; } ) ; }
if ( $ . isEmptyObject ( this . files ) ) { for ( var i = 0 ; i < files . length ; i ++ ) { this . files [ files [ i ] . uid ] = files [ i ] ; this . item _add _id ++ ; } } else { var currentfiles = [ ] ; for ( var key in this . files ) { if ( typeof this . files [ key ] == "undefined" || typeof this . files [ key ] == "function" ) continue ; currentfiles . push ( encodeURI ( this . files [ key ] . name ) ) ; }
files = $ . map ( files , function ( file , i ) { if ( $ . inArray ( encodeURI ( file . name ) , currentfiles ) != - 1 ) { return null ; }
file . uid = CHV . fn . uploader . item _add _id + i ; CHV . fn . uploader . item _add _id ++ ; return file ; } ) ; for ( var i = 0 ; i < files . length ; i ++ ) { this . files [ files [ i ] . uid ] = files [ i ] ; } }
$ ( this . selectors . queue , this . selectors . root ) . append ( item _queue _template . repeat ( files . length ) ) ; $ ( this . selectors . queue + " " + this . selectors . queue _item + ":not([data-id])" , this . selectors . root ) . hide ( ) ; $ ( this . selectors . close _cancel , this . selectors . root ) . hide ( ) . each ( function ( ) { if ( $ ( this ) . data ( "action" ) == "close-upload" ) $ ( this ) . show ( ) ; } ) ; var failed _before = failed _files , failed _files = [ ] , j = 0 , default _options = { canvas : true , } ; function CHVLoadImage ( i ) { if ( typeof i == typeof undefined ) { var i = 0 ; }
if ( ! ( i in files ) ) { return ; }
var file = files [ i ] ; $ ( CHV . fn . uploader . selectors . queue _item + ":not([data-id]) .load-url" , CHV . fn . uploader . selectors . queue ) [ typeof file . url !== "undefined" ? "show" : "remove" ] ( ) ; loadImage . parseMetaData ( file . url ? file . url : file , function ( data ) { $ ( CHV . fn . uploader . selectors . queue _item + ":not([data-id]) .preview:empty" , CHV . fn . uploader . selectors . queue ) . first ( ) . closest ( "li" ) . attr ( "data-id" , file . uid ) ; loadImage ( file . url ? file . url : file , function ( img ) { ++ j ; var $queue _item = $ ( CHV . fn . uploader . selectors . queue _item + "[data-id=" + ( file . uid ) + "]" , CHV . fn . uploader . selectors . queue ) ; if ( img . type === "error" ) { failed _files . push ( { id : file . uid , name : file . name . truncate _middle ( ) } ) ; } else { if ( ! $ ( "[data-group=upload-queue]" , CHV . fn . uploader . selectors . root ) . is ( ":visible" ) ) { $ ( "[data-group=upload-queue]" , CHV . fn . uploader . selectors . root ) . css ( "display" , "block" ) ; }
var mimetype = "image/jpeg" ; if ( typeof data . buffer !== typeof undefined ) { var buffer = ( new Uint8Array ( data . buffer ) ) . subarray ( 0 , 4 ) ; var header = "" ; for ( var i = 0 ; i < buffer . length ; i ++ ) { header += buffer [ i ] . toString ( 16 ) ; }
var header _to _mime = { '89504e47' : 'image/png' , '47494638' : 'image/gif' , 'ffd8ffe0' : 'image/jpeg' , }
$ . each ( [ 'ffd8ffe1' , 'ffd8ffe2' ] , function ( i , v ) { header _to _mime [ v ] = header _to _mime [ 'ffd8ffe0' ] ; } ) ; if ( typeof header _to _mime [ header ] !== typeof undefined ) { mimetype = header _to _mime [ header ] ; } }
var title = null ; if ( typeof file . name !== typeof undefined ) { var basename = PF . fn . baseName ( file . name ) ; title = $ . trim ( basename . substring ( 0 , 100 ) . capitalizeFirstLetter ( ) ) ; }
CHV . fn . uploader . files [ file . uid ] . parsedMeta = { title : title , width : img . width , height : img . height , canvas : img , mimetype : mimetype , } ; var img = loadImage . scale ( img , { maxWidth : 600 } ) ; $queue _item . show ( ) ; $ ( "[data-group=upload-queue-ready]" , CHV . fn . uploader . selectors . root ) . show ( ) ; $ ( "[data-group=upload]" , CHV . fn . uploader . selectors . root ) . hide ( ) ; $queue _item . find ( ".load-url" ) . remove ( ) ; $queue _item . find ( ".preview" ) . removeClass ( "soft-hidden" ) . show ( ) . append ( img ) ; $img = $queue _item . find ( ".preview" ) . find ( "img,canvas" ) ; $img . attr ( "class" , "canvas" ) ; queue _item _h = $queue _item . height ( ) ; queue _item _w = $queue _item . width ( ) ; var img _w = parseInt ( $img . attr ( "width" ) ) || $img . width ( ) ; var img _h = parseInt ( $img . attr ( "height" ) ) || $img . height ( ) ; var img _r = img _w / img _h ; $img . hide ( ) ; if ( img _w > img _h || img _w == img _h ) { var queue _img _h = img _h < queue _item _h ? img _h : queue _item _h ; if ( img _w > img _h ) { $img . height ( queue _img _h ) . width ( queue _img _h * img _r ) ; } }
if ( img _w < img _h || img _w == img _h ) { var queue _img _w = img _w < queue _item _w ? img _w : queue _item _w ; if ( img _w < img _h ) { $img . width ( queue _img _w ) . height ( queue _img _w / img _r ) ; } }
if ( img _w == img _h ) { $img . height ( queue _img _h ) . width ( queue _img _w ) ; }
$img . css ( { marginTop : - $img . height ( ) / 2 , marginLeft : - $img . width ( ) / 2 } ) . show ( ) ; CHV . fn . uploader . boxSizer ( ) ; }
if ( j == files . length ) { if ( typeof failed _before !== "undefined" ) { failed _files = failed _files . concat ( failed _before ) ; }
PF . fn . loading . destroy ( "fullscreen" ) ; if ( failed _files . length > 0 ) { var failed _message = "" ; for ( var i = 0 ; i < failed _files . length ; i ++ ) { failed _message += "<li>" + failed _files [ i ] . name + "</li>" ; delete CHV . fn . uploader . files [ failed _files [ i ] . uid ] ; $ ( "li[data-id=" + failed _files [ i ] . uid + "]" , CHV . fn . uploader . selectors . queue ) . find ( "[data-action=cancel]" ) . click ( ) }
PF . fn . modal . simple ( { title : PF . fn . _s ( "Some files couldn't be added" ) , message : '<ul>' + failed _message + '</ul>' } ) ; } else { CHV . fn . uploader . focus ( ) ; }
CHV . fn . uploader . boxSizer ( ) ; } } , $ . extend ( { } , default _options , { orientation : data . exif ? data . exif . get ( "Orientation" ) : 1 } ) ) ; setTimeout ( function ( ) { CHVLoadImage ( i + 1 ) ; } , 25 ) ; } ) ; }
PF . fn . loading . fullscreen ( ) ; CHVLoadImage ( ) ; } , queueSize : function ( ) { $ ( "[data-text=queue-objects]" , this . selectors . root ) . text ( PF . fn . _n ( "image" , "images" , Object . size ( this . files ) ) ) ; $ ( "[data-text=queue-size]" , this . selectors . root ) . text ( Object . size ( this . files ) ) ; } , queueProgress : function ( e ) { var total _queue _items _done = $ ( "> .completed, > .failed" , this . selectors . queue ) . length , total _queue _items = $ ( this . selectors . queue ) . children ( ) . length , total _queueProgress = parseInt ( 100 * ( parseFloat ( total _queue _items _done / total _queue _items ) + parseFloat ( ( e . loaded / e . total ) / total _queue _items ) ) ) ; $ ( "[data-text=queue-progress]" , this . selectors . root ) . text ( total _queueProgress ) ; } , upload : function ( $queue _item ) { var id = $queue _item . data ( "id" ) , f = this . files [ id ] , queue _is _url = typeof f . url !== "undefined" ; var source = queue _is _url ? f . url : f ; var hasForm = typeof f . formValues !== typeof undefined ; if ( typeof f == "undefined" ) { if ( $queue _item . next ( ) . exists ( ) ) { this . upload ( $queue _item . next ( ) ) ; }
return ; }
$ ( this . selectors . close _cancel , this . selectors . root ) . hide ( ) . each ( function ( ) { if ( $ ( this ) . data ( "action" ) == "cancel-upload" ) $ ( this ) . show ( ) ; } ) ; this . is _uploading = true ; if ( ! queue _is _url && f . parsedMeta . mimetype !== "image/gif" && typeof f . formValues !== typeof undefined && f . formValues . width != f . parsedMeta . width ) { isBlob = true ; var canvas = $ ( "<canvas />" ) [ 0 ] ; canvas . width = f . formValues . width ; canvas . height = f . formValues . height ; var ctx = canvas . getContext ( "2d" ) ; ctx . drawImage ( f . parsedMeta . canvas , 0 , 0 , canvas . width , canvas . height ) ; source = PF . fn . dataURItoBlob ( canvas . toDataURL ( f . parsedMeta . mimetype ) ) ; } ; var form = new FormData ( ) ; var formData = { source : null , type : queue _is _url ? "url" : "file" , action : "upload" , privacy : $ ( "[data-privacy]" , this . selectors . root ) . first ( ) . data ( "privacy" ) , timestamp : this . timestamp , auth _token : PF . obj . config . auth _token , category _id : $ ( "[name=upload-category-id]" , this . selectors . root ) . val ( ) || null , nsfw : $ ( "[name=upload-nsfw]" , this . selectors . root ) . prop ( "checked" ) ? 1 : 0 } ; if ( queue _is _url ) { formData . source = source ; } else { form . append ( "source" , source , f . name ) ; }
if ( hasForm ) { $ . each ( f . formValues , function ( i , v ) { formData [ i . replace ( /image_/g , "" ) ] = v ; } ) ; } ; $ . each ( formData , function ( i , v ) { form . append ( i , v ) ; } ) ; this . files [ id ] . xhr = new XMLHttpRequest ( ) ; $queue _item . removeClass ( "waiting" ) ; if ( ! queue _is _url ) { this . files [ id ] . xhr . upload . onprogress = function ( e ) { if ( e . lengthComputable ) { CHV . fn . uploader . queueProgress ( e ) ; percentComplete = parseInt ( ( e . loaded / e . total ) * 100 ) ; $ ( CHV . fn . uploader . selectors . item _progress _percent , $queue _item ) . text ( percentComplete ) ; $ ( CHV . fn . uploader . selectors . item _progress _bar , $queue _item ) . width ( 100 - percentComplete + "%" ) ; if ( percentComplete == 100 ) { $ ( CHV . fn . uploader . selectors . item _progress _percent , $queue _item ) . text ( "" ) ; CHV . fn . uploader . itemLoading ( $queue _item ) ; } } } } else { this . queueSize ( ) ; this . queueProgress ( { loaded : 1 , total : 1 } ) ; this . itemLoading ( $queue _item ) ; }
this . files [ id ] . xhr . onreadystatechange = function ( ) { var is _error = false ; if ( this . readyState == 4 && typeof CHV . fn . uploader . files [ id ] . xhr !== "undefined" && CHV . fn . uploader . files [ id ] . xhr . status !== 0 ) { $ ( ".loading-indicator" , $queue _item ) . remove ( ) ; $queue _item . removeClass ( "waiting uploading" ) ; try { var JSONresponse = this . responseType !== "json" ? JSON . parse ( this . response ) : this . response ; if ( typeof JSONresponse !== "undefined" && this . status == 200 ) { $ ( "[data-group=image-link]" , $queue _item ) . attr ( "href" , JSONresponse . image . url _viewer ) ; } else { if ( JSONresponse . error . context == "PDOException" ) { JSONresponse . error . message = "Database error" ; }
JSONresponse . error . message = CHV . fn . uploader . files [ id ] . name . truncate _middle ( ) + " - " + JSONresponse . error . message ; }
CHV . fn . uploader . results [ this . status == 200 ? "success" : "error" ] . push ( JSONresponse ) ; if ( this . status !== 200 ) is _error = true ; } catch ( err ) { is _error = true ; var err _handle ; if ( typeof JSONresponse == "undefined" ) { err _handle = { status : 500 , statusText : "Internal server error" } } else { err _handle = { status : 400 , statusText : JSONresponse . error . message } }
JSONresponse = { status _code : err _handle . status , error : { message : CHV . fn . uploader . files [ id ] . name . truncate _middle ( ) + " - Server error (" + err _handle . statusText + ")" , code : err _handle . status , context : "XMLHttpRequest" } , status _txt : err _handle . statusText } ; CHV . fn . uploader . results . error . push ( JSONresponse ) ; console . log ( "server error" , JSONresponse ) ; }
$queue _item . addClass ( ! is _error ? "completed" : "failed" ) ; if ( typeof JSONresponse . error !== "undefined" && typeof JSONresponse . error . message !== "undefined" ) { $queue _item . attr ( "rel" , "tooltip" ) . data ( "tiptip" , "top" ) . attr ( "title" , JSONresponse . error . message ) ; PF . fn . bindtipTip ( $queue _item ) ; }
if ( $queue _item . next ( ) . exists ( ) ) { CHV . fn . uploader . upload ( $queue _item . next ( ) ) ; $ ( CHV . fn . uploader . selectors . close _cancel , CHV . fn . uploader . selectors . root ) . hide ( ) . each ( function ( ) { if ( $ ( this ) . data ( "action" ) == "cancel-upload-remaining" ) $ ( this ) . show ( ) ; } ) ; } else { CHV . fn . uploader . is _uploading = false ; CHV . fn . uploader . displayResults ( ) ; }
$ ( ".done" , $queue _item ) . fadeOut ( ) ; } } ; this . files [ id ] . xhr . open ( "POST" , PF . obj . config . json _api , true ) ; this . files [ id ] . xhr . setRequestHeader ( "Accept" , "application/json" ) ; this . files [ id ] . xhr . send ( form ) ; } , itemLoading : function ( $queue _item ) { PF . fn . loading . inline ( $ ( ".progress" , $queue _item ) , { color : "#FFF" , size : "normal" , center : true , position : "absolute" , shadow : true } ) ; $ ( "[data-action=cancel], [data-action=edit]" , $queue _item ) . hide ( ) ; } , displayResults : function ( ) { var group _result = "[data-group=upload-result][data-result=%RESULT%]" , result _types = [ "error" , "mixed" , "success" ] , results = { } ; for ( var i = 0 ; i < result _types . length ; i ++ ) { results [ result _types [ i ] ] = group _result . replace ( "%RESULT%" , result _types [ i ] ) ; }
if ( this . results . error . length > 0 ) { var error _files = [ ] ; for ( var i = 0 ; i < this . results . error . length ; i ++ ) { error _files . push ( this . results . error [ i ] . error . message ) ; }
if ( Object . size ( error _files ) > 0 ) { $ ( this . selectors . failed _result ) . html ( "<li>" + error _files . join ( "</li><li>" ) + "</li>" ) ; } } else { $ ( results . error , this . selectors . root ) . hide ( ) ; }
if ( CHV . obj . config . upload . redirect _single _upload && this . results . success . length == 1 && this . results . error . length == 0 ) { window . location . href = this . results . success [ 0 ] . image . url _viewer ; return false ; }
$ ( "[data-text=queue-progress]" , this . selectors . root ) . text ( 100 ) ; $ ( "[data-group=uploading]" , this . selectors . root ) . hide ( ) ; $ ( this . selectors . close _cancel , this . selectors . root ) . hide ( ) . each ( function ( ) { if ( $ ( this ) . data ( "action" ) == "close-upload" ) $ ( this ) . show ( ) ; } ) ; $ ( this . selectors . queue ) . addClass ( this . selectors . queue _complete . substring ( 1 ) ) ; if ( this . results . success . length > 0 && $ ( "[data-group=upload-result] textarea" , this . selectors . root ) . exists ( ) ) { CHV . fn . fillEmbedCodes ( this . results . success , CHV . fn . uploader . selectors . root , "val" ) ; }
if ( this . results . success . length > 0 && this . results . error . length > 0 ) { $ ( results . mixed + ", " + results . success , this . selectors . root ) . show ( ) ; } else if ( this . results . success . length > 0 ) { $ ( results . success , this . selectors . root ) . show ( ) ; } else if ( this . results . error . length > 0 ) { $ ( results . error , this . selectors . root ) . show ( ) ; }
if ( $ ( results . success , this . selectors . root ) . is ( ":visible" ) ) { $ ( results . success , this . selectors . root ) . find ( "[data-group=user], [data-group=guest]" ) . hide ( ) ; $ ( results . success , this . selectors . root ) . find ( "[data-group=" + ( PF . fn . is _user _logged ( ) ? "user" : "guest" ) + "]" ) . show ( ) ; if ( typeof this . results . success [ 0 ] . image . album !== "undefined" ) { $ ( "[data-text=upload-target]" ) . text ( this . results . success [ 0 ] . image . album . name ) ; $ ( "[data-link=upload-target]" ) . attr ( "href" , this . results . success [ 0 ] . image . album . url ) ; } }
this . boxSizer ( ) ; this . queue _status = "done" ; } } ; CHV . fn . fillEmbedCodes = function ( elements , parent , fn ) { if ( typeof fn == "undefined" ) { fn = "val" ; }
$ . each ( elements , function ( key , value ) { var image = value . image ; if ( ! image . medium ) { image . medium = { } ; var imageProp = [ "filename" , "name" , "width" , "height" , "extension" , "size" , "size_formatted" , "url" ] ; for ( var i = 0 ; i < imageProp . length ; i ++ ) { image . medium [ imageProp [ i ] ] = image [ imageProp [ i ] ] ; } }
var flatten _image = Object . flatten ( image ) ; $ . each ( CHV . obj . embed _tpl , function ( key , value ) { $ . each ( value . options , function ( k , v ) { var embed = v , $embed = $ ( "textarea[name=" + k + "]" , parent ) , template = embed . template ; for ( var i in flatten _image ) { if ( ! flatten _image . hasOwnProperty ( i ) ) { continue ; }
template = template . replace ( new RegExp ( "%" + i . toUpperCase ( ) + "%" , "g" ) , flatten _image [ i ] ) ; }
$embed [ fn ] ( $embed . val ( ) + template + ( $embed . data ( "size" ) == "thumb" ? " " : "\n" ) ) ; } ) ; } ) ; } ) ; $ . each ( CHV . obj . embed _tpl , function ( key , value ) { $ . each ( value . options , function ( k , v ) { var $embed = $ ( "textarea[name=" + k + "]" , parent ) ; $embed [ fn ] ( $ . trim ( $embed . val ( ) ) ) ; } ) ; } ) ; } ; CHV . fn . resource _privacy _toggle = function ( privacy ) { if ( ! privacy ) privacy = "public" ; $ ( "[data-content=privacy-private]" ) . hide ( ) ; if ( privacy !== "public" ) { $ ( "[data-content=privacy-private]" ) . show ( ) ; } } ; CHV . fn . submit _upload _edit = function ( ) { var $modal = $ ( PF . obj . modal . selectors . root ) , new _album = false ; if ( $ ( "[data-content=form-new-album]" , $modal ) . is ( ":visible" ) && $ ( "[name=form-album-name]" , $modal ) . val ( ) == "" ) { PF . fn . growl . call ( PF . fn . _s ( "You must enter the album name." ) ) ; $ ( "[name=form-album-name]" , $modal ) . highlight ( ) ; return false ; }
if ( $ ( "[data-content=form-new-album]" , $modal ) . is ( ":visible" ) ) { new _album = true ; }
PF . obj . modal . form _data = { action : new _album ? "create-album" : "move" , type : "images" , album : { ids : $ . map ( CHV . fn . uploader . results . success , function ( v ) { return v . image . id _encoded ; } ) , new : new _album } } ; if ( new _album ) { PF . obj . modal . form _data . album . name = $ ( "[name=form-album-name]" , $modal ) . val ( ) ; PF . obj . modal . form _data . album . description = $ ( "[name=form-album-description]" , $modal ) . val ( ) ; PF . obj . modal . form _data . album . privacy = $ ( "[name=form-privacy]" , $modal ) . val ( ) ; if ( PF . obj . modal . form _data . album . privacy == "password" ) { PF . obj . modal . form _data . album . password = $ ( "[name=form-album-password]" , $modal ) . val ( ) ; } } else { PF . obj . modal . form _data . album . id = $ ( "[name=form-album-id]" , $modal ) . val ( ) ; }
return true ; } ; CHV . fn . complete _upload _edit = { success : function ( XHR ) { var response = XHR . responseJSON . album ; window . location = response . url ; } , error : function ( XHR ) { var response = XHR . responseJSON ; PF . fn . growl . call ( PF . fn . _s ( response . error . message ) ) ; } } ; CHV . fn . before _image _edit = function ( ) { var $modal = $ ( "[data-ajax-deferred='CHV.fn.complete_image_edit']" ) ; $ ( "[data-content=form-new-album]" , $modal ) . hide ( ) ; $ ( "#move-existing-album" , $modal ) . show ( ) ; } ; CHV . fn . submit _image _edit = function ( ) { var $modal = $ ( PF . obj . modal . selectors . root ) , new _album = false ; if ( $ ( "[data-content=form-new-album]" , $modal ) . is ( ":visible" ) && $ ( "[name=form-album-name]" , $modal ) . val ( ) == "" ) { PF . fn . growl . call ( PF . fn . _s ( "You must enter the album name." ) ) ; $ ( "[name=form-album-name]" , $modal ) . highlight ( ) ; return false ; }
if ( $ ( "[data-content=form-new-album]" , $modal ) . is ( ":visible" ) ) { new _album = true ; }
PF . obj . modal . form _data = { action : "edit" , edit : "image" , editing : { id : CHV . obj . resource . id , category _id : $ ( "[name=form-category-id]" , $modal ) . val ( ) || null , title : $ ( "[name=form-image-title]" , $modal ) . val ( ) || null , description : $ ( "[name=form-image-description]" , $modal ) . val ( ) || null , nsfw : $ ( "[name=form-nsfw]" , $modal ) . prop ( "checked" ) ? 1 : 0 , new _album : new _album } } ; if ( new _album ) { PF . obj . modal . form _data . editing . album _privacy = $ ( "[name=form-privacy]" , $modal ) . val ( ) ; if ( PF . obj . modal . form _data . editing . album _privacy == "password" ) { PF . obj . modal . form _data . editing . album _password = $ ( "[name=form-album-password]" , $modal ) . val ( ) ; }
PF . obj . modal . form _data . editing . album _name = $ ( "[name=form-album-name]" , $modal ) . val ( ) ; PF . obj . modal . form _data . editing . album _description = $ ( "[name=form-album-description]" , $modal ) . val ( ) ; } else { PF . obj . modal . form _data . editing . album _id = $ ( "[name=form-album-id]" , $modal ) . val ( ) ; }
return true ; } ; CHV . fn . complete _image _edit = { success : function ( XHR ) { var response = XHR . responseJSON . image ; if ( ! response . album . id _encoded ) response . album . id _encoded = "" ; if ( CHV . obj . image _viewer . album . id _encoded !== response . album . id _encoded ) { CHV . obj . image _viewer . album . id _encoded = response . album . id _encoded ; var slice = { html : response . album . slice && response . album . slice . html ? response . album . slice . html : null , prev : response . album . slice && response . album . slice . prev ? response . album . slice . prev : null , next : response . album . slice && response . album . slice . next ? response . album . slice . next : null } ; $ ( "[data-content=album-slice]" ) . html ( slice . html ) ; $ ( "[data-content=album-panel-title]" ) [ slice . html ? "show" : "hide" ] ( ) ; $ ( "a[data-action=prev]" ) . attr ( "href" , slice . prev ) ; $ ( "a[data-action=next]" ) . attr ( "href" , slice . next ) ; $ ( "a[data-action]" , ".image-viewer-navigation" ) . each ( function ( ) { $ ( this ) [ typeof $ ( this ) . attr ( "href" ) == "undefined" ? "addClass" : "removeClass" ] ( "hidden" ) ; } ) ; }
CHV . fn . resource _privacy _toggle ( response . album . privacy ) ; $ . each ( [ "description" , "title" ] , function ( i , v ) { var $obj = $ ( "[data-text=image-" + v + "]" ) ; $obj . html ( PF . fn . nl2br ( PF . fn . htmlEncode ( response [ v ] ) ) ) ; if ( $obj . html ( ) !== "" ) { $obj . show ( ) ; } } ) ; CHV . fn . common . updateDoctitle ( response . title ) ; PF . fn . growl . expirable ( PF . fn . _s ( "Image edited successfully." ) ) ; CHV . fn . list _editor . addAlbumtoModals ( response . album ) ; var $modal = $ ( "[data-submit-fn='CHV.fn.submit_image_edit']" ) ; $ . each ( [ "description" , "name" , "password" ] , function ( i , v ) { var $input = $ ( "[name=form-album-" + v + "]" , $modal ) ; if ( $input . is ( "textarea" ) ) { $input . val ( "" ) . html ( "" ) ; } else { $input . val ( "" ) . attr ( "value" , "" ) ; } } ) ; $ ( "[name=form-privacy] option" , $modal ) . each ( function ( ) { $ ( this ) . removeAttr ( "selected" ) ; } ) ; $ ( "[data-combo-value=password]" , $modal ) . hide ( ) ; $ ( "[name=form-album-id]" , $modal ) . find ( "option" ) . removeAttr ( "selected" ) ; $ ( "[name=form-album-id]" , $modal ) . find ( "[value=" + response . album . id _encoded + "]" ) . attr ( "selected" , true ) ; } } ; CHV . fn . before _album _edit = function ( e ) { var modal _source = "[data-before-fn='CHV.fn.before_album_edit']" ; $ ( "[data-action=album-switch]" , modal _source ) . remove ( ) ; } ; CHV . fn . submit _album _edit = function ( ) { var $modal = $ ( PF . obj . modal . selectors . root ) ; if ( ! $ ( "[name=form-album-name]" , $modal ) . val ( ) ) { PF . fn . growl . call ( PF . fn . _s ( "You must enter the album name." ) ) ; $ ( "[name=form-album-name]" , $modal ) . highlight ( ) ; return false ; }
PF . obj . modal . form _data = { action : "edit" , edit : "album" , editing : { id : CHV . obj . resource . id , name : $ ( "[name=form-album-name]" , $modal ) . val ( ) , privacy : $ ( "[name=form-privacy]" , $modal ) . val ( ) , description : $ ( "[name=form-album-description]" , $modal ) . val ( ) } } ; if ( PF . obj . modal . form _data . editing . privacy == "password" ) { PF . obj . modal . form _data . editing . password = $ ( "[name=form-album-password]" , $modal ) . val ( ) ; }
return true ; } ; CHV . fn . complete _album _edit = { success : function ( XHR ) { var album = XHR . responseJSON . album ; $ ( "[data-text=album-name]" ) . html ( PF . fn . htmlEncode ( album . name ) ) ; $ ( "[data-text=album-description]" ) . html ( PF . fn . htmlEncode ( album . description ) ) ; CHV . fn . resource _privacy _toggle ( album . privacy ) ; var stock = CHV . obj . resource . type ; CHV . obj . resource . type = null ; CHV . fn . list _editor . updateItem ( $ ( ".list-item" ) , XHR . responseJSON ) ; CHV . obj . resource . type = stock ; $ ( "[data-modal]" ) . each ( function ( ) { $ ( "option[value=" + album . id _encoded + "]" , this ) . text ( album . name + ( album . privacy !== "public" ? ' (' + PF . fn . _s ( "private" ) + ')' : '' ) ) ; } ) ; CHV . fn . common . updateDoctitle ( album . name ) ; PF . fn . growl . expirable ( PF . fn . _s ( "Album edited successfully." ) ) ; } } ; CHV . fn . category = { formFields : [ "id" , "name" , "url_key" , "description" ] , validateForm : function ( id ) { var modal = PF . obj . modal . selectors . root , submit = true , used _url _key = false ; if ( ! CHV . fn . common . validateForm ( modal ) ) { return false ; }
if ( /^[-\w]+$/ . test ( $ ( "[name=form-category-url_key]" , modal ) . val ( ) ) == false ) { PF . fn . growl . call ( PF . fn . _s ( "Invalid URL key." ) ) ; $ ( "[name=form-category-url_key]" , modal ) . highlight ( ) ; return false ; }
if ( Object . size ( CHV . obj . categories ) > 0 ) { $ . each ( CHV . obj . categories , function ( i , v ) { if ( typeof id !== "undefined" && v . id == id ) return true ; if ( v . url _key == $ ( "[name=form-category-url_key]" , modal ) . val ( ) ) { used _url _key = true ; return false ; } } ) ; }
if ( used _url _key ) { PF . fn . growl . call ( PF . fn . _s ( "Category URL key already being used." ) ) ; $ ( "[name=form-category-url_key]" , modal ) . highlight ( ) ; return false ; }
return true ; } , edit : { before : function ( e ) { var $this = $ ( e . target ) , id = $this . data ( "category-id" ) , category = CHV . obj . categories [ id ] , modal _source = "[data-modal=" + $this . data ( "target" ) + "]" ; $ . each ( CHV . fn . category . formFields , function ( i , v ) { var i = "form-category-" + v , v = category [ v ] , $input = $ ( "[name=" + i + "]" , modal _source ) ; if ( $input . is ( "textarea" ) ) { $input . html ( PF . fn . htmlEncode ( v ) ) ; } else { $input . attr ( "value" , v ) ; } } ) ; } , submit : function ( ) { var modal = PF . obj . modal . selectors . root , id = $ ( "[name=form-category-id]" , modal ) . val ( ) ; if ( ! CHV . fn . category . validateForm ( id ) ) { return false ; }
PF . obj . modal . form _data = { action : "edit" , edit : "category" , editing : { } } ; $ . each ( CHV . fn . category . formFields , function ( i , v ) { PF . obj . modal . form _data . editing [ v ] = $ ( "[name=form-category-" + v + "]" , modal ) . val ( ) ; } ) ; return true ; } , complete : { success : function ( XHR ) { var category = XHR . responseJSON . category , parent = "[data-content=category][data-category-id=" + category . id + "]" ; $ . each ( category , function ( i , v ) { $ ( "[data-content=category-" + i + "]" , parent ) . html ( PF . fn . htmlEncode ( v ) ) ; } ) ; $ ( "[data-link=category-url]" ) . attr ( "href" , category . url ) ; CHV . obj . categories [ category . id ] = category ; } } } , delete : { before : function ( e ) { var $this = $ ( e . target ) , id = $this . data ( "category-id" ) , category = CHV . obj . categories [ id ] ; $this . attr ( "data-confirm" , $this . attr ( "data-confirm" ) . replace ( "%s" , '"' + category . name + '"' ) ) ; } , submit : function ( id ) { PF . obj . modal . form _data = { action : "delete" , delete : "category" , deleting : { id : id } } ; return true ; } , complete : { success : function ( XHR ) { PF . fn . growl . expirable ( PF . fn . _s ( "Category successfully deleted." ) ) ; var id = XHR . responseJSON . request . deleting . id ; $ ( "[data-content=category][data-category-id=" + id + "]" ) . remove ( ) ; delete CHV . obj . categories [ id ] ; } } } , add : { submit : function ( ) { var modal = PF . obj . modal . selectors . root ; if ( ! CHV . fn . category . validateForm ( ) ) { return false ; }
PF . obj . modal . form _data = { action : "add-category" , category : { } } ; $ . each ( CHV . fn . category . formFields , function ( i , v ) { if ( v == "id" ) return ; PF . obj . modal . form _data . category [ v ] = $ ( "[name=form-category-" + v + "]" , modal ) . val ( ) ; } ) ; return true ; } , complete : { success : function ( XHR ) { var category = XHR . responseJSON . category , list = "[data-content=dashboard-categories-list]" , html = $ ( "[data-content=category-dashboard-template]" ) . html ( ) , replaces = { } ; $ . each ( category , function ( i , v ) { html = html . replace ( new RegExp ( "%" + i . toUpperCase ( ) + "%" , "g" ) , v ? v : "" ) ; } ) ; $ ( list ) . append ( html ) ; if ( Object . size ( CHV . obj . categories ) == 0 ) { CHV . obj . categories = { } ; }
CHV . obj . categories [ category . id ] = category ; PF . fn . growl . call ( PF . fn . _s ( "Category %s added." , '"' + category . name + '"' ) ) ; } } } } ; CHV . fn . ip _ban = { formFields : [ "id" , "ip" , "expires" , "message" ] , validateForm : function ( id ) { var modal = PF . obj . modal . selectors . root , submit = true , already _banned = false , ip = $ ( "[name=form-ip_ban-ip]" , modal ) . val ( ) ; if ( ! CHV . fn . common . validateForm ( modal ) ) { return false ; }
if ( $ ( "[name=form-ip_ban-expires]" , modal ) . val ( ) !== "" && /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/ . test ( $ ( "[name=form-ip_ban-expires]" , modal ) . val ( ) ) == false ) { PF . fn . growl . call ( PF . fn . _s ( "Invalid expiration date." ) ) ; $ ( "[name=form-ip_ban-expires]" , modal ) . highlight ( ) ; return false ; }
if ( Object . size ( CHV . obj . ip _bans ) > 0 ) { $ . each ( CHV . obj . ip _bans , function ( i , v ) { if ( typeof id !== "undefined" && v . id == id ) return true ; if ( v . ip == ip ) { already _banned = true ; return false ; } } ) ; }
if ( already _banned ) { PF . fn . growl . call ( PF . fn . _s ( "IP %s already banned." , ip ) ) ; $ ( "[name=form-ip_ban-ip]" , modal ) . highlight ( ) ; return false ; }
return true ; } , add : { submit : function ( ) { var modal = PF . obj . modal . selectors . root ; if ( ! CHV . fn . ip _ban . validateForm ( ) ) { return false ; }
PF . obj . modal . form _data = { action : "add-ip_ban" , ip _ban : { } } ; $ . each ( CHV . fn . ip _ban . formFields , function ( i , v ) { if ( v == "id" ) return ; PF . obj . modal . form _data . ip _ban [ v ] = $ ( "[name=form-ip_ban-" + v + "]" , modal ) . val ( ) ; } ) ; return true ; } , complete : { success : function ( XHR ) { var ip _ban = XHR . responseJSON . ip _ban , list = "[data-content=dashboard-ip_bans-list]" , html = $ ( "[data-content=ip_ban-dashboard-template]" ) . html ( ) , replaces = { } ; if ( typeof html !== "undefined" ) { $ . each ( ip _ban , function ( i , v ) { html = html . replace ( new RegExp ( "%" + i . toUpperCase ( ) + "%" , "g" ) , v ? v : "" ) ; } ) ; $ ( list ) . append ( html ) ; }
if ( Object . size ( CHV . obj . ip _bans ) == 0 ) { CHV . obj . ip _bans = { } ; }
CHV . obj . ip _bans [ ip _ban . id ] = ip _ban ; $ ( "[data-content=ban_uploader_ip]" ) . hide ( ) ; $ ( "[data-content=banned_uploader_ip]" ) . show ( ) ; PF . fn . growl . call ( PF . fn . _s ( "IP %s banned." , ip _ban . ip ) ) ; } , error : function ( XHR ) { var error = XHR . responseJSON . error ; PF . fn . growl . call ( PF . fn . _s ( error . message ) ) ; } } } , edit : { before : function ( e ) { var $this = $ ( e . target ) , id = $this . data ( "ip_ban-id" ) , target = CHV . obj . ip _bans [ id ] , modal _source = "[data-modal=" + $this . data ( "target" ) + "]" ; $ . each ( CHV . fn . ip _ban . formFields , function ( i , v ) { var i = "form-ip_ban-" + v , v = target [ v ] , $input = $ ( "[name=" + i + "]" , modal _source ) ; if ( $input . is ( "textarea" ) ) { $input . html ( PF . fn . htmlEncode ( v ) ) ; } else { $input . attr ( "value" , v ) ; } } ) ; } , submit : function ( ) { var modal = PF . obj . modal . selectors . root , id = $ ( "[name=form-ip_ban-id]" , modal ) . val ( ) ; if ( ! CHV . fn . ip _ban . validateForm ( id ) ) { return false ; }
PF . obj . modal . form _data = { action : "edit" , edit : "ip_ban" , editing : { } } ; $ . each ( CHV . fn . ip _ban . formFields , function ( i , v ) { PF . obj . modal . form _data . editing [ v ] = $ ( "[name=form-ip_ban-" + v + "]" , modal ) . val ( ) ; } ) ; return true ; } , complete : { success : function ( XHR ) { var ip _ban = XHR . responseJSON . ip _ban , parent = "[data-content=ip_ban][data-ip_ban-id=" + ip _ban . id + "]" ; $ . each ( ip _ban , function ( i , v ) { $ ( "[data-content=ip_ban-" + i + "]" , parent ) . html ( PF . fn . htmlEncode ( v ) ) ; } ) ; CHV . obj . ip _bans [ ip _ban . id ] = ip _ban ; } } } , delete : { before : function ( e ) { var $this = $ ( e . target ) , id = $this . data ( "ip_ban-id" ) , ip _ban = CHV . obj . ip _bans [ id ] ; $this . attr ( "data-confirm" , $this . attr ( "data-confirm" ) . replace ( "%s" , ip _ban . ip ) ) ; } , submit : function ( id ) { PF . obj . modal . form _data = { action : "delete" , delete : "ip_ban" , deleting : { id : id } } ; return true ; } , complete : { success : function ( XHR ) { PF . fn . growl . expirable ( PF . fn . _s ( "IP ban successfully deleted." ) ) ; var id = XHR . responseJSON . request . deleting . id ; $ ( "[data-content=ip_ban][data-ip_ban-id=" + id + "]" ) . remove ( ) ; delete CHV . obj . ip _bans [ id ] ; } } } } ; CHV . fn . storage = { formFields : [ "id" , "name" , "api_id" , "bucket" , "server" , "service" , "capacity" , "region" , "key" , "secret" , "url" , "account_id" , "account_name" ] , calling : false , validateForm : function ( ) { var modal = PF . obj . modal . selectors . root , id = $ ( "[name=form-storage-id]" , modal ) . val ( ) , submit = true ; $ . each ( $ ( ":input" , modal ) , function ( i , v ) { if ( $ ( this ) . is ( ":hidden" ) ) { if ( $ ( this ) . attr ( "required" ) ) { $ ( this ) . removeAttr ( "required" ) . attr ( "data-required" , 1 ) ; } } else { if ( $ ( this ) . attr ( "data-required" ) == 1 ) { $ ( this ) . attr ( "required" , "required" ) ; } }
if ( $ ( this ) . is ( ":visible" ) && $ ( this ) . val ( ) == "" && $ ( this ) . attr ( "required" ) ) { $ ( this ) . highlight ( ) ; submit = false ; } } ) ; if ( ! submit ) { PF . fn . growl . call ( PF . fn . _s ( "Please fill all the required fields." ) ) ; return false ; }
var $storage _capacity = $ ( "[name=form-storage-capacity]" , modal ) , storage _capacity = $storage _capacity . val ( ) , capacity _error _msg ; if ( storage _capacity !== "" ) { if ( /^[\d\.]+\s*[A-Za-z]{2}$/ . test ( storage _capacity ) == false || typeof storage _capacity . getBytes ( ) == "undefined" ) { capacity _error _msg = PF . fn . _s ( "Invalid storage capacity value. Make sure to use a valid format." ) ; } else if ( typeof CHV . obj . storages [ id ] !== "undefined" && storage _capacity . getBytes ( ) < CHV . obj . storages [ id ] . space _used ) { capacity _error _msg = PF . fn . _s ( "Storage capacity can't be lower than its current usage (%s)." , CHV . obj . storages [ id ] . space _used . formatBytes ( ) ) ; }
if ( capacity _error _msg ) { PF . fn . growl . call ( capacity _error _msg ) ; $storage _capacity . highlight ( ) ; return false ; } }
if ( /^https?:\/\/.+$/ . test ( $ ( "[name=form-storage-url]" , modal ) . val ( ) ) == false ) { PF . fn . growl . call ( PF . fn . _s ( "Invalid URL." ) ) ; $ ( "[name=form-storage-url]" , modal ) . highlight ( ) ; return false ; }
return true ; } , toggleHttps : function ( id ) { this . toggleBool ( id , "https" ) ; } , toggleActive : function ( id ) { this . toggleBool ( id , "active" ) ; } , toggleBool : function ( id , string ) { if ( this . calling ) return ; this . calling = true ; var $root = $ ( "[data-storage-id=" + id + "]" ) , $parent = $ ( "[data-content=storage-" + string + "]" , $root ) , $el = $ ( "[data-checkbox]" , $parent ) , checked = CHV . obj . storages [ id ] [ "is_" + string ] , toggle = checked == 0 ? 1 : 0 , data = { action : "edit" , edit : "storage" , editing : { id : id } } ; data . editing [ "is_" + string ] = toggle ; if ( string == "https" ) { data . editing . url = CHV . obj . storages [ id ] . url ; }
PF . fn . loading . fullscreen ( ) ; $ . ajax ( { data : data } ) . always ( function ( data , status , XHR ) { CHV . fn . storage . calling = false ; PF . fn . loading . destroy ( "fullscreen" ) ; if ( typeof data . storage == "undefined" ) { PF . fn . growl . call ( data . responseJSON . error . message ) ; return ; }
var storage = data . storage ; CHV . obj . storages [ storage . id ] = storage ; PF . fn . growl . expirable ( PF . fn . _s ( "Storage successfully edited." ) ) ; switch ( string ) { case "https" : $ ( "[data-content=storage-url]" , $root ) . html ( storage . url ) ; break ; }
CHV . fn . storage . toggleBoolDisplay ( $el , toggle ) ; CHV . fn . queuePixel ( ) ; } ) ; } , edit : { before : function ( e ) { var $this = $ ( e . target ) , id = $this . data ( "storage-id" ) , storage = CHV . obj . storages [ id ] , modal _source = "[data-modal=" + $this . data ( "target" ) + "]" , combo = "[data-combo-value~=" + storage [ 'api_id' ] + "]" ; $ . each ( CHV . fn . storage . formFields , function ( i , v ) { var i = "form-storage-" + v , v = storage [ v ] , $combo _input = $ ( combo + " [name=" + i + "]" , modal _source ) , $global _input = $ ( "[name=" + i + "]" , modal _source ) , $input = $combo _input . exists ( ) ? $combo _input : $global _input ; if ( $input . is ( "textarea" ) ) { $input . html ( PF . fn . htmlEncode ( v ) ) ; } else if ( $input . is ( "select" ) ) { $ ( "option" , $input ) . removeAttr ( "selected" ) ; $ ( "option" , $input ) . each ( function ( ) { if ( $ ( this ) . attr ( "value" ) == v ) { $ ( this ) . attr ( "selected" , "selected" ) ; return false ; } } ) ; } else { if ( $input . is ( "[name=form-storage-capacity]" ) && typeof v !== "undefined" && v > 0 ) { v = v . formatBytes ( 2 ) ; }
$input . attr ( "value" , v ) ; } } ) ; $ ( "[data-combo-value]" ) . addClass ( "soft-hidden" ) ; $ ( combo ) . removeClass ( "soft-hidden" ) ; } , submit : function ( ) { var modal = PF . obj . modal . selectors . root , id = $ ( "[name=form-storage-id]" , modal ) . val ( ) , used _url _key = false ; if ( ! CHV . fn . storage . validateForm ( ) ) { return false ; }
PF . obj . modal . form _data = { action : "edit" , edit : "storage" , editing : { } } ; $ . each ( CHV . fn . storage . formFields , function ( i , v ) { var sel ; sel = "[name=form-storage-" + v + "]" ; if ( $ ( sel , modal ) . attr ( "type" ) !== "hidden" ) { sel += ":visible" }
PF . obj . modal . form _data . editing [ v ] = $ ( sel , modal ) . val ( ) ; } ) ; return true ; } , complete : { success : function ( XHR ) { var storage = XHR . responseJSON . storage , parent = "[data-content=storage][data-storage-id=" + storage . id + "]" , $el = $ ( "[data-action=toggle-storage-https]" , parent ) ; $ . each ( storage , function ( i , v ) { $ ( "[data-content=storage-" + i + "]" , parent ) . html ( PF . fn . htmlEncode ( v ) ) ; } ) ; CHV . obj . storages [ storage . id ] = storage ; CHV . fn . storage . toggleBoolDisplay ( $el , storage [ 'is_https' ] == 1 ) ; CHV . fn . queuePixel ( ) ; } , error : function ( XHR ) { var response = XHR . responseJSON , message = response . error . message ; PF . fn . growl . call ( message ) ; } } } , add : { submit : function ( ) { if ( ! CHV . fn . storage . validateForm ( ) ) { return false ; }
var modal = PF . obj . modal . selectors . root ; PF . obj . modal . form _data = { action : "add-storage" , storage : { } } ; $ . each ( CHV . fn . storage . formFields , function ( i , v ) { if ( v == "id" ) return ; var sel ; sel = "[name=form-storage-" + v + "]" ; if ( $ ( sel , modal ) . attr ( "type" ) !== "hidden" ) { sel += ":visible" }
PF . obj . modal . form _data . storage [ v ] = $ ( sel , modal ) . val ( ) ; } ) ; return true ; } , complete : { success : function ( XHR ) { var storage = XHR . responseJSON . storage , list = "[data-content=dashboard-storages-list]" , html = $ ( "[data-content=storage-dashboard-template]" ) . html ( ) , replaces = { } ; $ . each ( storage , function ( i , v ) { var upper = i . toUpperCase ( ) ; if ( i == "is_https" || i == "is_active" ) { var v = CHV . obj . storageTemplate . icon . replace ( "%TITLE%" , CHV . obj . storageTemplate . messages [ i ] ) . replace ( "%ICON%" , CHV . obj . storageTemplate . checkboxes [ v ] ) . replace ( "%PROP%" , i . replace ( "is_" , "" ) ) ; }
html = html . replace ( new RegExp ( "%" + upper + "%" , "g" ) , v ? v : "" ) ; } ) ; $ ( list ) . append ( html ) ; PF . fn . bindtipTip ( $ ( "[data-storage-id=" + storage . id + "]" ) ) ; if ( CHV . obj . storages . length == 0 ) { CHV . obj . storages = { } ; }
CHV . obj . storages [ storage . id ] = storage ; CHV . fn . queuePixel ( ) ; } , error : function ( XHR ) { var response = XHR . responseJSON , message = response . error . message ; PF . fn . growl . call ( message ) ; } } } , toggleBoolDisplay : function ( $el , toggle ) { var icons = { 0 : $el . data ( "unchecked-icon" ) , 1 : $el . data ( "checked-icon" ) } ; $el . removeClass ( icons [ 0 ] + " " + icons [ 1 ] ) . addClass ( icons [ toggle ? 1 : 0 ] ) ; } } ; CHV . fn . common = { validateForm : function ( modal ) { if ( typeof modal == "undefined" ) { var modal = PF . obj . modal . selectors . root }
var submit = true ; $ . each ( $ ( ":input:visible" , modal ) , function ( i , v ) { if ( $ ( this ) . val ( ) == "" && $ ( this ) . attr ( "required" ) ) { $ ( this ) . highlight ( ) ; submit = false ; } } ) ; if ( ! submit ) { PF . fn . growl . call ( PF . fn . _s ( "Please fill all the required fields." ) ) ; return false ; }
return true ; } , updateDoctitle : function ( pre _doctitle ) { if ( typeof CHV . obj . page _info !== typeof undefined ) { CHV . obj . page _info . pre _doctitle = pre _doctitle ; CHV . obj . page _info . doctitle = CHV . obj . page _info . pre _doctitle + CHV . obj . page _info . pos _doctitle ; document . title = CHV . obj . page _info . doctitle ; } } } ; CHV . fn . user = { add : { submit : function ( ) { var $modal = $ ( PF . obj . modal . selectors . root ) , submit = true ; $ . each ( $ ( ":input" , $modal ) , function ( i , v ) { if ( $ ( this ) . val ( ) == "" && $ ( this ) . attr ( "required" ) ) { $ ( this ) . highlight ( ) ; submit = false ; } } ) ; if ( ! submit ) { PF . fn . growl . call ( PF . fn . _s ( "Please fill all the required fields." ) ) ; return false ; }
PF . obj . modal . form _data = { action : "add-user" , user : { username : $ ( "[name=form-username]" , $modal ) . val ( ) , email : $ ( "[name=form-email]" , $modal ) . val ( ) , password : $ ( "[name=form-password]" , $modal ) . val ( ) , role : $ ( "[name=form-role]" , $modal ) . val ( ) } } ; return true ; } , complete : { success : function ( XHR ) { var response = XHR . responseJSON ; PF . fn . growl . expirable ( PF . fn . _s ( "User added successfully." ) ) ; } , error : function ( XHR ) { var response = XHR . responseJSON ; PF . fn . growl . call ( PF . fn . _s ( response . error . message ) ) ; } } } , delete : { submit : function ( ) { PF . obj . modal . form _data = { action : "delete" , delete : "user" , owner : CHV . obj . resource . user . id , deleting : CHV . obj . resource . user } ; return true ; } } } ; CHV . fn . submit _resource _delete = function ( ) { PF . obj . modal . form _data = { action : "delete" , delete : CHV . obj . resource . type , from : "resource" , owner : typeof CHV . obj . resource . user !== "undefined" ? CHV . obj . resource . user . id : null , deleting : CHV . obj . resource } ; return true ; } ; CHV . fn . complete _resource _delete = { success : function ( XHR ) { var response = XHR . responseJSON ; $ ( "body" ) . fadeOut ( "normal" , function ( ) { var redir ; if ( CHV . obj . resource . type == "album" || CHV . obj . resource . type == "image" ) { redir = CHV . obj . resource . parent _url ; } else { redir = CHV . obj . resource . user ? CHV . obj . resource . user . url : CHV . obj . resource . url ; }
if ( typeof redir !== "undefined" ) { window . location = redir + "?deleted" ; } } ) ; } } ; CHV . fn . list _editor = { selectionCount : function ( ) { var $content _listing = $ ( PF . obj . listing . selectors . content _listing ) ; $content _listing . each ( function ( ) { var $listing _options = $ ( "[data-content=pop-selection]" , "[data-content=list-selection][data-tab=" + $ ( this ) . attr ( "id" ) + "]" ) , selection _count = $ ( PF . obj . listing . selectors . list _item + ".selected" , this ) . length ; all _count = $ ( PF . obj . listing . selectors . list _item , this ) . length ; $listing _options [ selection _count > 0 ? "removeClass" : "addClass" ] ( "disabled" ) ; $ ( "[data-text=selection-count]" , $listing _options ) . text ( selection _count > 0 ? selection _count : "" ) ; if ( $content _listing . data ( 'list' ) == 'images' && selection _count > 0 ) { var has _sfw = $ ( PF . obj . listing . selectors . list _item + ".selected[data-flag=safe]" , this ) . length > 0 , has _nsfw = $ ( PF . obj . listing . selectors . list _item + ".selected[data-flag=unsafe]" , this ) . length > 0 ; $ ( "[data-action=flag-safe]" , $listing _options ) [ ( has _nsfw ? "remove" : "add" ) + "Class" ] ( "hidden" ) ; $ ( "[data-action=flag-unsafe]" , $listing _options ) [ ( has _sfw ? "remove" : "add" ) + "Class" ] ( "hidden" ) ; }
if ( $ ( this ) . is ( ":visible" ) ) { CHV . fn . list _editor . listMassActionSet ( all _count == selection _count ? "clear" : "select" ) ; } } ) ; } , removeFromList : function ( $target , msg ) { if ( typeof $target == "undefined" ) return ; var $target = $target instanceof jQuery == false ? $ ( $target ) : $target , $content _listing = $ ( PF . obj . listing . selectors . content _listing _visible ) , target _size = $target . length ; $target . fadeOut ( "fast" ) ; var type = $target . first ( ) . data ( "type" ) , new _count = parseInt ( $ ( "[data-text=" + type + "-count]" ) . text ( ) ) - target _size ; CHV . fn . list _editor . updateUserCounters ( $target . first ( ) . data ( "type" ) , target _size , "-" ) ; $target . promise ( ) . done ( function ( ) { var affected _content _lists = { } ; $target . each ( function ( ) { $ ( "[data-id=" + $ ( this ) . data ( "id" ) + "]" ) . each ( function ( ) { var list _id = $ ( this ) . closest ( PF . obj . listing . selectors . content _listing ) . attr ( "id" ) ; if ( ! affected _content _lists [ list _id ] ) { affected _content _lists [ list _id ] = 0 ; }
affected _content _lists [ list _id ] += 1 ; } ) ; } ) ; if ( target _size == 1 ) { $ ( "[data-id=" + $ ( this ) . data ( "id" ) + "]" ) . remove ( ) ; } else { $target . each ( function ( ) { $ ( "[data-id=" + $ ( this ) . data ( "id" ) + "]" ) . remove ( ) ; } ) ; }
PF . fn . listing . columnizerQueue ( ) ; PF . fn . listing . refresh ( ) ; CHV . fn . list _editor . selectionCount ( ) ; if ( typeof msg !== "undefined" && typeof msg == "string" ) { PF . fn . growl . expirable ( msg ) ; }
for ( var k in affected _content _lists ) { var $list = $ ( "#" + k ) , stock _offset = $list . data ( "offset" ) , offset = - affected _content _lists [ k ] ; ; stock _offset = ( typeof stock _offset == "undefined" ) ? 0 : parseInt ( stock _offset ) ; $list . data ( "offset" , stock _offset + offset ) ; }
if ( ! $ ( PF . obj . listing . selectors . content _listing _pagination , $content _listing ) . exists ( ) && $ ( ".list-item" , $content _listing ) . length == 0 ) { new _count = 0 ; }
if ( new _count == 0 ) { $content _listing . html ( PF . obj . listing . template . empty ) ; $ ( PF . obj . listing . selectors . content _listing + ":not(" + PF . obj . listing . selectors . content _listing _visible + ")" ) . data ( { empty : null , load : "ajax" } ) ; $ ( "[data-content=list-selection][data-tab=" + $content _listing . attr ( "id" ) + "]" ) . addClass ( "disabled" ) ; } else { if ( $ ( PF . obj . listing . selectors . list _item , $content _listing ) . length == 0 ) { $ ( PF . obj . listing . selectors . pad _content ) . height ( 0 ) ; $content _listing . find ( "[data-action=load-more]" ) . click ( ) ; PF . obj . listing . recolumnize = true ; } } } ) ; } , deleteFromList : function ( $target ) { if ( typeof growl == "undefined" ) { var growl = true ; }
var $target = $target instanceof jQuery == false ? $ ( $target ) : $target ; this . removeFromList ( $target , growl ? PF . fn . _s ( "The content has been deleted." ) : null ) ; } , moveFromList : function ( $target , growl ) { if ( typeof growl == "undefined" ) { var growl = true ; }
var $target = $target instanceof jQuery == false ? $ ( $target ) : $target ; this . removeFromList ( $target , growl ? PF . fn . _s ( "The content has been moved." ) : null ) ; } , toggleSelectItem : function ( $list _item , select ) { if ( typeof select !== "boolean" ) { var select = true ; }
var $icon = $ ( "[data-action=select] .btn-icon" , $list _item ) , add _class , remove _class , label _text ; if ( ! select ) { $list _item . removeClass ( "selected" ) . find ( ".list-item-image-tools" ) . css ( "display" , "none" ) ; add _class = $icon . data ( "icon-unselected" ) ; remove _class = $icon . data ( "icon-selected" ) ; label _text = PF . fn . _s ( "Select" ) ; setTimeout ( function ( ) { $list _item . find ( ".list-item-image-tools" ) . css ( "display" , "" ) ; } , 0 ) ; } else { $list _item . addClass ( "selected" ) ; add _class = $icon . data ( "icon-selected" ) ; remove _class = $icon . data ( "icon-unselected" ) ; label _text = PF . fn . _s ( "Unselect" ) ; }
$ ( "[data-action=select] .label" , $list _item ) . text ( label _text ) ; $icon . removeClass ( remove _class ) . addClass ( add _class ) ; CHV . fn . list _editor . selectionCount ( ) ; } , selectItem : function ( $list _item ) { this . toggleSelectItem ( $list _item , true ) ; } , unselectItem : function ( $list _item ) { this . toggleSelectItem ( $list _item , false ) ; } , clearSelection : function ( all ) { var $targets = $ ( PF . obj . listing . selectors . list _item + ".selected" , PF . obj . listing . selectors [ all ? "content_listing" : "content_listing_visible" ] ) ; this . unselectItem ( $targets ) ; this . listMassActionSet ( "select" ) ; } , listMassActionSet : function ( action ) { var current = action == "select" ? "clear" : "select" ; var $target = $ ( "[data-action=list-" + current + "-all]:visible" ) ; var text = $target . data ( "text-" + action + "-all" ) ; $target . text ( text ) . attr ( "data-action" , "list-" + action + "-all" ) ; } , updateItem : function ( $target , response , action , growl ) { if ( $target instanceof jQuery == false ) { var $target = $ ( $target ) ; }
var dealing _with = $target . data ( "type" ) , album = dealing _with == "image" ? response . album : response ; this . addAlbumtoModals ( album ) ; $ ( "option[value=" + album . id _encoded + "]" , "[name=form-album-id]" ) . html ( PF . fn . htmlEncode ( album . name ) ) ; if ( typeof action == "undefined" ) { var action = "edit" ; }
if ( action == "edit" || action == "move" ) { if ( action == "move" && CHV . obj . resource . type == "album" ) { CHV . fn . list _editor . moveFromList ( $target , growl ) ; return }
$target . data ( "description" , response . description ) ; if ( dealing _with == "image" ) { if ( typeof response . title !== typeof undefined ) { $target . data ( "title" , response . title ) ; $target . find ( "[title]" ) . attr ( "title" , response . title ) ; $ ( "[data-text=image-title]" , $target ) . html ( PF . fn . htmlEncode ( response . title ) ) ; }
if ( typeof response . title _truncated !== typeof undefined ) { $ ( "[data-text=image-title-truncated]" , $target ) . html ( PF . fn . htmlEncode ( response . title _truncated ) ) ; }
if ( typeof response . category _id !== typeof undefined ) { $target . data ( "category-id" , response . category _id ) ; }
$target . data ( { "album-id" : album . id _encoded , flag : response . nsfw == 1 ? "unsafe" : "safe" } ) . removeClass ( "safe unsafe" ) . addClass ( response . nsfw == 1 ? "unsafe" : "safe" ) ; $ ( "[data-content=album-link]" , $target ) . attr ( "href" , album . url ) ; } else { $target . data ( "privacy" , album . privacy ) ; $target . data ( "password" , album . password ) ; $target . data ( "name" , album . name ) ; }
$target . removeClass ( "privacy-public privacy-private privacy-password" ) . addClass ( "privacy-" + album . privacy ) ; $ ( "[data-text=album-name]" , $target ) . html ( PF . fn . htmlEncode ( album . name ) ) ; PF . fn . growl . expirable ( action == "edit" ? PF . fn . _s ( "The content has been edited." ) : PF . fn . _s ( "The content has been moved." ) ) ; } } , addAlbumtoModals : function ( album ) { var added = false ; $ ( "[name=form-album-id]" , "[data-modal]" ) . each ( function ( ) { if ( album . id _encoded && ! $ ( "option[value=" + album . id _encoded + "]" , this ) . exists ( ) ) { $ ( this ) . append ( '<option value="' + album . id _encoded + '">' + album . name + ( album . privacy !== "public" ? ' (' + PF . fn . _s ( "private" ) + ')' : '' ) + '</option>' ) ; added = true ; } } ) ; if ( added ) { CHV . fn . list _editor . updateUserCounters ( "album" , 1 , "+" ) ; } } , updateAlbum : function ( album ) { $ ( "[data-id=" + album . id _encoded + "]" ) . each ( function ( ) { if ( album . html !== "" ) { $ ( this ) . after ( album . html ) ; $ ( this ) . remove ( ) ; } } ) ; } , updateUserCounters : function ( counter , number , operation ) { if ( typeof operation == "undefined" ) { var operation = "+" ; }
var $count = $ ( "[data-text=" + counter + "-count]" ) , $count _label = $ ( "[data-text=" + counter + "-label]" ) , number = parseInt ( number ) , old _count = parseInt ( $count . html ( ) ) , new _count , delta ; switch ( operation ) { case "+" : new _count = old _count + number ; break ; case "-" : new _count = old _count - number ; break ; case "=" : new _count = number ; break ; }
delta = new _count - old _count ; var $total _count = $ ( "[data-text=total-" + $count . data ( "text" ) + "]" ) , $total _count _label = $ ( "[data-text=" + $total _count . data ( "text" ) + "-label]" ) , old _total _count = parseInt ( $total _count . html ( ) ) , new _total _count = old _total _count + delta ; $count . text ( new _count ) ; $total _count . text ( new _total _count ) ; $count _label . text ( $count _label . data ( new _count == 1 ? "label-single" : "label-plural" ) ) ; $total _count _label . text ( $count _label . data ( new _total _count == 1 ? "label-single" : "label-plural" ) ) ; } , updateMoveItemLists : function ( response , dealing _with , $targets ) { CHV . fn . list _editor . clearSelection ( ) ; if ( /image/ . test ( dealing _with ) ) { if ( dealing _with == "image" ) { CHV . fn . list _editor . updateItem ( "[data-id=" + $targets . data ( "id" ) + "]" , response . image , "move" ) ; } else { $targets . each ( function ( ) { CHV . fn . list _editor . updateItem ( "[data-id=" + $ ( this ) . data ( "id" ) + "]" , response , "move" , false ) ; } ) ; PF . fn . growl . expirable ( PF . fn . _s ( "The content has been moved." ) ) ; } } else { if ( CHV . obj . resource . type == "album" ) { CHV . fn . list _editor . moveFromList ( $targets ) ; } else { PF . fn . growl . expirable ( PF . fn . _s ( "The content has been moved." ) ) ; }
if ( typeof response . albums _old !== "undefined" ) { for ( var i = 0 ; i < response . albums _old . length ; i ++ ) { CHV . fn . list _editor . updateAlbum ( response . albums _old [ i ] ) ; } } else { CHV . fn . list _editor . updateAlbum ( response . old _album ) ; }
if ( response . album ) { if ( typeof response . albums _old !== "undefined" ? response . request . album . new == "true" : response . request . editing . new _album == "true" ) { CHV . fn . list _editor . addAlbumtoModals ( response . album ) ; var old _count = parseInt ( $ ( "[data-text=album-count]" ) . text ( ) ) - 1 ; $ ( PF . obj . listing . selectors . pad _content ) . each ( function ( ) { var list _count = $ ( this ) . find ( PF . obj . listing . selectors . list _item ) . length ; if ( list _count == 0 ) { return ; }
var params = PF . fn . deparam ( $ ( this ) . closest ( PF . obj . listing . selectors . content _listing ) . data ( "params" ) ) ; if ( params . sort == "date_desc" || old _count == list _count ) { $ ( this ) [ params . sort == "date_desc" ? "prepend" : "append" ] ( response . album . html ) ; } } ) ; } else { CHV . fn . list _editor . updateAlbum ( response . album ) ; } }
PF . fn . listing . columnizerQueue ( ) ; PF . fn . listing . refresh ( 0 ) ; } } } ; CHV . fn . queuePixel = function ( ) { var img = '<img data-content="queue-pixel" src="' + PF . obj . config . base _url + '?queue&r=' + PF . fn . generate _random _string ( 32 ) + '" width="1" height="1" alt="" style="display: none;">' ; $ ( "body" ) . append ( img ) ; }