Input: Start or resume uploading . [CODESPLIT] function ( ) { // Make sure we don't start too many uploads at once var ret = this . _shouldUploadNext ( ) ; if ( ret === false ) { return ; } // Kick off the queue this . fire ( 'uploadStart' ) ; var started = false ; for ( var num = 1 ; num <= this . opts . simultaneousUploads - ret ; num ++ ) { started = this . uploadNextChunk ( true ) || started ; } if ( ! started ) { async ( function ( ) { this . fire ( 'complete' ) ; } , this ) ; } }


Input: Add a HTML5 File object to the list of files . [CODESPLIT] function ( fileList , event ) { var files = [ ] ; each ( fileList , function ( file ) { // https://github.com/flowjs/flow.js/issues/55 if ( ( ! ie10plus || ie10plus && file . size > 0 ) && ! ( file . size % 4096 === 0 && ( file . name === '.' || file . fileName === '.' ) ) ) { var uniqueIdentifier = this . generateUniqueIdentifier ( file ) ; if ( this . opts . allowDuplicateUploads || ! this . getFromUniqueIdentifier ( uniqueIdentifier ) ) { var f = new FlowFile ( this , file , uniqueIdentifier ) ; if ( this . fire ( 'fileAdded' , f , event ) ) { files . push ( f ) ; } } } } , this ) ; if ( this . fire ( 'filesAdded' , files , event ) ) { each ( files , function ( file ) { if ( this . opts . singleFile && this . files . length > 0 ) { this . removeFile ( this . files [ 0 ] ) ; } this . files . push ( file ) ; } , this ) ; this . fire ( 'filesSubmitted' , files , event ) ; } }


Input: Cancel upload of a specific FlowFile object from the list . [CODESPLIT] function ( file ) { for ( var i = this . files . length - 1 ; i >= 0 ; i -- ) { if ( this . files [ i ] === file ) { this . files . splice ( i , 1 ) ; file . abort ( ) ; this . fire ( 'fileRemoved' , file ) ; } } }


Input: Look up a FlowFile object by its unique identifier . [CODESPLIT] function ( uniqueIdentifier ) { var ret = false ; each ( this . files , function ( file ) { if ( file . uniqueIdentifier === uniqueIdentifier ) { ret = file ; } } ) ; return ret ; }


Input: Returns remaining time to upload all files in seconds . Accuracy is based on average speed . If speed is zero time remaining will be equal to positive infinity Number . POSITIVE_INFINITY [CODESPLIT] function ( ) { var sizeDelta = 0 ; var averageSpeed = 0 ; each ( this . files , function ( file ) { if ( ! file . paused && ! file . error ) { sizeDelta += file . size - file . sizeUploaded ( ) ; averageSpeed += file . averageSpeed ; } } ) ; if ( sizeDelta && ! averageSpeed ) { return Number . POSITIVE_INFINITY ; } if ( ! sizeDelta && ! averageSpeed ) { return 0 ; } return Math . floor ( sizeDelta / averageSpeed ) ; }


Input:
FlowFile class [CODESPLIT] function FlowFile ( flowObj , file , uniqueIdentifier ) { /**
     * Reference to parent Flow instance
     * @type {Flow}
     */ this . flowObj = flowObj ; /**
     * Used to store the bytes read
     * @type {Blob|string}
     */ this . bytes = null ; /**
     * Reference to file
     * @type {File}
     */ this . file = file ; /**
     * File name. Some confusion in different versions of Firefox
     * @type {string}
     */ this . name = file . fileName || file . name ; /**
     * File size
     * @type {number}
     */ this . size = file . size ; /**
     * Relative file path
     * @type {string}
     */ this . relativePath = file . relativePath || file . webkitRelativePath || this . name ; /**
     * File unique identifier
     * @type {string}
     */ this . uniqueIdentifier = ( uniqueIdentifier === undefined ? flowObj . generateUniqueIdentifier ( file ) : uniqueIdentifier ) ; /**
     * List of chunks
     * @type {Array.<FlowChunk>}
     */ this . chunks = [ ] ; /**
     * Indicated if file is paused
     * @type {boolean}
     */ this . paused = false ; /**
     * Indicated if file has encountered an error
     * @type {boolean}
     */ this . error = false ; /**
     * Average upload speed
     * @type {number}
     */ this . averageSpeed = 0 ; /**
     * Current upload speed
     * @type {number}
     */ this . currentSpeed = 0 ; /**
     * Date then progress was called last time
     * @type {number}
     * @private
     */ this . _lastProgressCallback = Date . now ( ) ; /**
     * Previously uploaded file size
     * @type {number}
     * @private
     */ this . _prevUploadedSize = 0 ; /**
     * Holds previous progress
     * @type {number}
     * @private
     */ this . _prevProgress = 0 ; this . bootstrap ( ) ; }


Input: Update speed parameters [CODESPLIT] function ( ) { var timeSpan = Date . now ( ) - this . _lastProgressCallback ; if ( ! timeSpan ) { return ; } var smoothingFactor = this . flowObj . opts . speedSmoothingFactor ; var uploaded = this . sizeUploaded ( ) ; // Prevent negative upload speed after file upload resume this . currentSpeed = Math . max ( ( uploaded - this . _prevUploadedSize ) / timeSpan * 1000 , 0 ) ; this . averageSpeed = smoothingFactor * this . currentSpeed + ( 1 - smoothingFactor ) * this . averageSpeed ; this . _prevUploadedSize = uploaded ; }


Input: For internal usage only . Callback when something happens within the chunk . [CODESPLIT] function ( chunk , event , message ) { switch ( event ) { case 'progress' : if ( Date . now ( ) - this . _lastProgressCallback < this . flowObj . opts . progressCallbacksInterval ) { break ; } this . measureSpeed ( ) ; this . flowObj . fire ( 'fileProgress' , this , chunk ) ; this . flowObj . fire ( 'progress' ) ; this . _lastProgressCallback = Date . now ( ) ; break ; case 'error' : this . error = true ; this . abort ( true ) ; this . flowObj . fire ( 'fileError' , this , message , chunk ) ; this . flowObj . fire ( 'error' , message , this , chunk ) ; break ; case 'success' : if ( this . error ) { return ; } this . measureSpeed ( ) ; this . flowObj . fire ( 'fileProgress' , this , chunk ) ; this . flowObj . fire ( 'progress' ) ; this . _lastProgressCallback = Date . now ( ) ; if ( this . isComplete ( ) ) { this . currentSpeed = 0 ; this . averageSpeed = 0 ; this . flowObj . fire ( 'fileSuccess' , this , message , chunk ) ; } break ; case 'retry' : this . flowObj . fire ( 'fileRetry' , this , chunk ) ; break ; } }


Input: Abort current upload [CODESPLIT] function ( reset ) { this . currentSpeed = 0 ; this . averageSpeed = 0 ; var chunks = this . chunks ; if ( reset ) { this . chunks = [ ] ; } each ( chunks , function ( c ) { if ( c . status ( ) === 'uploading' ) { c . abort ( ) ; this . flowObj . uploadNextChunk ( ) ; } } , this ) ; }


Input: Clear current chunks and slice file again [CODESPLIT] function ( ) { if ( typeof this . flowObj . opts . initFileFn === "function" ) { this . flowObj . opts . initFileFn ( this ) ; } this . abort ( true ) ; this . error = false ; // Rebuild stack of chunks from file this . _prevProgress = 0 ; var round = this . flowObj . opts . forceChunkSize ? Math . ceil : Math . floor ; var chunks = Math . max ( round ( this . size / this . flowObj . opts . chunkSize ) , 1 ) ; for ( var offset = 0 ; offset < chunks ; offset ++ ) { this . chunks . push ( new FlowChunk ( this . flowObj , this , offset ) ) ; } }


Input: Get current upload progress status [CODESPLIT] function ( ) { if ( this . error ) { return 1 ; } if ( this . chunks . length === 1 ) { this . _prevProgress = Math . max ( this . _prevProgress , this . chunks [ 0 ] . progress ( ) ) ; return this . _prevProgress ; } // Sum up progress across everything var bytesLoaded = 0 ; each ( this . chunks , function ( c ) { // get chunk progress relative to entire file bytesLoaded += c . progress ( ) * ( c . endByte - c . startByte ) ; } ) ; var percent = bytesLoaded / this . size ; // We don't want to lose percentages when an upload is paused this . _prevProgress = Math . max ( this . _prevProgress , percent > 0.9999 ? 1 : percent ) ; return this . _prevProgress ; }


Input: Indicates if file is has finished uploading and received a response [CODESPLIT] function ( ) { var outstanding = false ; each ( this . chunks , function ( chunk ) { var status = chunk . status ( ) ; if ( status === 'pending' || status === 'uploading' || status === 'reading' || chunk . preprocessState === 1 || chunk . readState === 1 ) { outstanding = true ; return false ; } } ) ; return ! outstanding ; }


Input: Returns remaining time to finish upload file in seconds . Accuracy is based on average speed . If speed is zero time remaining will be equal to positive infinity Number . POSITIVE_INFINITY [CODESPLIT] function ( ) { if ( this . paused || this . error ) { return 0 ; } var delta = this . size - this . sizeUploaded ( ) ; if ( delta && ! this . averageSpeed ) { return Number . POSITIVE_INFINITY ; } if ( ! delta && ! this . averageSpeed ) { return 0 ; } return Math . floor ( delta / this . averageSpeed ) ; }


Input: Default read function using the webAPI [CODESPLIT] function webAPIFileRead ( fileObj , startByte , endByte , fileType , chunk ) { var function_name = 'slice' ; if ( fileObj . file . slice ) function_name = 'slice' ; else if ( fileObj . file . mozSlice ) function_name = 'mozSlice' ; else if ( fileObj . file . webkitSlice ) function_name = 'webkitSlice' ; chunk . readFinished ( fileObj . file [ function_name ] ( startByte , endByte , fileType ) ) ; }


Input:
Class for storing a single chunk [CODESPLIT] function FlowChunk ( flowObj , fileObj , offset ) { /**
     * Reference to parent flow object
     * @type {Flow}
     */ this . flowObj = flowObj ; /**
     * Reference to parent FlowFile object
     * @type {FlowFile}
     */ this . fileObj = fileObj ; /**
     * File offset
     * @type {number}
     */ this . offset = offset ; /**
     * Indicates if chunk existence was checked on the server
     * @type {boolean}
     */ this . tested = false ; /**
     * Number of retries performed
     * @type {number}
     */ this . retries = 0 ; /**
     * Pending retry
     * @type {boolean}
     */ this . pendingRetry = false ; /**
     * Preprocess state
     * @type {number} 0 = unprocessed, 1 = processing, 2 = finished
     */ this . preprocessState = 0 ; /**
     * Read state
     * @type {number} 0 = not read, 1 = reading, 2 = finished
     */ this . readState = 0 ; /**
     * Bytes transferred from total request size
     * @type {number}
     */ this . loaded = 0 ; /**
     * Total request size
     * @type {number}
     */ this . total = 0 ; /**
     * Size of a chunk
     * @type {number}
     */ this . chunkSize = this . flowObj . opts . chunkSize ; /**
     * Chunk start byte in a file
     * @type {number}
     */ this . startByte = this . offset * this . chunkSize ; /**
      * Compute the endbyte in a file
      *
      */ this . computeEndByte = function ( ) { var endByte = Math . min ( this . fileObj . size , ( this . offset + 1 ) * this . chunkSize ) ; if ( this . fileObj . size - endByte < this . chunkSize && ! this . flowObj . opts . forceChunkSize ) { // The last chunk will be bigger than the chunk size, // but less than 2 * this.chunkSize endByte = this . fileObj . size ; } return endByte ; } /**
     * Chunk end byte in a file
     * @type {number}
     */ this . endByte = this . computeEndByte ( ) ; /**
     * XMLHttpRequest
     * @type {XMLHttpRequest}
     */ this . xhr = null ; var $ = this ; /**
     * Send chunk event
     * @param event
     * @param {...} args arguments of a callback
     */ this . event = function ( event , args ) { args = Array . prototype . slice . call ( arguments ) ; args . unshift ( $ ) ; $ . fileObj . chunkEvent . apply ( $ . fileObj , args ) ; } ; /**
     * Catch progress event
     * @param {ProgressEvent} event
     */ this . progressHandler = function ( event ) { if ( event . lengthComputable ) { $ . loaded = event . loaded ; $ . total = event . total ; } $ . event ( 'progress' , event ) ; } ; /**
     * Catch test event
     * @param {Event} event
     */ this . testHandler = function ( event ) { var status = $ . status ( true ) ; if ( status === 'error' ) { $ . event ( status , $ . message ( ) ) ; $ . flowObj . uploadNextChunk ( ) ; } else if ( status === 'success' ) { $ . tested = true ; $ . event ( status , $ . message ( ) ) ; $ . flowObj . uploadNextChunk ( ) ; } else if ( ! $ . fileObj . paused ) { // Error might be caused by file pause method // Chunks does not exist on the server side $ . tested = true ; $ . send ( ) ; } } ; /**
     * Upload has stopped
     * @param {Event} event
     */ this . doneHandler = function ( event ) { var status = $ . status ( ) ; if ( status === 'success' || status === 'error' ) { delete this . data ; $ . event ( status , $ . message ( ) ) ; $ . flowObj . uploadNextChunk ( ) ; } else { $ . event ( 'retry' , $ . message ( ) ) ; $ . pendingRetry = true ; $ . abort ( ) ; $ . retries ++ ; var retryInterval = $ . flowObj . opts . chunkRetryInterval ; if ( retryInterval !== null ) { setTimeout ( function ( ) { $ . send ( ) ; } , retryInterval ) ; } else { $ . send ( ) ; } } } ; }


Input: Makes a GET request without any data to see if the chunk has already been uploaded in a previous session [CODESPLIT] function ( ) { // Set up request and listen for event this . xhr = new XMLHttpRequest ( ) ; this . xhr . addEventListener ( "load" , this . testHandler , false ) ; this . xhr . addEventListener ( "error" , this . testHandler , false ) ; var testMethod = evalOpts ( this . flowObj . opts . testMethod , this . fileObj , this ) ; var data = this . prepareXhrRequest ( testMethod , true ) ; this . xhr . send ( data ) ; }


Input: Uploads the actual data in a POST call [CODESPLIT] function ( ) { var preprocess = this . flowObj . opts . preprocess ; var read = this . flowObj . opts . readFileFn ; if ( typeof preprocess === 'function' ) { switch ( this . preprocessState ) { case 0 : this . preprocessState = 1 ; preprocess ( this ) ; return ; case 1 : return ; } } switch ( this . readState ) { case 0 : this . readState = 1 ; read ( this . fileObj , this . startByte , this . endByte , this . fileObj . file . type , this ) ; return ; case 1 : return ; } if ( this . flowObj . opts . testChunks && ! this . tested ) { this . test ( ) ; return ; } this . loaded = 0 ; this . total = 0 ; this . pendingRetry = false ; // Set up request and listen for event this . xhr = new XMLHttpRequest ( ) ; this . xhr . upload . addEventListener ( 'progress' , this . progressHandler , false ) ; this . xhr . addEventListener ( "load" , this . doneHandler , false ) ; this . xhr . addEventListener ( "error" , this . doneHandler , false ) ; var uploadMethod = evalOpts ( this . flowObj . opts . uploadMethod , this . fileObj , this ) ; var data = this . prepareXhrRequest ( uploadMethod , false , this . flowObj . opts . method , this . bytes ) ; this . xhr . send ( data ) ; }


Input: Retrieve current chunk upload status [CODESPLIT] function ( isTest ) { if ( this . readState === 1 ) { return 'reading' ; } else if ( this . pendingRetry || this . preprocessState === 1 ) { // if pending retry then that's effectively the same as actively uploading, // there might just be a slight delay before the retry starts return 'uploading' ; } else if ( ! this . xhr ) { return 'pending' ; } else if ( this . xhr . readyState < 4 ) { // Status is really 'OPENED', 'HEADERS_RECEIVED' // or 'LOADING' - meaning that stuff is happening return 'uploading' ; } else { if ( this . flowObj . opts . successStatuses . indexOf ( this . xhr . status ) > - 1 ) { // HTTP 200, perfect // HTTP 202 Accepted - The request has been accepted for processing, but the processing has not been completed. return 'success' ; } else if ( this . flowObj . opts . permanentErrors . indexOf ( this . xhr . status ) > - 1 || ! isTest && this . retries >= this . flowObj . opts . maxChunkRetries ) { // HTTP 413/415/500/501, permanent error return 'error' ; } else { // this should never happen, but we'll reset and queue a retry // a likely case for this would be 503 service unavailable this . abort ( ) ; return 'pending' ; } } }


Input: Prepare Xhr request . Set query headers and data [CODESPLIT] function ( method , isTest , paramsMethod , blob ) { // Add data from the query options var query = evalOpts ( this . flowObj . opts . query , this . fileObj , this , isTest ) ; query = extend ( query || { } , this . getParams ( ) ) ; var target = evalOpts ( this . flowObj . opts . target , this . fileObj , this , isTest ) ; var data = null ; if ( method === 'GET' || paramsMethod === 'octet' ) { // Add data from the query options var params = [ ] ; each ( query , function ( v , k ) { params . push ( [ encodeURIComponent ( k ) , encodeURIComponent ( v ) ] . join ( '=' ) ) ; } ) ; target = this . getTarget ( target , params ) ; data = blob || null ; } else { // Add data from the query options data = new FormData ( ) ; each ( query , function ( v , k ) { data . append ( k , v ) ; } ) ; if ( typeof blob !== "undefined" ) data . append ( this . flowObj . opts . fileParameterName , blob , this . fileObj . file . name ) ; } this . xhr . open ( method , target , true ) ; this . xhr . withCredentials = this . flowObj . opts . withCredentials ; // Add data from header options each ( evalOpts ( this . flowObj . opts . headers , this . fileObj , this , isTest ) , function ( v , k ) { this . xhr . setRequestHeader ( k , v ) ; } , this ) ; return data ; }


Input: If option is a function evaluate it with given params [CODESPLIT] function evalOpts ( data , args ) { if ( typeof data === "function" ) { // `arguments` is an object, not array, in FF, so: args = Array . prototype . slice . call ( arguments ) ; data = data . apply ( null , args . slice ( 1 ) ) ; } return data ; }


Input: Extends the destination object dst by copying all of the properties from the src object ( s ) to dst . You can specify multiple src objects . [CODESPLIT] function extend ( dst , src ) { each ( arguments , function ( obj ) { if ( obj !== dst ) { each ( obj , function ( value , key ) { dst [ key ] = value ; } ) ; } } ) ; return dst ; }


Input: Iterate each element of an object [CODESPLIT] function each ( obj , callback , context ) { if ( ! obj ) { return ; } var key ; // Is Array? // Array.isArray won't work, not only arrays can be iterated by index https://github.com/flowjs/ng-flow/issues/236# if ( typeof ( obj . length ) !== 'undefined' ) { for ( key = 0 ; key < obj . length ; key ++ ) { if ( callback . call ( context , obj [ key ] , key ) === false ) { return ; } } } else { for ( key in obj ) { if ( obj . hasOwnProperty ( key ) && callback . call ( context , obj [ key ] , key ) === false ) { return ; } } } }


Input: Create a table | a json file The second argument is optional if ommitted the file will be created at the default location . [CODESPLIT] function createTable ( ) { tableName = arguments [ 0 ] ; var fname = '' ; var callback ; if ( arguments . length === 2 ) { callback = arguments [ 1 ] ; fname = path . join ( userData , tableName + '.json' ) ; } else if ( arguments . length === 3 ) { fname = path . join ( arguments [ 1 ] , arguments [ 0 ] + '.json' ) ; callback = arguments [ 2 ] ; } // Check if the file with the tablename.json exists let exists = fs . existsSync ( fname ) ; if ( exists ) { // The file exists, do not recreate the table/json file callback ( false , tableName + '.json already exists!' ) ; return ; } else { // Create an empty object and pass an empty array as value let obj = new Object ( ) ; obj [ tableName ] = [ ] ; // Write the object to json file try { fs . writeFileSync ( fname , JSON . stringify ( obj , null , 2 ) , ( err ) => { } ) callback ( true , "Success!" ) return ; } catch ( e ) { callback ( false , e . toString ( ) ) ; return ; } } }


Input: Checks if a json file contains valid JSON string [CODESPLIT] function valid ( ) { var fName = '' if ( arguments . length == 2 ) { // Given the database name and location const dbName = arguments [ 0 ] const dbLocation = arguments [ 1 ] var fName = path . join ( dbLocation , dbName + '.json' ) } else if ( arguments . length == 1 ) { const dbName = arguments [ 0 ] fname = path . join ( userData , dbName + '.json' ) } const content = fs . readFileSync ( fName , 'utf-8' ) try { JSON . parse ( content ) } catch ( e ) { return false } return true }


Input: Insert object to table . The object will be appended with the property id which uses timestamp as value . There are 3 required arguments . [CODESPLIT] function insertTableContent ( ) { let tableName = arguments [ 0 ] ; var fname = '' ; var callback ; var tableRow ; if ( arguments . length === 3 ) { callback = arguments [ 2 ] ; fname = path . join ( userData , arguments [ 0 ] + '.json' ) ; tableRow = arguments [ 1 ] ; } else if ( arguments . length === 4 ) { fname = path . join ( arguments [ 1 ] , arguments [ 0 ] + '.json' ) ; callback = arguments [ 3 ] ; tableRow = arguments [ 2 ] ; } let exists = fs . existsSync ( fname ) ; if ( exists ) { // Table | json parsed let table = JSON . parse ( fs . readFileSync ( fname ) ) ; let date = new Date ( ) ; let id = date . getTime ( ) ; tableRow [ 'id' ] = id ; table [ tableName ] . push ( tableRow ) ; try { fs . writeFileSync ( fname , JSON . stringify ( table , null , 2 ) , ( err ) => { } ) callback ( true , "Object written successfully!" ) ; return ; } catch ( e ) { callback ( false , "Error writing object." ) ; return ; } } callback ( false , "Table/json file doesn't exist!" ) ; return ; }


Input: Get all contents of the table / json file object [CODESPLIT] function getAll ( ) { var fname = '' ; var callback ; var tableName = arguments [ 0 ] ; if ( arguments . length === 2 ) { fname = path . join ( userData , tableName + '.json' ) ; callback = arguments [ 1 ] ; } else if ( arguments . length === 3 ) { fname = path . join ( arguments [ 1 ] , arguments [ 0 ] + '.json' ) ; callback = arguments [ 2 ] ; } let exists = fs . existsSync ( fname ) ; if ( exists ) { try { let table = JSON . parse ( fs . readFileSync ( fname ) ) ; callback ( true , table [ tableName ] ) ; return ; } catch ( e ) { callback ( false , [ ] ) ; return ; } } else { callback ( false , 'Table file does not exist!' ) ; return ; } }


Input: Find rows of a given field / key . [CODESPLIT] function getField ( ) { let fname = '' let tableName = arguments [ 0 ] let callback let key if ( arguments . length === 3 ) { fname = path . join ( userData , tableName + '.json' ) ; callback = arguments [ 2 ] ; key = arguments [ 1 ] } else if ( arguments . length === 4 ) { fname = path . join ( arguments [ 1 ] , arguments [ 0 ] + '.json' ) ; callback = arguments [ 3 ] ; key = arguments [ 2 ] } let exists = fs . existsSync ( fname ) if ( exists ) { let table = JSON . parse ( fs . readFileSync ( fname ) ) ; const rows = table [ tableName ] let data = [ ] for ( let i = 0 ; i < rows . length ; i ++ ) { if ( rows [ i ] . hasOwnProperty ( key ) ) { data . push ( rows [ i ] [ key ] ) } } callback ( true , data ) } else { callback ( false , 'The table you are trying to access does not exist.' ) return } }


Input: Count the number of rows for a given table . [CODESPLIT] function count ( ) { let tableName = arguments [ 0 ] let callback if ( arguments . length === 2 ) { callback = arguments [ 1 ] getAll ( tableName , ( succ , data ) => { if ( succ ) { callback ( true , data . length ) return } else { callback ( false , data ) return } } ) } else if ( arguments . length === 3 ) { callback = arguments [ 2 ] getAll ( tableName , arguments [ 1 ] , ( succ , data ) => { if ( succ ) { callback ( true , data . length ) return } else { callback ( false , data ) return } } ) } else { callback ( false , 'Wrong number of arguments. Must be either 2 or 3 arguments including callback function.' ) return } }


Input: Get row or rows that matched the given condition ( s ) in WHERE argument [CODESPLIT] function getRows ( ) { let tableName = arguments [ 0 ] ; var fname = '' ; var callback ; var where ; if ( arguments . length === 3 ) { fname = path . join ( userData , tableName + '.json' ) ; where = arguments [ 1 ] ; callback = arguments [ 2 ] ; } else if ( arguments . length === 4 ) { fname = path . join ( arguments [ 1 ] , arguments [ 0 ] + '.json' ) ; where = arguments [ 2 ] ; callback = arguments [ 3 ] ; } let exists = fs . existsSync ( fname ) ; let whereKeys ; // Check if where is an object if ( Object . prototype . toString . call ( where ) === "[object Object]" ) { // Check for number of keys whereKeys = Object . keys ( where ) ; if ( whereKeys === 0 ) { callback ( false , "There are no conditions passed to the WHERE clause." ) ; return ; } } else { callback ( false , "WHERE clause should be an object." ) ; return ; } // Check if the json file exists, if it is, parse it. if ( exists ) { try { let table = JSON . parse ( fs . readFileSync ( fname ) ) ; let rows = table [ tableName ] ; let objs = [ ] ; for ( let i = 0 ; i < rows . length ; i ++ ) { let matched = 0 ; // Number of matched complete where clause for ( var j = 0 ; j < whereKeys . length ; j ++ ) { // Test if there is a matched key with where clause if ( rows [ i ] . hasOwnProperty ( whereKeys [ j ] ) ) { if ( rows [ i ] [ whereKeys [ j ] ] === where [ whereKeys [ j ] ] ) { matched ++ ; } } } // Check if all conditions in the WHERE clause are matched if ( matched === whereKeys . length ) { objs . push ( rows [ i ] ) } } callback ( true , objs ) ; return ; } catch ( e ) { callback ( false , e . toString ( ) ) ; return ; } } else { callback ( false , 'Table file does not exist!' ) ; return ; } }


Input: Update a row or record which satisfies the where clause [CODESPLIT] function updateRow ( ) { let tableName = arguments [ 0 ] ; var fname = '' ; var where ; var set ; var callback ; if ( arguments . length === 4 ) { fname = path . join ( userData , tableName + '.json' ) ; where = arguments [ 1 ] ; set = arguments [ 2 ] ; callback = arguments [ 3 ] ; } else if ( arguments . length === 5 ) { fname = path . join ( arguments [ 1 ] , arguments [ 0 ] + '.json' ) ; where = arguments [ 2 ] ; set = arguments [ 3 ] ; callback = arguments [ 4 ] ; } let exists = fs . existsSync ( fname ) ; let whereKeys = Object . keys ( where ) ; let setKeys = Object . keys ( set ) ; if ( exists ) { let table = JSON . parse ( fs . readFileSync ( fname ) ) ; let rows = table [ tableName ] ; let matched = 0 ; // Number of matched complete where clause let matchedIndex = 0 ; for ( var i = 0 ; i < rows . length ; i ++ ) { for ( var j = 0 ; j < whereKeys . length ; j ++ ) { // Test if there is a matched key with where clause and single row of table if ( rows [ i ] . hasOwnProperty ( whereKeys [ j ] ) ) { if ( rows [ i ] [ whereKeys [ j ] ] === where [ whereKeys [ j ] ] ) { matched ++ ; matchedIndex = i ; } } } } if ( matched === whereKeys . length ) { // All field from where clause are present in this particular // row of the database table try { for ( var k = 0 ; k < setKeys . length ; k ++ ) { // rows[i][setKeys[k]] = set[setKeys[k]]; rows [ matchedIndex ] [ setKeys [ k ] ] = set [ setKeys [ k ] ] ; } // Create a new object and pass the rows let obj = new Object ( ) ; obj [ tableName ] = rows ; // Write the object to json file try { fs . writeFileSync ( fname , JSON . stringify ( obj , null , 2 ) , ( err ) => { } ) callback ( true , "Success!" ) return ; } catch ( e ) { callback ( false , e . toString ( ) ) ; return ; } callback ( true , rows ) ; } catch ( e ) { callback ( false , e . toString ( ) ) ; return ; } } else { callback ( false , "Cannot find the specified record." ) ; return ; } } else { callback ( false , 'Table file does not exist!' ) ; return ; } }


Input: Searching function [CODESPLIT] function search ( ) { let tableName = arguments [ 0 ] ; var fname = '' ; var field ; var keyword ; var callback ; if ( arguments . length === 4 ) { fname = path . join ( userData , tableName + '.json' ) ; field = arguments [ 1 ] ; keyword = arguments [ 2 ] ; callback = arguments [ 3 ] ; } else if ( arguments . length === 5 ) { fname = path . join ( arguments [ 1 ] , arguments [ 0 ] + '.json' ) ; field = arguments [ 2 ] ; keyword = arguments [ 3 ] ; callback = arguments [ 4 ] ; } let exists = fs . existsSync ( fname ) ; if ( exists ) { let table = JSON . parse ( fs . readFileSync ( fname ) ) ; let rows = table [ tableName ] ; if ( rows . length > 0 ) { // Declare an empty list let foundRows = [ ] ; for ( var i = 0 ; i < rows . length ; i ++ ) { // Check if key exists if ( rows [ i ] . hasOwnProperty ( field ) ) { // Make sure that an object is converted to string before // applying toLowerCase() let value = rows [ i ] [ field ] . toString ( ) . toLowerCase ( ) ; let n = value . search ( keyword . toString ( ) . toLowerCase ( ) ) ; if ( n !== - 1 ) { // The substring is found, add object to the list. foundRows . push ( rows [ i ] ) ; } } else { callback ( false , 2 ) ; return ; } } callback ( true , foundRows ) ; return ; } else { callback ( false , [ ] ) ; return ; } } else { callback ( false , 'Table file does not exist!' ) ; return ; } }


Input: Create a getter for the given header name . [CODESPLIT] function createHeaderGetter ( str ) { var name = str . toLowerCase ( ) return function ( req , res ) { // set appropriate Vary header vary ( res , str ) // get header var header = req . headers [ name ] if ( ! header ) { return undefined } // multiple headers get joined with comma by node.js core var index = header . indexOf ( ',' ) // return first value return index !== - 1 ? header . substr ( 0 , index ) . trim ( ) : header . trim ( ) } }


Input: Assign key value to target when value is not null . <br > This function mutates the target! [CODESPLIT] function assignNotNull ( target , ... sources ) { sources . forEach ( source => { Object . keys ( source ) . forEach ( key => { if ( source [ key ] != null ) { target [ key ] = source [ key ] ; } } ) } ) ; return target ; }


Input: Layer [CODESPLIT] function Layer ( options ) { this . options = { } ; if ( options != null ) { [ "resourceType" , "type" , "publicId" , "format" ] . forEach ( ( function ( _this ) { return function ( key ) { var ref ; return _this . options [ key ] = ( ref = options [ key ] ) != null ? ref : options [ Util . snakeCase ( key ) ] ; } ; } ) ( this ) ) ; } }


Input:
Represents a single parameter [CODESPLIT] function Param ( name , shortName , process ) { if ( process == null ) { process = cloudinary . Util . identity ; } /**
       * The name of the parameter in snake_case
       * @member {string} Param#name
       */ this . name = name ; /**
       * The name of the serialized form of the parameter
       * @member {string} Param#shortName
       */ this . shortName = shortName ; /**
       * Manipulate origValue when value is called
       * @member {function} Param#process
       */ this . process = process ; }


Input: A parameter that represents an array [CODESPLIT] function ArrayParam ( name , shortName , sep , process ) { if ( sep == null ) { sep = '.' ; } this . sep = sep ; ArrayParam . __super__ . constructor . call ( this , name , shortName , process ) ; }


Input: A parameter that represents a transformation [CODESPLIT] function TransformationParam ( name , shortName , sep , process ) { if ( shortName == null ) { shortName = "t" ; } if ( sep == null ) { sep = '.' ; } this . sep = sep ; TransformationParam . __super__ . constructor . call ( this , name , shortName , process ) ; }


Input: A parameter that represents a range [CODESPLIT] function RangeParam ( name , shortName , process ) { if ( process == null ) { process = this . norm_range_value ; } RangeParam . __super__ . constructor . call ( this , name , shortName , process ) ; }


Input:
Represents a transformation expression @param { string } expressionStr - a expression in string format @class Expression [CODESPLIT] function Expression ( expressionStr ) { /**
        * @protected
        * @inner Expression-expressions
       */ this . expressions = [ ] ; if ( expressionStr != null ) { this . expressions . push ( Expression . normalize ( expressionStr ) ) ; } }


Input: Cloudinary configuration class [CODESPLIT] function Configuration ( options ) { if ( options == null ) { options = { } ; } this . configuration = Util . cloneDeep ( options ) ; Util . defaults ( this . configuration , DEFAULT_CONFIGURATION_PARAMS ) ; }


Input:
The base class for transformations . Members of this class are documented as belonging to the { [CODESPLIT] function TransformationBase ( options ) { var parent , trans ; if ( options == null ) { options = { } ; } /** @private */ parent = void 0 ; /** @private */ trans = { } ; /**
       * Return an options object that can be used to create an identical Transformation
       * @function Transformation#toOptions
       * @return {Object} Returns a plain object representing this transformation
       */ this . toOptions || ( this . toOptions = function ( withChain ) { var key , list , opt , ref , ref1 , tr , value ; if ( withChain == null ) { withChain = true ; } opt = { } ; for ( key in trans ) { value = trans [ key ] ; opt [ key ] = value . origValue ; } ref = this . otherOptions ; for ( key in ref ) { value = ref [ key ] ; if ( value !== void 0 ) { opt [ key ] = value ; } } if ( withChain && ! Util . isEmpty ( this . chained ) ) { list = ( function ( ) { var j , len , ref1 , results ; ref1 = this . chained ; results = [ ] ; for ( j = 0 , len = ref1 . length ; j < len ; j ++ ) { tr = ref1 [ j ] ; results . push ( tr . toOptions ( ) ) ; } return results ; } ) . call ( this ) ; list . push ( opt ) ; opt = { } ; ref1 = this . otherOptions ; for ( key in ref1 ) { value = ref1 [ key ] ; if ( value !== void 0 ) { opt [ key ] = value ; } } opt . transformation = list ; } return opt ; } ) ; /**
       * Set a parent for this object for chaining purposes.
       *
       * @function Transformation#setParent
       * @param {Object} object - the parent to be assigned to
       * @returns {Transformation} Returns this instance for chaining purposes.
       */ this . setParent || ( this . setParent = function ( object ) { parent = object ; if ( object != null ) { this . fromOptions ( typeof object . toOptions === "function" ? object . toOptions ( ) : void 0 ) ; } return this ; } ) ; /**
       * Returns the parent of this object in the chain
       * @function Transformation#getParent
       * @protected
       * @return {Object} Returns the parent of this object if there is any
       */ this . getParent || ( this . getParent = function ( ) { return parent ; } ) ; /** @protected */ this . param || ( this . param = function ( value , name , abbr , defaultValue , process ) { if ( process == null ) { if ( Util . isFunction ( defaultValue ) ) { process = defaultValue ; } else { process = Util . identity ; } } trans [ name ] = new Param ( name , abbr , process ) . set ( value ) ; return this ; } ) ; /** @protected */ this . rawParam || ( this . rawParam = function ( value , name , abbr , defaultValue , process ) { if ( process == null ) { process = Util . identity ; } process = lastArgCallback ( arguments ) ; trans [ name ] = new RawParam ( name , abbr , process ) . set ( value ) ; return this ; } ) ; /** @protected */ this . rangeParam || ( this . rangeParam = function ( value , name , abbr , defaultValue , process ) { if ( process == null ) { process = Util . identity ; } process = lastArgCallback ( arguments ) ; trans [ name ] = new RangeParam ( name , abbr , process ) . set ( value ) ; return this ; } ) ; /** @protected */ this . arrayParam || ( this . arrayParam = function ( value , name , abbr , sep , defaultValue , process ) { if ( sep == null ) { sep = ":" ; } if ( defaultValue == null ) { defaultValue = [ ] ; } if ( process == null ) { process = Util . identity ; } process = lastArgCallback ( arguments ) ; trans [ name ] = new ArrayParam ( name , abbr , sep , process ) . set ( value ) ; return this ; } ) ; /** @protected */ this . transformationParam || ( this . transformationParam = function ( value , name , abbr , sep , defaultValue , process ) { if ( sep == null ) { sep = "." ; } if ( process == null ) { process = Util . identity ; } process = lastArgCallback ( arguments ) ; trans [ name ] = new TransformationParam ( name , abbr , sep , process ) . set ( value ) ; return this ; } ) ; this . layerParam || ( this . layerParam = function ( value , name , abbr ) { trans [ name ] = new LayerParam ( name , abbr ) . set ( value ) ; return this ; } ) ; /**
       * Get the value associated with the given name.
       * @function Transformation#getValue
       * @param {string} name - the name of the parameter
       * @return {*} the processed value associated with the given name
       * @description Use {@link get}.origValue for the value originally provided for the parameter
       */ this . getValue || ( this . getValue = function ( name ) { var ref , ref1 ; return ( ref = ( ref1 = trans [ name ] ) != null ? ref1 . value ( ) : void 0 ) != null ? ref : this . otherOptions [ name ] ; } ) ; /**
       * Get the parameter object for the given parameter name
       * @function Transformation#get
       * @param {string} name the name of the transformation parameter
       * @returns {Param} the param object for the given name, or undefined
       */ this . get || ( this . get = function ( name ) { return trans [ name ] ; } ) ; /**
       * Remove a transformation option from the transformation.
       * @function Transformation#remove
       * @param {string} name - the name of the option to remove
       * @return {*} Returns the option that was removed or null if no option by that name was found. The type of the
       *              returned value depends on the value.
       */ this . remove || ( this . remove = function ( name ) { var temp ; switch ( false ) { case trans [ name ] == null : temp = trans [ name ] ; delete trans [ name ] ; return temp . origValue ; case this . otherOptions [ name ] == null : temp = this . otherOptions [ name ] ; delete this . otherOptions [ name ] ; return temp ; default : return null ; } } ) ; /**
       * Return an array of all the keys (option names) in the transformation.
       * @return {Array<string>} the keys in snakeCase format
       */ this . keys || ( this . keys = function ( ) { var key ; return ( ( function ( ) { var results ; results = [ ] ; for ( key in trans ) { if ( key != null ) { results . push ( key . match ( VAR_NAME_RE ) ? key : Util . snakeCase ( key ) ) ; } } return results ; } ) ( ) ) . sort ( ) ; } ) ; /**
       * Returns a plain object representation of the transformation. Values are processed.
       * @function Transformation#toPlainObject
       * @return {Object} the transformation options as plain object
       */ this . toPlainObject || ( this . toPlainObject = function ( ) { var hash , key , list , tr ; hash = { } ; for ( key in trans ) { hash [ key ] = trans [ key ] . value ( ) ; if ( Util . isPlainObject ( hash [ key ] ) ) { hash [ key ] = Util . cloneDeep ( hash [ key ] ) ; } } if ( ! Util . isEmpty ( this . chained ) ) { list = ( function ( ) { var j , len , ref , results ; ref = this . chained ; results = [ ] ; for ( j = 0 , len = ref . length ; j < len ; j ++ ) { tr = ref [ j ] ; results . push ( tr . toPlainObject ( ) ) ; } return results ; } ) . call ( this ) ; list . push ( hash ) ; hash = { transformation : list } ; } return hash ; } ) ; /**
       * Complete the current transformation and chain to a new one.
       * In the URL, transformations are chained together by slashes.
       * @function Transformation#chain
       * @return {Transformation} Returns this transformation for chaining
       * @example
       * var tr = cloudinary.Transformation.new();
       * tr.width(10).crop('fit').chain().angle(15).serialize()
       * // produces "c_fit,w_10/a_15"
       */ this . chain || ( this . chain = function ( ) { var names , tr ; names = Object . getOwnPropertyNames ( trans ) ; if ( names . length !== 0 ) { tr = new this . constructor ( this . toOptions ( false ) ) ; this . resetTransformations ( ) ; this . chained . push ( tr ) ; } return this ; } ) ; this . resetTransformations || ( this . resetTransformations = function ( ) { trans = { } ; return this ; } ) ; this . otherOptions || ( this . otherOptions = { } ) ; this . chained = [ ] ; if ( ! Util . isEmpty ( options ) ) { this . fromOptions ( options ) ; } }


Input: Represents a single transformation . @class Transformation @example t = new cloudinary . Transformation () ; t . angle ( 20 ) . crop ( scale ) . width ( auto ) ; [CODESPLIT] function Transformation ( options ) { if ( options == null ) { options = { } ; } Transformation . __super__ . constructor . call ( this , options ) ; this ; }


Input: Creates an HTML ( DOM ) Image tag using Cloudinary as the source . [CODESPLIT] function ImageTag ( publicId , options ) { if ( options == null ) { options = { } ; } ImageTag . __super__ . constructor . call ( this , "img" , publicId , options ) ; }


Input: Creates an HTML ( DOM ) Video tag using Cloudinary as the source . [CODESPLIT] function VideoTag ( publicId , options ) { if ( options == null ) { options = { } ; } options = Util . defaults ( { } , options , Cloudinary . DEFAULT_VIDEO_PARAMS ) ; VideoTag . __super__ . constructor . call ( this , "video" , publicId . replace ( / \.(mp4|ogv|webm)$ / , '' ) , options ) ; }


Input: Creates an HTML ( DOM ) Meta tag that enables client - hints . [CODESPLIT] function ClientHintsMetaTag ( options ) { ClientHintsMetaTag . __super__ . constructor . call ( this , 'meta' , void 0 , Util . assign ( { "http-equiv" : "Accept-CH" , content : "DPR, Viewport-Width, Width" } , options ) ) ; }


Input:
Main Cloudinary class [CODESPLIT] function Cloudinary ( options ) { var configuration ; this . devicePixelRatioCache = { } ; this . responsiveConfig = { } ; this . responsiveResizeInitialized = false ; configuration = new Configuration ( options ) ; this . config = function ( newConfig , newValue ) { return configuration . config ( newConfig , newValue ) ; } ; /**
       * Use \<meta\> tags in the document to configure this Cloudinary instance.
       * @return {Cloudinary} this for chaining
       */ this . fromDocument = function ( ) { configuration . fromDocument ( ) ; return this ; } ; /**
       * Use environment variables to configure this Cloudinary instance.
       * @return {Cloudinary} this for chaining
       */ this . fromEnvironment = function ( ) { configuration . fromEnvironment ( ) ; return this ; } ; /**
       * Initialize configuration.
       * @function Cloudinary#init
       * @see Configuration#init
       * @return {Cloudinary} this for chaining
       */ this . init = function ( ) { configuration . init ( ) ; return this ; } ; }


Input: Determine the build mode . [CODESPLIT] function getMode ( env , argv ) { // When running from parallel-webpack, grab the cli parameters argv = Object . keys ( argv ) . length ? argv : require ( 'minimist' ) ( process . argv . slice ( 2 ) ) ; var isProd = ( argv . mode || env . mode ) === 'production' || env === 'prod' || env . prod ; return isProd ? 'production' : 'development' ; }


Input: This function is used by webpack to resolve individual lodash modules [CODESPLIT] function resolveLodash ( context , request , callback ) { if ( / ^lodash\/ / . test ( request ) ) { callback ( null , { commonjs : request , commonjs2 : request , amd : request , root : [ '_' , request . split ( '/' ) [ 1 ] ] } ) ; } else { callback ( ) ; } }


Input: Generate a webpack configuration [CODESPLIT] function baseConfig ( name , mode ) { const config = { name : ` ${ name } ${ mode } ` , mode , output : { library : 'cloudinary' , libraryTarget : 'umd' , globalObject : "this" , pathinfo : false } , optimization : { concatenateModules : true , moduleIds : 'named' , usedExports : true , minimizer : [ new TerserPlugin ( { terserOptions : { mangle : { keep_classnames : true , reserved : reserved , ie8 : true } } , } ) ] } , resolve : { extensions : [ '.js' ] } , externals : [ { jquery : 'jQuery' } ] , node : { Buffer : false , process : false } , devtool : "source-map" , module : { rules : [ { test : / \.m?js$ / , exclude : / (node_modules|bower_components) / , use : { loader : 'babel-loader' } } ] } , plugins : [ new webpack . BannerPlugin ( { banner : ` ${ version } ` , // the banner as string or function, it will be wrapped in a comment raw : true , // if true, banner will not be wrapped in a comment entryOnly : true , // if true, the banner will only be added to the entry chunks } ) ] } ; let filename = ` ${ name } ` ; if ( mode === 'production' ) { filename += '.min' ; } const util = name . startsWith ( 'jquery' ) ? 'jquery' : 'lodash' ; const utilPath = path . resolve ( __dirname , ` ${ util } ` ) ; config . output . filename = ` ${ filename } ` ; config . entry = ` ${ name } ` ; config . resolve . alias = { "../util$" : utilPath , "./util$" : utilPath } ; // Add reference to each lodash function as a separate module. if ( name === 'core' ) { config . externals . push ( resolveLodash ) ; } config . plugins . push ( new BundleAnalyzerPlugin ( { analyzerMode : 'static' , reportFilename : ` ${ filename } ` , openAnalyzer : false } ) ) ; return config ; }


Input: * cdn_subdomain - Boolean ( default : false ) . Whether to automatically build URLs with multiple CDN sub - domains . See this blog post for more details . * private_cdn - Boolean ( default : false ) . Should be set to true for Advanced plan s users that have a private CDN distribution . * secure_distribution - The domain name of the CDN distribution to use for building HTTPS URLs . Relevant only for Advanced plan s users that have a private CDN distribution . * cname - Custom domain name to use for building HTTP URLs . Relevant only for Advanced plan s users that have a private CDN distribution and a custom CNAME . * secure - Boolean ( default : false ) . Force HTTPS URLs of images even if embedded in non - secure HTTP pages . [CODESPLIT] function cloudinaryUrlPrefix ( publicId , options ) { var cdnPart , host , path , protocol , ref , subdomain ; if ( ( ( ref = options . cloud_name ) != null ? ref . indexOf ( "/" ) : void 0 ) === 0 ) { return '/res' + options . cloud_name ; } // defaults protocol = "http://" ; cdnPart = "" ; subdomain = "res" ; host = ".cloudinary.com" ; path = "/" + options . cloud_name ; // modifications if ( options . protocol ) { protocol = options . protocol + '//' ; } if ( options . private_cdn ) { cdnPart = options . cloud_name + "-" ; path = "" ; } if ( options . cdn_subdomain ) { subdomain = "res-" + cdnSubdomainNumber ( publicId ) ; } if ( options . secure ) { protocol = "https://" ; if ( options . secure_cdn_subdomain === false ) { subdomain = "res" ; } if ( ( options . secure_distribution != null ) && options . secure_distribution !== OLD_AKAMAI_SHARED_CDN && options . secure_distribution !== SHARED_CDN ) { cdnPart = "" ; subdomain = "" ; host = options . secure_distribution ; } } else if ( options . cname ) { protocol = "http://" ; cdnPart = "" ; subdomain = options . cdn_subdomain ? 'a' + ( ( crc32 ( publicId ) % 5 ) + 1 ) + '.' : '' ; host = options . cname ; } return [ protocol , cdnPart , subdomain , host , path ] . join ( "" ) ; }


Input: Return the resource type and action type based on the given configuration [CODESPLIT] function finalizeResourceType ( resourceType = "image" , type = "upload" , urlSuffix , useRootPath , shorten ) { var options ; resourceType = resourceType == null ? "image" : resourceType ; type = type == null ? "upload" : type ; if ( isPlainObject ( resourceType ) ) { options = resourceType ; resourceType = options . resource_type ; type = options . type ; urlSuffix = options . url_suffix ; useRootPath = options . use_root_path ; shorten = options . shorten ; } if ( type == null ) { type = 'upload' ; } if ( urlSuffix != null ) { resourceType = SEO_TYPES [ ` ${ resourceType } ${ type } ` ] ; type = null ; if ( resourceType == null ) { throw new Error ( ` ${ Object . keys ( SEO_TYPES ) . join ( ', ' ) } ` ) ; } } if ( useRootPath ) { if ( resourceType === 'image' && type === 'upload' || resourceType === "images" ) { resourceType = null ; type = null ; } else { throw new Error ( "Root path only supported for image/upload" ) ; } } if ( shorten && resourceType === 'image' && type === 'upload' ) { resourceType = 'iu' ; type = null ; } return [ resourceType , type ] . join ( "/" ) ; }


Input: @private @param { Viewport } parent @param { object } [ options ] @param { number } [ options . percent = 0 . 1 ] percent to scroll with each spin @param { number } [ options . smooth ] smooth the zooming by providing the number of frames to zoom between wheel spins @param { boolean } [ options . interrupt = true ] stop smoothing with any user input on the viewport @param { boolean } [ options . reverse ] reverse the direction of the scroll @param { PIXI . Point } [ options . center ] place this point at center during zoom instead of current mouse position [CODESPLIT] function Wheel ( parent , options ) { _classCallCheck ( this , Wheel ) ; var _this = _possibleConstructorReturn ( this , ( Wheel . __proto__ || Object . getPrototypeOf ( Wheel ) ) . call ( this , parent ) ) ; options = options || { } ; _this . percent = options . percent || 0.1 ; _this . center = options . center ; _this . reverse = options . reverse ; _this . smooth = options . smooth ; _this . interrupt = typeof options . interrupt === 'undefined' ? true : options . interrupt ; return _this ; }


Input: Scroll viewport when mouse hovers near one of the edges . @private @param { Viewport } parent @param { object } [ options ] @param { number } [ options . radius ] distance from center of screen in screen pixels @param { number } [ options . distance ] distance from all sides in screen pixels @param { number } [ options . top ] alternatively set top distance ( leave unset for no top scroll ) @param { number } [ options . bottom ] alternatively set bottom distance ( leave unset for no top scroll ) @param { number } [ options . left ] alternatively set left distance ( leave unset for no top scroll ) @param { number } [ options . right ] alternatively set right distance ( leave unset for no top scroll ) @param { number } [ options . speed = 8 ] speed in pixels / frame to scroll viewport @param { boolean } [ options . reverse ] reverse direction of scroll @param { boolean } [ options . noDecelerate ] don t use decelerate plugin even if it s installed @param { boolean } [ options . linear ] if using radius use linear movement ( + / - 1 + / - 1 ) instead of angled movement ( Math . cos ( angle from center ) Math . sin ( angle from center )) @param { boolean } [ options . allowButtons ] allows plugin to continue working even when there s a mousedown event [CODESPLIT] function MouseEdges ( parent , options ) { _classCallCheck ( this , MouseEdges ) ; var _this = _possibleConstructorReturn ( this , ( MouseEdges . __proto__ || Object . getPrototypeOf ( MouseEdges ) ) . call ( this , parent ) ) ; options = options || { } ; _this . options = options ; _this . reverse = options . reverse ? 1 : - 1 ; _this . noDecelerate = options . noDecelerate ; _this . linear = options . linear ; _this . radiusSquared = Math . pow ( options . radius , 2 ) ; _this . resize ( ) ; _this . speed = options . speed || 8 ; return _this ; }


Input: enable one - finger touch to drag [CODESPLIT] function Drag ( parent , options ) { _classCallCheck ( this , Drag ) ; options = options || { } ; var _this = _possibleConstructorReturn ( this , ( Drag . __proto__ || Object . getPrototypeOf ( Drag ) ) . call ( this , parent ) ) ; _this . moved = false ; _this . wheelActive = utils . defaults ( options . wheel , true ) ; _this . wheelScroll = options . wheelScroll || 1 ; _this . reverse = options . reverse ? 1 : - 1 ; _this . clampWheel = options . clampWheel ; _this . factor = options . factor || 1 ; _this . xDirection = ! options . direction || options . direction === 'all' || options . direction === 'x' ; _this . yDirection = ! options . direction || options . direction === 'all' || options . direction === 'y' ; _this . parseUnderflow ( options . underflow || 'center' ) ; _this . mouseButtons ( options . mouseButtons ) ; return _this ; }


Input: @private @param { Viewport } parent @param { object } [ options ] @param { number } [ options . width ] the desired width to snap ( to maintain aspect ratio choose only width or height ) @param { number } [ options . height ] the desired height to snap ( to maintain aspect ratio choose only width or height ) @param { number } [ options . time = 1000 ] @param { string|function } [ options . ease = easeInOutSine ] ease function or name ( see http : // easings . net / for supported names ) @param { PIXI . Point } [ options . center ] place this point at center during zoom instead of center of the viewport @param { boolean } [ options . interrupt = true ] pause snapping with any user input on the viewport @param { boolean } [ options . removeOnComplete ] removes this plugin after snapping is complete @param { boolean } [ options . removeOnInterrupt ] removes this plugin if interrupted by any user input @param { boolean } [ options . forceStart ] starts the snap immediately regardless of whether the viewport is at the desired zoom @param { boolean } [ options . noMove ] zoom but do not move [CODESPLIT] function SnapZoom ( parent , options ) { _classCallCheck ( this , SnapZoom ) ; var _this = _possibleConstructorReturn ( this , ( SnapZoom . __proto__ || Object . getPrototypeOf ( SnapZoom ) ) . call ( this , parent ) ) ; options = options || { } ; _this . width = options . width ; _this . height = options . height ; if ( _this . width > 0 ) { _this . x_scale = parent . _screenWidth / _this . width ; } if ( _this . height > 0 ) { _this . y_scale = parent . _screenHeight / _this . height ; } _this . xIndependent = utils . exists ( _this . x_scale ) ; _this . yIndependent = utils . exists ( _this . y_scale ) ; _this . x_scale = _this . xIndependent ? _this . x_scale : _this . y_scale ; _this . y_scale = _this . yIndependent ? _this . y_scale : _this . x_scale ; _this . time = utils . defaults ( options . time , 1000 ) ; _this . ease = utils . ease ( options . ease , 'easeInOutSine' ) ; _this . center = options . center ; _this . noMove = options . noMove ; _this . stopOnResize = options . stopOnResize ; _this . removeOnInterrupt = options . removeOnInterrupt ; _this . removeOnComplete = utils . defaults ( options . removeOnComplete , true ) ; _this . interrupt = utils . defaults ( options . interrupt , true ) ; if ( _this . time === 0 ) { parent . container . scale . x = _this . x_scale ; parent . container . scale . y = _this . y_scale ; if ( _this . removeOnComplete ) { _this . parent . removePlugin ( 'snap-zoom' ) ; } } else if ( options . forceStart ) { _this . createSnapping ( ) ; } return _this ; }


Input: @private @param { Viewport } parent @param { number } x @param { number } y @param { object } [ options ] @param { boolean } [ options . topLeft ] snap to the top - left of viewport instead of center @param { number } [ options . friction = 0 . 8 ] friction / frame to apply if decelerate is active @param { number } [ options . time = 1000 ] @param { string|function } [ options . ease = easeInOutSine ] ease function or name ( see http : // easings . net / for supported names ) @param { boolean } [ options . interrupt = true ] pause snapping with any user input on the viewport @param { boolean } [ options . removeOnComplete ] removes this plugin after snapping is complete @param { boolean } [ options . removeOnInterrupt ] removes this plugin if interrupted by any user input @param { boolean } [ options . forceStart ] starts the snap immediately regardless of whether the viewport is at the desired location [CODESPLIT] function Snap ( parent , x , y , options ) { _classCallCheck ( this , Snap ) ; var _this = _possibleConstructorReturn ( this , ( Snap . __proto__ || Object . getPrototypeOf ( Snap ) ) . call ( this , parent ) ) ; options = options || { } ; _this . friction = options . friction || 0.8 ; _this . time = options . time || 1000 ; _this . ease = utils . ease ( options . ease , 'easeInOutSine' ) ; _this . x = x ; _this . y = y ; _this . topLeft = options . topLeft ; _this . interrupt = utils . defaults ( options . interrupt , true ) ; _this . removeOnComplete = options . removeOnComplete ; _this . removeOnInterrupt = options . removeOnInterrupt ; if ( options . forceStart ) { _this . startEase ( ) ; } return _this ; }


Input: Array - like iteration for objects . [CODESPLIT] function each ( object , fn ) { keys ( object ) . forEach ( function ( key ) { return fn ( object [ key ] , key ) ; } ) ; }


Input: Array - like reduce for objects . [CODESPLIT] function reduce ( object , fn ) { var initial = arguments . length > 2 && arguments [ 2 ] !== undefined ? arguments [ 2 ] : 0 ; return keys ( object ) . reduce ( function ( accum , key ) { return fn ( accum , object [ key ] , key ) ; } , initial ) ; }


Input: Object . assign - style object shallow merge / extend . [CODESPLIT] function assign ( target ) { for ( var _len = arguments . length , sources = Array ( _len > 1 ? _len - 1 : 0 ) , _key = 1 ; _key < _len ; _key ++ ) { sources [ _key - 1 ] = arguments [ _key ] ; } if ( Object . assign ) { return Object . assign . apply ( Object , [ target ] . concat ( sources ) ) ; } sources . forEach ( function ( source ) { if ( ! source ) { return ; } each ( source , function ( value , key ) { target [ key ] = value ; } ) ; } ) ; return target ; }


Input: Returns whether an object appears to be a plain object - that is a direct instance of Object . [CODESPLIT] function isPlain ( value ) { return isObject ( value ) && toString . call ( value ) === '[object Object]' && value . constructor === Object ; }


Input: Log messages to the console and history based on the type of message [CODESPLIT] function logByType ( type , args ) { var stringify = arguments . length > 2 && arguments [ 2 ] !== undefined ? arguments [ 2 ] : ! ! IE_VERSION && IE_VERSION < 11 ; var lvl = log . levels [ level ] ; var lvlRegExp = new RegExp ( '^(' + lvl + ')$' ) ; if ( type !== 'log' ) { // Add the type to the front of the message when it's not "log". args . unshift ( type . toUpperCase ( ) + ':' ) ; } // Add a clone of the args at this point to history. if ( history ) { history . push ( [ ] . concat ( args ) ) ; } // Add console prefix after adding to history. args . unshift ( 'VIDEOJS:' ) ; // If there's no console then don't try to output messages, but they will // still be stored in history. // // Was setting these once outside of this function, but containing them // in the function makes it easier to test cases where console doesn't exist // when the module is executed. var fn = window . console && window . console [ type ] ; // Bail out if there's no console or if this type is not allowed by the // current logging level. if ( ! fn || ! lvl || ! lvlRegExp . test ( type ) ) { return ; } // IEs previous to 11 log objects uselessly as "[object Object]"; so, JSONify // objects and arrays for those less-capable browsers. if ( stringify ) { args = args . map ( function ( a ) { if ( isObject ( a ) || Array . isArray ( a ) ) { try { return JSON . stringify ( a ) ; } catch ( x ) { return String ( a ) ; } } // Cast to string before joining, so we get null and undefined explicitly // included in output (as we would in a modern console). return String ( a ) ; } ) . join ( ' ' ) ; } // Old IE versions do not allow .apply() for console methods (they are // reported as objects rather than functions). if ( ! fn . apply ) { fn ( args ) ; } else { fn [ Array . isArray ( args ) ? 'apply' : 'call' ] ( window . console , args ) ; } }


Input: @file computed - style . js @module computed - style A safe getComputedStyle with an IE8 fallback . [CODESPLIT] function computedStyle ( el , prop ) { if ( ! el || ! prop ) { return '' ; } if ( typeof window . getComputedStyle === 'function' ) { var cs = window . getComputedStyle ( el ) ; return cs ? cs [ prop ] : '' ; } return el . currentStyle [ prop ] || '' ; }


Input: Creates an element and applies properties . [CODESPLIT] function createEl ( ) { var tagName = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : 'div' ; var properties = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : { } ; var attributes = arguments . length > 2 && arguments [ 2 ] !== undefined ? arguments [ 2 ] : { } ; var content = arguments [ 3 ] ; var el = document . createElement ( tagName ) ; Object . getOwnPropertyNames ( properties ) . forEach ( function ( propName ) { var val = properties [ propName ] ; // See #2176 // We originally were accepting both properties and attributes in the // same object, but that doesn't work so well. if ( propName . indexOf ( 'aria-' ) !== - 1 || propName === 'role' || propName === 'type' ) { log$1 . warn ( tsml ( _templateObject , propName , val ) ) ; el . setAttribute ( propName , val ) ; // Handle textContent since it's not supported everywhere and we have a // method for it. } else if ( propName === 'textContent' ) { textContent ( el , val ) ; } else { el [ propName ] = val ; } } ) ; Object . getOwnPropertyNames ( attributes ) . forEach ( function ( attrName ) { el . setAttribute ( attrName , attributes [ attrName ] ) ; } ) ; if ( content ) { appendContent ( el , content ) ; } return el ; }


Input: Add a CSS class name to an element [CODESPLIT] function addClass ( element , classToAdd ) { if ( element . classList ) { element . classList . add ( classToAdd ) ; // Don't need to `throwIfWhitespace` here because `hasElClass` will do it // in the case of classList not being supported. } else if ( ! hasClass ( element , classToAdd ) ) { element . className = ( element . className + ' ' + classToAdd ) . trim ( ) ; } return element ; }


Input: The callback definition for toggleElClass . [CODESPLIT] function toggleClass ( element , classToToggle , predicate ) { // This CANNOT use `classList` internally because IE does not support the // second parameter to the `classList.toggle()` method! Which is fine because // `classList` will be used by the add/remove functions. var has = hasClass ( element , classToToggle ) ; if ( typeof predicate === 'function' ) { predicate = predicate ( element , classToToggle ) ; } if ( typeof predicate !== 'boolean' ) { predicate = ! has ; } // If the necessary class operation matches the current state of the // element, no action is required. if ( predicate === has ) { return ; } if ( predicate ) { addClass ( element , classToToggle ) ; } else { removeClass ( element , classToToggle ) ; } return element ; }


Input: Identical to the native getBoundingClientRect function but ensures that the method is supported at all ( it is in all browsers we claim to support ) and that the element is in the DOM before continuing . [CODESPLIT] function getBoundingClientRect ( el ) { if ( el && el . getBoundingClientRect && el . parentNode ) { var rect = el . getBoundingClientRect ( ) ; var result = { } ; [ 'bottom' , 'height' , 'left' , 'right' , 'top' , 'width' ] . forEach ( function ( k ) { if ( rect [ k ] !== undefined ) { result [ k ] = rect [ k ] ; } } ) ; if ( ! result . height ) { result . height = parseFloat ( computedStyle ( el , 'height' ) ) ; } if ( ! result . width ) { result . width = parseFloat ( computedStyle ( el , 'width' ) ) ; } return result ; } }


Input: x and y coordinates for a dom element or mouse pointer [CODESPLIT] function getPointerPosition ( el , event ) { var position = { } ; var box = findPosition ( el ) ; var boxW = el . offsetWidth ; var boxH = el . offsetHeight ; var boxY = box . top ; var boxX = box . left ; var pageY = event . pageY ; var pageX = event . pageX ; if ( event . changedTouches ) { pageX = event . changedTouches [ 0 ] . pageX ; pageY = event . changedTouches [ 0 ] . pageY ; } position . y = Math . max ( 0 , Math . min ( 1 , ( boxY - pageY + boxH ) / boxH ) ) ; position . x = Math . max ( 0 , Math . min ( 1 , ( pageX - boxX ) / boxW ) ) ; return position ; }


Input: Normalizes and appends content to an element . [CODESPLIT] function appendContent ( el , content ) { normalizeContent ( content ) . forEach ( function ( node ) { return el . appendChild ( node ) ; } ) ; return el ; }


Input: Returns the cache object where data for an element is stored [CODESPLIT] function getData ( el ) { var id = el [ elIdAttr ] ; if ( ! id ) { id = el [ elIdAttr ] = newGUID ( ) ; } if ( ! elData [ id ] ) { elData [ id ] = { } ; } return elData [ id ] ; }


Input: Returns whether or not an element has cached data [CODESPLIT] function hasData ( el ) { var id = el [ elIdAttr ] ; if ( ! id ) { return false ; } return ! ! Object . getOwnPropertyNames ( elData [ id ] ) . length ; }


Input: Delete data for the element from the cache and the guid attr from getElementById [CODESPLIT] function removeData ( el ) { var id = el [ elIdAttr ] ; if ( ! id ) { return ; } // Remove all stored data delete elData [ id ] ; // Remove the elIdAttr property from the DOM node try { delete el [ elIdAttr ] ; } catch ( e ) { if ( el . removeAttribute ) { el . removeAttribute ( elIdAttr ) ; } else { // IE doesn't appear to support removeAttribute on the document element el [ elIdAttr ] = null ; } } }


Input: @file events . js . An Event System ( John Resig - Secrets of a JS Ninja http : // jsninja . com / ) ( Original book version wasn t completely usable so fixed some things and made Closure Compiler compatible ) This should work very similarly to jQuery s events however it s based off the book version which isn t as robust as jquery s so there s probably some differences . [CODESPLIT] function _cleanUpEvents ( elem , type ) { var data = getData ( elem ) ; // Remove the events of a particular type if there are none left if ( data . handlers [ type ] . length === 0 ) { delete data . handlers [ type ] ; // data.handlers[type] = null; // Setting to null was causing an error with data.handlers // Remove the meta-handler from the element if ( elem . removeEventListener ) { elem . removeEventListener ( type , data . dispatcher , false ) ; } else if ( elem . detachEvent ) { elem . detachEvent ( 'on' + type , data . dispatcher ) ; } } // Remove the events object if there are no types left if ( Object . getOwnPropertyNames ( data . handlers ) . length <= 0 ) { delete data . handlers ; delete data . dispatcher ; delete data . disabled ; } // Finally remove the element data if there is no data left if ( Object . getOwnPropertyNames ( data ) . length === 0 ) { removeData ( elem ) ; } }


Input: Loops through an array of event types and calls the requested method for each type . [CODESPLIT] function _handleMultipleEvents ( fn , elem , types , callback ) { types . forEach ( function ( type ) { // Call the event method for each one of the types fn ( elem , type , callback ) ; } ) ; }


Input: Add an event listener to element It stores the handler function in a separate cache object and adds a generic handler to the element s event along with a unique id ( guid ) to the element . [CODESPLIT] function on ( elem , type , fn ) { if ( Array . isArray ( type ) ) { return _handleMultipleEvents ( on , elem , type , fn ) ; } var data = getData ( elem ) ; // We need a place to store all our handler data if ( ! data . handlers ) { data . handlers = { } ; } if ( ! data . handlers [ type ] ) { data . handlers [ type ] = [ ] ; } if ( ! fn . guid ) { fn . guid = newGUID ( ) ; } data . handlers [ type ] . push ( fn ) ; if ( ! data . dispatcher ) { data . disabled = false ; data . dispatcher = function ( event , hash ) { if ( data . disabled ) { return ; } event = fixEvent ( event ) ; var handlers = data . handlers [ event . type ] ; if ( handlers ) { // Copy handlers so if handlers are added/removed during the process it doesn't throw everything off. var handlersCopy = handlers . slice ( 0 ) ; for ( var m = 0 , n = handlersCopy . length ; m < n ; m ++ ) { if ( event . isImmediatePropagationStopped ( ) ) { break ; } else { try { handlersCopy [ m ] . call ( elem , event , hash ) ; } catch ( e ) { log$1 . error ( e ) ; } } } } } ; } if ( data . handlers [ type ] . length === 1 ) { if ( elem . addEventListener ) { var options = false ; if ( _supportsPassive && passiveEvents . indexOf ( type ) > - 1 ) { options = { passive : true } ; } elem . addEventListener ( type , data . dispatcher , options ) ; } else if ( elem . attachEvent ) { elem . attachEvent ( 'on' + type , data . dispatcher ) ; } } }


Input: Removes event listeners from an element [CODESPLIT] function off ( elem , type , fn ) { // Don't want to add a cache object through getElData if not needed if ( ! hasData ( elem ) ) { return ; } var data = getData ( elem ) ; // If no events exist, nothing to unbind if ( ! data . handlers ) { return ; } if ( Array . isArray ( type ) ) { return _handleMultipleEvents ( off , elem , type , fn ) ; } // Utility function var removeType = function removeType ( t ) { data . handlers [ t ] = [ ] ; _cleanUpEvents ( elem , t ) ; } ; // Are we removing all bound events? if ( ! type ) { for ( var t in data . handlers ) { removeType ( t ) ; } return ; } var handlers = data . handlers [ type ] ; // If no handlers exist, nothing to unbind if ( ! handlers ) { return ; } // If no listener was provided, remove all listeners for type if ( ! fn ) { removeType ( type ) ; return ; } // We're only removing a single handler if ( fn . guid ) { for ( var n = 0 ; n < handlers . length ; n ++ ) { if ( handlers [ n ] . guid === fn . guid ) { handlers . splice ( n -- , 1 ) ; } } } _cleanUpEvents ( elem , type ) ; }


Input: Trigger a listener only once for an event [CODESPLIT] function one ( elem , type , fn ) { if ( Array . isArray ( type ) ) { return _handleMultipleEvents ( one , elem , type , fn ) ; } var func = function func ( ) { off ( elem , type , func ) ; fn . apply ( this , arguments ) ; } ; // copy the guid to the new function so it can removed using the original function's ID func . guid = fn . guid = fn . guid || newGUID ( ) ; on ( elem , type , func ) ; }


Input: Set up any tags that have a data - setup attribute when the player is started . [CODESPLIT] function autoSetup ( ) { // Protect against breakage in non-browser environments. if ( ! isReal ( ) ) { return ; } // One day, when we stop supporting IE8, go back to this, but in the meantime...*hack hack hack* // var vids = Array.prototype.slice.call(document.getElementsByTagName('video')); // var audios = Array.prototype.slice.call(document.getElementsByTagName('audio')); // var mediaEls = vids.concat(audios); // Because IE8 doesn't support calling slice on a node list, we need to loop // through each list of elements to build up a new, combined list of elements. var vids = document . getElementsByTagName ( 'video' ) ; var audios = document . getElementsByTagName ( 'audio' ) ; var mediaEls = [ ] ; if ( vids && vids . length > 0 ) { for ( var i = 0 , e = vids . length ; i < e ; i ++ ) { mediaEls . push ( vids [ i ] ) ; } } if ( audios && audios . length > 0 ) { for ( var _i = 0 , _e = audios . length ; _i < _e ; _i ++ ) { mediaEls . push ( audios [ _i ] ) ; } } // Check if any media elements exist if ( mediaEls && mediaEls . length > 0 ) { for ( var _i2 = 0 , _e2 = mediaEls . length ; _i2 < _e2 ; _i2 ++ ) { var mediaEl = mediaEls [ _i2 ] ; // Check if element exists, has getAttribute func. // IE seems to consider typeof el.getAttribute == 'object' instead of // 'function' like expected, at least when loading the player immediately. if ( mediaEl && mediaEl . getAttribute ) { // Make sure this player hasn't already been set up. if ( mediaEl . player === undefined ) { var options = mediaEl . getAttribute ( 'data-setup' ) ; // Check if data-setup attr exists. // We only auto-setup if they've added the data-setup attr. if ( options !== null ) { // Create new video.js instance. videojs$2 ( mediaEl ) ; } } // If getAttribute isn't defined, we need to wait for the DOM. } else { autoSetupTimeout ( 1 ) ; break ; } } // No videos were found, so keep looping unless page is finished loading. } else if ( ! _windowLoaded ) { autoSetupTimeout ( 1 ) ; } }


Input: Wait until the page is loaded before running autoSetup . This will be called in autoSetup if hasLoaded returns false . [CODESPLIT] function autoSetupTimeout ( wait , vjs ) { if ( vjs ) { videojs$2 = vjs ; } window . setTimeout ( autoSetup , wait ) ; }


Input: Add text to a DOM element . [CODESPLIT] function setTextContent ( el , content ) { if ( el . styleSheet ) { el . styleSheet . cssText = content ; } else { el . textContent = content ; } }


Input: @file fn . js @module fn Bind ( a . k . a proxy or Context ) . A simple method for changing the context of a function It also stores a unique id on the function so it can be easily removed from events . [CODESPLIT] function bind ( context , fn , uid ) { // Make sure the function has a unique ID if ( ! fn . guid ) { fn . guid = newGUID ( ) ; } // Create the new function that changes the context var bound = function bound ( ) { return fn . apply ( context , arguments ) ; } ; // Allow for the ability to individualize this function // Needed in the case where multiple objects might share the same prototype // IF both items add an event listener with the same function, then you try to remove just one // it will remove both because they both have the same guid. // when using this, you need to use the bind method when you remove the listener as well. // currently used in text tracks bound . guid = uid ? uid + '_' + fn . guid : fn . guid ; return bound ; }


Input: Wraps the given function fn with a new function that only invokes fn at most once per every wait milliseconds . [CODESPLIT] function throttle ( fn , wait ) { var last = Date . now ( ) ; var throttled = function throttled ( ) { var now = Date . now ( ) ; if ( now - last >= wait ) { fn . apply ( undefined , arguments ) ; last = now ; } } ; return throttled ; }


Input: @file mixins / evented . js @module evented Returns whether or not an object has had the evented mixin applied . [CODESPLIT] function isEvented ( object ) { return object instanceof EventTarget || ! ! object . eventBusEl_ && [ 'on' , 'one' , 'off' , 'trigger' ] . every ( function ( k ) { return typeof object [ k ] === 'function' ; } ) ; }


Input: Whether a value is a valid event type - non - empty string or array . [CODESPLIT] function isValidEventType ( type ) { return ( // The regex here verifies that the `type` contains at least one non- // whitespace character. typeof type === 'string' && / \S / . test ( type ) || Array . isArray ( type ) && ! ! type . length ) ; }


Input: Takes an array of arguments given to on () or one () validates them and normalizes them into an object . [CODESPLIT] function normalizeListenArgs ( self , args ) { // If the number of arguments is less than 3, the target is always the // evented object itself. var isTargetingSelf = args . length < 3 || args [ 0 ] === self || args [ 0 ] === self . eventBusEl_ ; var target = void 0 ; var type = void 0 ; var listener = void 0 ; if ( isTargetingSelf ) { target = self . eventBusEl_ ; // Deal with cases where we got 3 arguments, but we are still listening to // the evented object itself. if ( args . length >= 3 ) { args . shift ( ) ; } type = args [ 0 ] ; listener = args [ 1 ] ; } else { target = args [ 0 ] ; type = args [ 1 ] ; listener = args [ 2 ] ; } validateTarget ( target ) ; validateEventType ( type ) ; validateListener ( listener ) ; listener = bind ( self , listener ) ; return { isTargetingSelf : isTargetingSelf , target : target , type : type , listener : listener } ; }


Input: Adds the listener to the event type ( s ) on the target normalizing for the type of target . [CODESPLIT] function listen ( target , method , type , listener ) { validateTarget ( target ) ; if ( target . nodeName ) { Events [ method ] ( target , type , listener ) ; } else { target [ method ] ( type , listener ) ; } }


Input: Add a listener to an event ( or events ) on this object or another evented object . [CODESPLIT] function on$$1 ( ) { var _this = this ; for ( var _len = arguments . length , args = Array ( _len ) , _key = 0 ; _key < _len ; _key ++ ) { args [ _key ] = arguments [ _key ] ; } var _normalizeListenArgs = normalizeListenArgs ( this , args ) , isTargetingSelf = _normalizeListenArgs . isTargetingSelf , target = _normalizeListenArgs . target , type = _normalizeListenArgs . type , listener = _normalizeListenArgs . listener ; listen ( target , 'on' , type , listener ) ; // If this object is listening to another evented object. if ( ! isTargetingSelf ) { // If this object is disposed, remove the listener. var removeListenerOnDispose = function removeListenerOnDispose ( ) { return _this . off ( target , type , listener ) ; } ; // Use the same function ID as the listener so we can remove it later it // using the ID of the original listener. removeListenerOnDispose . guid = listener . guid ; // Add a listener to the target's dispose event as well. This ensures // that if the target is disposed BEFORE this object, we remove the // removal listener that was just added. Otherwise, we create a memory leak. var removeRemoverOnTargetDispose = function removeRemoverOnTargetDispose ( ) { return _this . off ( 'dispose' , removeListenerOnDispose ) ; } ; // Use the same function ID as the listener so we can remove it later // it using the ID of the original listener. removeRemoverOnTargetDispose . guid = listener . guid ; listen ( this , 'on' , 'dispose' , removeListenerOnDispose ) ; listen ( target , 'on' , 'dispose' , removeRemoverOnTargetDispose ) ; } }


Input: Add a listener to an event ( or events ) on this object or another evented object . The listener will only be called once and then removed . [CODESPLIT] function one$$1 ( ) { var _this2 = this ; for ( var _len2 = arguments . length , args = Array ( _len2 ) , _key2 = 0 ; _key2 < _len2 ; _key2 ++ ) { args [ _key2 ] = arguments [ _key2 ] ; } var _normalizeListenArgs2 = normalizeListenArgs ( this , args ) , isTargetingSelf = _normalizeListenArgs2 . isTargetingSelf , target = _normalizeListenArgs2 . target , type = _normalizeListenArgs2 . type , listener = _normalizeListenArgs2 . listener ; // Targeting this evented object. if ( isTargetingSelf ) { listen ( target , 'one' , type , listener ) ; // Targeting another evented object. } else { var wrapper = function wrapper ( ) { for ( var _len3 = arguments . length , largs = Array ( _len3 ) , _key3 = 0 ; _key3 < _len3 ; _key3 ++ ) { largs [ _key3 ] = arguments [ _key3 ] ; } _this2 . off ( target , type , wrapper ) ; listener . apply ( null , largs ) ; } ; // Use the same function ID as the listener so we can remove it later // it using the ID of the original listener. wrapper . guid = listener . guid ; listen ( target , 'one' , type , wrapper ) ; } }


Input: Removes listener ( s ) from event ( s ) on an evented object . [CODESPLIT] function off$$1 ( targetOrType , typeOrListener , listener ) { // Targeting this evented object. if ( ! targetOrType || isValidEventType ( targetOrType ) ) { off ( this . eventBusEl_ , targetOrType , typeOrListener ) ; // Targeting another evented object. } else { var target = targetOrType ; var type = typeOrListener ; // Fail fast and in a meaningful way! validateTarget ( target ) ; validateEventType ( type ) ; validateListener ( listener ) ; // Ensure there's at least a guid, even if the function hasn't been used listener = bind ( this , listener ) ; // Remove the dispose listener on this evented object, which was given // the same guid as the event listener in on(). this . off ( 'dispose' , listener ) ; if ( target . nodeName ) { off ( target , type , listener ) ; off ( target , 'dispose' , listener ) ; } else if ( isEvented ( target ) ) { target . off ( type , listener ) ; target . off ( 'dispose' , listener ) ; } } }


Input: Applies { @link module : evented~EventedMixin|EventedMixin } to a target object . [CODESPLIT] function evented ( target ) { var options = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : { } ; var eventBusKey = options . eventBusKey ; // Set or create the eventBusEl_. if ( eventBusKey ) { if ( ! target [ eventBusKey ] . nodeName ) { throw new Error ( 'The eventBusKey "' + eventBusKey + '" does not refer to an element.' ) ; } target . eventBusEl_ = target [ eventBusKey ] ; } else { target . eventBusEl_ = createEl ( 'span' , { className : 'vjs-event-bus' } ) ; } assign ( target , EventedMixin ) ; // When any evented object is disposed, it removes all its listeners. target . on ( 'dispose' , function ( ) { return target . off ( ) ; } ) ; return target ; }


Input:
Set the state of an object by mutating its { @link module : stateful~StatefulMixin . state|state } object in place . [CODESPLIT] function setState ( stateUpdates ) { var _this = this ; // Support providing the `stateUpdates` state as a function. if ( typeof stateUpdates === 'function' ) { stateUpdates = stateUpdates ( ) ; } var changes = void 0 ; each ( stateUpdates , function ( value , key ) { // Record the change if the value is different from what's in the // current state. if ( _this . state [ key ] !== value ) { changes = changes || { } ; changes [ key ] = { from : _this . state [ key ] , to : value } ; } _this . state [ key ] = value ; } ) ; // Only trigger "statechange" if there were changes AND we have a trigger // function. This allows us to not require that the target object be an // evented object. if ( changes && isEvented ( this ) ) { /**
       * An event triggered on an object that is both
       * {@link module:stateful|stateful} and {@link module:evented|evented}
       * indicating that its state has changed.
       *
       * @event    module:stateful~StatefulMixin#statechanged
       * @type     {Object}
       * @property {Object} changes
       *           A hash containing the properties that were changed and
       *           the values they were changed `from` and `to`.
       */ this . trigger ( { changes : changes , type : 'statechanged' } ) ; } return changes ; }


Input: Applies { @link module : stateful~StatefulMixin|StatefulMixin } to a target object . [CODESPLIT] function stateful ( target , defaultState ) { assign ( target , StatefulMixin ) ; // This happens after the mixing-in because we need to replace the `state` // added in that step. target . state = assign ( { } , target . state , defaultState ) ; // Auto-bind the `handleStateChanged` method of the target object if it exists. if ( typeof target . handleStateChanged === 'function' && isEvented ( target ) ) { target . on ( 'statechanged' , target . handleStateChanged ) ; } return target ; }


Input: @file merge - options . js @module merge - options Deep - merge one or more options objects recursively merging ** only ** plain object properties . [CODESPLIT] function mergeOptions ( ) { var result = { } ; for ( var _len = arguments . length , sources = Array ( _len ) , _key = 0 ; _key < _len ; _key ++ ) { sources [ _key ] = arguments [ _key ] ; } sources . forEach ( function ( source ) { if ( ! source ) { return ; } each ( source , function ( value , key ) { if ( ! isPlain ( value ) ) { result [ key ] = value ; return ; } if ( ! isPlain ( result [ key ] ) ) { result [ key ] = { } ; } result [ key ] = mergeOptions ( result [ key ] , value ) ; } ) ; } ) ; return result ; }


Input: A callback that is called when a component is ready . Does not have any paramters and any callback value will be ignored . [CODESPLIT] function Component ( player , options , ready ) { classCallCheck ( this , Component ) ; // The component might be the player itself and we can't pass `this` to super if ( ! player && this . play ) { this . player_ = player = this ; // eslint-disable-line } else { this . player_ = player ; } // Make a copy of prototype.options_ to protect against overriding defaults this . options_ = mergeOptions ( { } , this . options_ ) ; // Updated options with supplied options options = this . options_ = mergeOptions ( this . options_ , options ) ; // Get ID from options or options element if one is supplied this . id_ = options . id || options . el && options . el . id ; // If there was no ID from the options, generate one if ( ! this . id_ ) { // Don't require the player ID function in the case of mock players var id = player && player . id && player . id ( ) || 'no_player' ; this . id_ = id + '_component_' + newGUID ( ) ; } this . name_ = options . name || null ; // Create element if one wasn't provided in options if ( options . el ) { this . el_ = options . el ; } else if ( options . createEl !== false ) { this . el_ = this . createEl ( ) ; } // Make this an evented object and use `el_`, if available, as its event bus evented ( this , { eventBusKey : this . el_ ? 'el_' : null } ) ; stateful ( this , this . constructor . defaultState ) ; this . children_ = [ ] ; this . childIndex_ = { } ; this . childNameIndex_ = { } ; // Add any child components in options if ( options . initChildren !== false ) { this . initChildren ( ) ; } this . ready ( ready ) ; // Don't want to trigger ready here or it will before init is actually // finished for all children that run this constructor if ( options . reportTouchActivity !== false ) { this . enableTouchActivity ( ) ; } }


Input: An object that contains ranges of time for various reasons . [CODESPLIT] function rangeCheck ( fnName , index , maxIndex ) { if ( typeof index !== 'number' || index < 0 || index > maxIndex ) { throw new Error ( 'Failed to execute \'' + fnName + '\' on \'TimeRanges\': The index provided (' + index + ') is non-numeric or out of bounds (0-' + maxIndex + ').' ) ; } }


Input: Check if any of the time ranges are over the maximum index . [CODESPLIT] function getRange ( fnName , valueIndex , ranges , rangeIndex ) { rangeCheck ( fnName , rangeIndex , ranges . length - 1 ) ; return ranges [ rangeIndex ] [ valueIndex ] ; }


Input: Create a time range object givent ranges of time . [CODESPLIT] function createTimeRangesObj ( ranges ) { if ( ranges === undefined || ranges . length === 0 ) { return { length : 0 , start : function start ( ) { throw new Error ( 'This TimeRanges object is empty' ) ; } , end : function end ( ) { throw new Error ( 'This TimeRanges object is empty' ) ; } } ; } return { length : ranges . length , start : getRange . bind ( null , 'start' , 0 , ranges ) , end : getRange . bind ( null , 'end' , 1 , ranges ) } ; }


Input: Should create a fake TimeRange object which mimics an HTML5 time range instance . [CODESPLIT] function createTimeRanges ( start , end ) { if ( Array . isArray ( start ) ) { return createTimeRangesObj ( start ) ; } else if ( start === undefined || end === undefined ) { return createTimeRangesObj ( ) ; } return createTimeRangesObj ( [ [ start , end ] ] ) ; }


Input: @file buffer . js @module buffer Compute the percentage of the media that has been buffered . [CODESPLIT] function bufferedPercent ( buffered , duration ) { var bufferedDuration = 0 ; var start = void 0 ; var end = void 0 ; if ( ! duration ) { return 0 ; } if ( ! buffered || ! buffered . length ) { buffered = createTimeRanges ( 0 , 0 ) ; } for ( var i = 0 ; i < buffered . length ; i ++ ) { start = buffered . start ( i ) ; end = buffered . end ( i ) ; // buffered end can be bigger than duration by a very small fraction if ( end > duration ) { end = duration ; } bufferedDuration += end - start ; } return bufferedDuration / duration ; }


Input: @file media - error . js A Custom MediaError class which mimics the standard HTML5 MediaError class . [CODESPLIT] function MediaError ( value ) { // Allow redundant calls to this constructor to avoid having `instanceof` // checks peppered around the code. if ( value instanceof MediaError ) { return value ; } if ( typeof value === 'number' ) { this . code = value ; } else if ( typeof value === 'string' ) { // default code is zero, so this is a custom error this . message = value ; } else if ( isObject ( value ) ) { // We assign the `code` property manually because native `MediaError` objects // do not expose it as an own/enumerable property of the object. if ( typeof value . code === 'number' ) { this . code = value . code ; } assign ( this , value ) ; } if ( ! this . message ) { this . message = MediaError . defaultMessages [ this . code ] || '' ; } }


Input: @file text - track - list - converter . js Utilities for capturing text track state and re - creating tracks based on a capture . [CODESPLIT] function trackToJson_ ( track ) { var ret = [ 'kind' , 'label' , 'language' , 'id' , 'inBandMetadataTrackDispatchType' , 'mode' , 'src' ] . reduce ( function ( acc , prop , i ) { if ( track [ prop ] ) { acc [ prop ] = track [ prop ] ; } return acc ; } , { cues : track . cues && Array . prototype . map . call ( track . cues , function ( cue ) { return { startTime : cue . startTime , endTime : cue . endTime , text : cue . text , id : cue . id } ; } ) } ) ; return ret ; }


Input: Examine a { @link Tech } and return a JSON - compatible javascript array that represents the state of all { @link TextTrack } s currently configured . The return array is compatible with { @link text - track - list - converter : jsonToTextTracks } . [CODESPLIT] function textTracksToJson ( tech ) { var trackEls = tech . $$ ( 'track' ) ; var trackObjs = Array . prototype . map . call ( trackEls , function ( t ) { return t . track ; } ) ; var tracks = Array . prototype . map . call ( trackEls , function ( trackEl ) { var json = trackToJson_ ( trackEl . track ) ; if ( trackEl . src ) { json . src = trackEl . src ; } return json ; } ) ; return tracks . concat ( Array . prototype . filter . call ( tech . textTracks ( ) , function ( track ) { return trackObjs . indexOf ( track ) === - 1 ; } ) . map ( trackToJson_ ) ) ; }


Input: Create a set of remote { @link TextTrack } s on a { @link Tech } based on an array of javascript object { @link TextTrack } representations . [CODESPLIT] function jsonToTextTracks ( json , tech ) { json . forEach ( function ( track ) { var addedTrack = tech . addRemoteTextTrack ( track ) . track ; if ( ! track . src && track . cues ) { track . cues . forEach ( function ( cue ) { return addedTrack . addCue ( cue ) ; } ) ; } } ) ; return tech . textTracks ( ) ; }


Input:
Create an instance of this class [CODESPLIT] function TrackList ( ) { var tracks = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : [ ] ; var _ret ; var list = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : null ; classCallCheck ( this , TrackList ) ; var _this = possibleConstructorReturn ( this , _EventTarget . call ( this ) ) ; if ( ! list ) { list = _this ; // eslint-disable-line if ( IS_IE8 ) { list = document . createElement ( 'custom' ) ; for ( var prop in TrackList . prototype ) { if ( prop !== 'constructor' ) { list [ prop ] = TrackList . prototype [ prop ] ; } } } } list . tracks_ = [ ] ; /**
     * @memberof TrackList
     * @member {number} length
     *         The current number of `Track`s in the this Trackist.
     * @instance
     */ Object . defineProperty ( list , 'length' , { get : function get$$1 ( ) { return this . tracks_ . length ; } } ) ; for ( var i = 0 ; i < tracks . length ; i ++ ) { list . addTrack ( tracks [ i ] ) ; } // must return the object, as for ie8 it will not be this // but a reference to a document object return _ret = list , possibleConstructorReturn ( _this , _ret ) ; }


Input: Create an instance of this class . [CODESPLIT] function AudioTrackList ( ) { var _this , _ret ; var tracks = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : [ ] ; classCallCheck ( this , AudioTrackList ) ; var list = void 0 ; // make sure only 1 track is enabled // sorted from last index to first index for ( var i = tracks . length - 1 ; i >= 0 ; i -- ) { if ( tracks [ i ] . enabled ) { disableOthers ( tracks , tracks [ i ] ) ; break ; } } // IE8 forces us to implement inheritance ourselves // as it does not support Object.defineProperty properly if ( IS_IE8 ) { list = document . createElement ( 'custom' ) ; for ( var prop in TrackList . prototype ) { if ( prop !== 'constructor' ) { list [ prop ] = TrackList . prototype [ prop ] ; } } for ( var _prop in AudioTrackList . prototype ) { if ( _prop !== 'constructor' ) { list [ _prop ] = AudioTrackList . prototype [ _prop ] ; } } } list = ( _this = possibleConstructorReturn ( this , _TrackList . call ( this , tracks , list ) ) , _this ) ; list . changing_ = false ; return _ret = list , possibleConstructorReturn ( _this , _ret ) ; }


Input: @file video - track - list . js Un - select all other { @link VideoTrack } s that are selected . [CODESPLIT] function disableOthers ( list , track ) { for ( var i = 0 ; i < list . length ; i ++ ) { if ( ! Object . keys ( list [ i ] ) . length || track . id === list [ i ] . id ) { continue ; } // another video track is enabled, disable it list [ i ] . selected = false ; } }


Input:
Create an instance of this class . [CODESPLIT] function VideoTrackList ( ) { var _this , _ret ; var tracks = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : [ ] ; classCallCheck ( this , VideoTrackList ) ; var list = void 0 ; // make sure only 1 track is enabled // sorted from last index to first index for ( var i = tracks . length - 1 ; i >= 0 ; i -- ) { if ( tracks [ i ] . selected ) { disableOthers$1 ( tracks , tracks [ i ] ) ; break ; } } // IE8 forces us to implement inheritance ourselves // as it does not support Object.defineProperty properly if ( IS_IE8 ) { list = document . createElement ( 'custom' ) ; for ( var prop in TrackList . prototype ) { if ( prop !== 'constructor' ) { list [ prop ] = TrackList . prototype [ prop ] ; } } for ( var _prop in VideoTrackList . prototype ) { if ( _prop !== 'constructor' ) { list [ _prop ] = VideoTrackList . prototype [ _prop ] ; } } } list = ( _this = possibleConstructorReturn ( this , _TrackList . call ( this , tracks , list ) ) , _this ) ; list . changing_ = false ; /**
     * @member {number} VideoTrackList#selectedIndex
     *         The current index of the selected {@link VideoTrack`}.
     */ Object . defineProperty ( list , 'selectedIndex' , { get : function get$$1 ( ) { for ( var _i = 0 ; _i < this . length ; _i ++ ) { if ( this [ _i ] . selected ) { return _i ; } } return - 1 ; } , set : function set$$1 ( ) { } } ) ; return _ret = list , possibleConstructorReturn ( _this , _ret ) ; }


Input: Create an instance of this class . [CODESPLIT] function TextTrackList ( ) { var _this , _ret ; var tracks = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : [ ] ; classCallCheck ( this , TextTrackList ) ; var list = void 0 ; // IE8 forces us to implement inheritance ourselves // as it does not support Object.defineProperty properly if ( IS_IE8 ) { list = document . createElement ( 'custom' ) ; for ( var prop in TrackList . prototype ) { if ( prop !== 'constructor' ) { list [ prop ] = TrackList . prototype [ prop ] ; } } for ( var _prop in TextTrackList . prototype ) { if ( _prop !== 'constructor' ) { list [ _prop ] = TextTrackList . prototype [ _prop ] ; } } } list = ( _this = possibleConstructorReturn ( this , _TrackList . call ( this , tracks , list ) ) , _this ) ; return _ret = list , possibleConstructorReturn ( _this , _ret ) ; }


Input:
Create an instance of this class . [CODESPLIT] function HtmlTrackElementList ( ) { var trackElements = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : [ ] ; classCallCheck ( this , HtmlTrackElementList ) ; var list = this ; // eslint-disable-line if ( IS_IE8 ) { list = document . createElement ( 'custom' ) ; for ( var prop in HtmlTrackElementList . prototype ) { if ( prop !== 'constructor' ) { list [ prop ] = HtmlTrackElementList . prototype [ prop ] ; } } } list . trackElements_ = [ ] ; /**
     * @memberof HtmlTrackElementList
     * @member {number} length
     *         The current number of `Track`s in the this Trackist.
     * @instance
     */ Object . defineProperty ( list , 'length' , { get : function get$$1 ( ) { return this . trackElements_ . length ; } } ) ; for ( var i = 0 , length = trackElements . length ; i < length ; i ++ ) { list . addTrackElement_ ( trackElements [ i ] ) ; } if ( IS_IE8 ) { return list ; } }


Input:
Create an instance of this class .. [CODESPLIT] function TextTrackCueList ( cues ) { classCallCheck ( this , TextTrackCueList ) ; var list = this ; // eslint-disable-line if ( IS_IE8 ) { list = document . createElement ( 'custom' ) ; for ( var prop in TextTrackCueList . prototype ) { if ( prop !== 'constructor' ) { list [ prop ] = TextTrackCueList . prototype [ prop ] ; } } } TextTrackCueList . prototype . setCues_ . call ( list , cues ) ; /**
     * @memberof TextTrackCueList
     * @member {number} length
     *         The current number of `TextTrackCue`s in the TextTrackCueList.
     * @instance
     */ Object . defineProperty ( list , 'length' , { get : function get$$1 ( ) { return this . length_ ; } } ) ; if ( IS_IE8 ) { return list ; } }


Input: Returns the extension of the passed file name . It will return an empty string if passed an invalid path . [CODESPLIT] function getFileExtension ( path ) { if ( typeof path === 'string' ) { var splitPathRe = / ^(\/?)([\s\S]*?)((?:\.{1,2}|[^\/]+?)(\.([^\.\/\?]+)))(?:[\/]*|[\?].*)$ / i ; var pathParts = splitPathRe . exec ( path ) ; if ( pathParts ) { return pathParts . pop ( ) . toLowerCase ( ) ; } } return '' ; }


Input: @file text - track . js Takes a webvtt file contents and parses it into cues [CODESPLIT] function parseCues ( srcContent , track ) { var parser = new window . WebVTT . Parser ( window , window . vttjs , window . WebVTT . StringDecoder ( ) ) ; var errors = [ ] ; parser . oncue = function ( cue ) { track . addCue ( cue ) ; } ; parser . onparsingerror = function ( error ) { errors . push ( error ) ; } ; parser . onflush = function ( ) { track . trigger ( { type : 'loadeddata' , target : track } ) ; } ; parser . parse ( srcContent ) ; if ( errors . length > 0 ) { if ( window . console && window . console . groupCollapsed ) { window . console . groupCollapsed ( 'Text Track parsing errors for ' + track . src ) ; } errors . forEach ( function ( error ) { return log$1 . error ( error ) ; } ) ; if ( window . console && window . console . groupEnd ) { window . console . groupEnd ( ) ; } } parser . flush ( ) ; }


Input: Load a TextTrack from a specifed url . [CODESPLIT] function loadTrack ( src , track ) { var opts = { uri : src } ; var crossOrigin = isCrossOrigin ( src ) ; if ( crossOrigin ) { opts . cors = crossOrigin ; } xhr ( opts , bind ( this , function ( err , response , responseBody ) { if ( err ) { return log$1 . error ( err , response ) ; } track . loaded_ = true ; // Make sure that vttjs has loaded, otherwise, wait till it finished loading // NOTE: this is only used for the alt/video.novtt.js build if ( typeof window . WebVTT !== 'function' ) { if ( track . tech_ ) { var loadHandler = function loadHandler ( ) { return parseCues ( responseBody , track ) ; } ; track . tech_ . on ( 'vttjsloaded' , loadHandler ) ; track . tech_ . on ( 'vttjserror' , function ( ) { log$1 . error ( 'vttjs failed to load, stopping trying to process ' + track . src ) ; track . tech_ . off ( 'vttjsloaded' , loadHandler ) ; } ) ; } } else { parseCues ( responseBody , track ) ; } } ) ) ; }