PageSourceSearch

https://impactfm.fr/player/js/lib/main.js

js impactfm.fr collected 2026-10-02 11:33:16 UTC 21,100 bytes, 679 lines download raw bytes

1const LOGLEVEL_NONE     = 0 ; 
2const LOGLEVEL_TRACE    = 1 ; 
3const LOGLEVEL_DEBUG    = 2 ; 
4const LOGLEVEL_INFO     = 3 ; 
5const LOGLEVEL_NOTICE   = 4 ; 
6const LOGLEVEL_WARNING  = 5 ; 
7const LOGLEVEL_ERROR    = 6 ; 
8const logLevelStr = ['NON', 'TRA', 'DEB', 'INF', 'NOT', 'WAR', 'ERR'] ; 
9
10const ORIENTATION_HORIZONTAL = 1 ; 
11const ORIENTATION_VERTICAL = 2 ; 
12
13function TFrameworkCore(aParentDiv) {
14    var that = this ; 
15    var FParent = aParentDiv ; 
16    var FInitialized = false ; 
17        
18    this.div ; 
19    
20    // Parameters ==============================================================
21    
22    this.modulePath = '/lib/js/' ; 
23    this.logLevel = LOGLEVEL_TRACE ; 
24
25    this.ajax = false ; 
26    this.ajaxPath = 'dyn/' ; 
27    
28    this.xhr = false ; 
29    this.ui  = new Object() ; 
30       
31    
32    // Initialization ==========================================================
33    
34    this.onInitialize = false ;    
35        
36    function Init() {
37        window['fwCore'] = that ;                 
38        document.body.addEventListener('load', doDOMLoaded(), true) ; 
39        that.div = fwCore.createDiv(FParent, 'absolute', '0px', '0px', '0px', '0px') ;        
40        that.div.ondragend = function(e) {
41            that.dragObject = false ; 
42        }
43        
44        initDisplaySize() ; 
45    
46        that.addParameter('color', 'defaultSelect',     '#B0C0FF') ; 
47        that.addParameter('color', 'defaultModified',   '#FFFFA0') ; 
48        that.addParameter('color', 'defaultNormal',     '#FFFFFF') ; 
49        that.addParameter('font', 'defaultFont', 'Roboto,Arial,Helvetica') ; 
50                
51        fwCore.log('fwCore initialisation finished') ; 
52    }
53    
54    function doDOMLoaded() {
55        fwCore.log('fwCore DOM loaded') ; 
56    }
57    
58    function doInitialized() {
59        if (FInitialized)
60            return false ; 
61        
62        FInitialized = true ;         
63        
64        // Ajax
65        that.ajax = new TAjax(that.ajaxPath) ; 
66        
67        if (that.onInitialize) 
68            that.onInitialize(that) ; 
69        
70        doDisplaySizeChange() ; 
71    }
72    
73    this.isInitialized = function() {
74        return FInitialized ; 
75    }
76    
77    // Modules =================================================================
78
79    var FLoadedModules = new Array() ; 
80        
81    this.loadModules = function(aModuleNames) {
82        fwCore.log('Loading modules') ; 
83        for (var i in aModuleNames) {
84            var vModuleName = aModuleNames[i] ; 
85            that.loadModule(vModuleName) ; 
86        }
87    }
88    
89    this.isModuleLoaded = function(aModuleName) {
90        for (var i in FLoadedModules) {
91            var vModule = FLoadedModules[i] ; 
92            if (vModule.name == aModuleName) {
93                return true ;
94            }
95        }
96        
97        return false ; 
98    }
99    
100    this.loadScript = function(aScriptFileName) {
101        fwCore.log('Loading script ' + aScriptFileName, LOGLEVEL_DEBUG) ; 
102
103        var vModule = new TFrameworkModule() ; 
104        vModule.name        = aScriptFileName ;                         
105        vModule.script      = document.createElement('script') ; 
106        vModule.script.src  = aScriptFileName ; 
107        vModule.script.defer = true ; 
108        vModule.loaded      = false ; 
109
110        FLoadedModules.push(vModule) ; 
111
112        vModule.script.onload = function() {
113            vModule.loaded = true ; 
114            fwCore.log('Script ' + vModule.name + ' loaded', LOGLEVEL_DEBUG) ; 
115            evalModuleLoaded() ; 
116        }
117
118        vModule.script.onerror = function() {
119            vModule.loaded = false ; 
120            fwCore.log('Script ' + vModule.name + ' load error', LOGLEVEL_ERROR) ; 
121        }
122
123        document.head.appendChild(vModule.script) ;                         
124
125        return true ; 
126    }
127    
128    this.loadModule = function(aModuleName) {   
129        return ;
130        if (!that.isModuleLoaded(aModuleName)) {
131            fwCore.log('Loading module ' + aModuleName, LOGLEVEL_DEBUG) ; 
132            
133            var vModule = new TFrameworkModule() ; 
134            vModule.name        = aModuleName ;                         
135            vModule.script      = document.createElement('script') ; 
136            vModule.script.src  = that.modulePath + aModuleName + '.js' ;   
137            vModule.script.defer = true ;             
138            vModule.loaded      = false ; 
139            
140            FLoadedModules.push(vModule) ; 
141            
142            vModule.script.onload = function() {
143                vModule.loaded = true ; 
144                fwCore.log('Module ' + vModule.name + ' loaded', LOGLEVEL_DEBUG) ; 
145                evalModuleLoaded() ; 
146            }
147
148            vModule.script.onerror = function() {
149                vModule.loaded = false ; 
150                fwCore.log('Module ' + vModule.name + ' load error', LOGLEVEL_ERROR) ; 
151            }
152            
153            document.head.appendChild(vModule.script) ;                         
154                        
155            return true ; 
156        } else {
157            fwCore.log('Module ' + aModuleName + ' alredy loaded', LOGLEVEL_DEBUG) ; 
158            return false ; 
159        }        
160    }
161    
162    function evalModuleLoaded() {
163        for (var i in FLoadedModules) {
164            var vModule = FLoadedModules[i] ;
165            if (!vModule.loaded)
166                return false ; 
167        }
168        
169        fwCore.log('All modules loaded') ;                 
170        doInitialized() ; 
171        
172        return true ; 
173    }
174    
175    // Parameters ===============================================================
176    
177    var FParameters = new Array() ;
178    
179    function getParameter(aKind, aName) {
180        for (var i in FParameters) {
181            var vParameter = FParameters[i] ; 
182            
183            if ((vParameter.kind == aKind) && (vParameter.name == aName)) {
184                return vParameter ; 
185            }
186        }
187        
188        return false ; 
189    }
190    
191    this.addParameter = function(aKind, aName, aValue) {
192        var vParameter = getParameter(aKind, aName) ; 
193        
194        if (!vParameter) {
195            vParameter = new TFrameworkParameter() ; 
196            vParameter.kind  = aKind ; 
197            vParameter.name  = aName ; 
198            vParameter.value = aValue ;
199            
200            FParameters.push(vParameter) ; 
201        }
202        
203        return vParameter ; 
204    }
205    
206    this.getParameterValue = function(aKind, aName, aDefaultValue = null) {
207        var vParameter = getParameter(aKind, aName) ; 
208        
209        if (vParameter) 
210            return vParameter.value ; 
211        
212        return aDefaultValue ; 
213    }
214
215// Resources ===============================================================
216    
217    var FResources = new Array() ;
218    var FDefaultResourcePath = '' ; 
219    
220    function getResource(aKind, aName) {
221        for (var i in FResources) {
222            var vResource = FResources[i] ; 
223            
224            if ((vResource.kind == aKind) && (vResource.name == aName)) {
225                return vResource ; 
226            }
227        }
228        
229        return false ; 
230    }
231    
232    this.setDefaultResourcePath = function(aPath) {
233        FDefaultResourcePath = aPath ; 
234    }
235    
236    this.addResource = function(aKind, aName, aPath) {
237        var vResource = getResource(aKind, aName) ; 
238        
239        if (!vResource) {
240            vResource = new TFrameworkResource() ; 
241            vResource.kind = aKind ; 
242            vResource.name = aName ; 
243            vResource.path = aPath ;
244            
245            FResources.push(vResource) ; 
246        }
247        
248        return vResource ; 
249    }
250    
251    this.getResourcePath = function(aKind, aName) {
252        var vResource = getResource(aKind, aName) ; 
253        
254        if (vResource) 
255            return vResource.path ; 
256        
257        return FDefaultResourcePath ; 
258    }
259    
260    // Shared Data =============================================================
261    
262    var FShared = new Array() ;
263    this.onSharedLoaded = false ; 
264    
265    this.getShared = function(aName) {
266        for(var i in FShared) {
267            var vShared = FShared[i] ; 
268            
269            if (vShared.name == aName)
270                return vShared ; 
271        }
272        
273        return null ; 
274    }
275    
276    this.addShared = function(aName, aData, aOnLoad) {
277        var vShared = that.getShared(aName) ; 
278        
279        if (!vShared) {
280            vShared = new TFrameworkShared() ; 
281            vShared.name = aName ;             
282            
283            FShared.push(vShared) ; 
284        }
285        
286        vShared.data = aData ; 
287        vShared.onLoad = aOnLoad ; 
288        vShared.invalidate() ; 
289        
290        return vShared ;         
291    }
292    
293    this.checkSharedLoaded = function() {    
294        for (var i in FShared) {
295            var vShared = FShared[i] ; 
296            if ((!vShared.isLoaded()) || (vShared.mustReload()))
297                return false ; 
298        }
299        
300        fwCore.log('All shared are loaded') ; 
301        
302        if (this.onSharedLoaded)
303            this.onSharedLoaded() ; 
304        
305        return true ; 
306    }
307    
308    this.getSharedData = function(aName) {
309        var vShared = that.getShared(aName) ; 
310        if (!vShared)
311            return false ; 
312        
313        return vShared.data ; 
314    }
315        
316    this.invalidateShared = function(aName) {
317        var vShared = that.getShared(aName) ; 
318        
319        if (vShared) {
320            vShared.invalidate() ; 
321            that.reloadShared() ; 
322            
323            return true ; 
324        }
325                        
326        return false ; 
327    }
328
329    this.invalidateAllShared = function() {
330        fwCore.log('Invalidating all shared data', LOGLEVEL_DEBUG) ; 
331        
332        for(var i in FShared) {
333            var vShared = FShared[i] ; 
334            vShared.invalidate() ;             
335        }        
336        
337        that.reloadShared() ;
338    }
339    
340    this.reloadShared = function() {
341        for(var i in FShared) {
342            var vShared = FShared[i] ; 
343            
344            if (vShared.mustReload()) {
345                vShared.load() ;             
346            }
347        }                       
348    }
349    
350    this.loadShared = function(aOnSharedLoaded = false) {
351        if (aOnSharedLoaded)
352            this.onSharedLoaded = aOnSharedLoaded ; 
353        
354        that.reloadShared();       
355    }
356        
357    // Messaging ===============================================================
358    
359    var FComponents = new Array() ; 
360    
361    function getComponent(aComponent) {
362        for (var i in FComponents) {
363            var vComponent = FComponents[i] ; 
364            if (vComponent == aComponent)
365                return vComponent ; 
366        }
367        return false ; 
368    }
369    
370    this.registerComponent = function(aComponent) {
371        var vComponent = getComponent(aComponent) ; 
372        if (!vComponent) {
373            vComponent = aComponent ; 
374            FComponents.push(vComponent) ; 
375        }
376        
377        return vComponent ; 
378    }
379
380    this.unregisterComponent = function(aComponent) {
381        for (var i in FComponents) {
382            var vComponent = FComponents[i] ; 
383            if (vComponent == aComponent) {
384                FComponents.splice(i, 1) ; 
385                return true ; 
386            }
387        }
388        return false ; 
389    }
390    
391    this.broadcastComponent = function(aFuncName, aParam) {
392        for (var i in FComponents) {
393            var vComponent = FComponents[i] ; 
394            
395            try {
396                if (aFuncName in vComponent) {
397                    vComponent[aFuncName](aParam) ; 
398                }                
399            } catch (e) {
400                fwCore.log('Broadcast Component Exception : ' + e, LOGLEVEL_ERROR) ; 
401                FComponents.splice(i, 1) ;      // remove invalid component
402            }            
403        }
404    }
405    
406    // Drag Drop ===============================================================
407    
408    this.dragObject = false ; 
409    
410    this.getDragObjectType = function() {
411        if (!that.dragObject)
412            return false ; 
413        
414        if (Array.isArray(that.dragObject)) 
415            return that.dragObject[0].constructor.name ; 
416        
417        if (typeof that.dragObject == 'object')                         
418            return that.dragObject.constructor.name ; 
419        
420        return (typeof that.dragObject) ; 
421    }
422    
423    // Log =====================================================================
424    
425    this.debug = function(aMsg) {
426        that.log(aMsg, LOGLEVEL_DEBUG) ; 
427    }
428    
429    this.log = function(aMsg, aLevel = LOGLEVEL_INFO) {
430        if (aLevel >= that.logLevel) {
431            if (Array.isArray(aMsg)) {
432                console.table(aMsg) ; 
433            } else {
434                switch (aLevel) {
435                    case LOGLEVEL_TRACE :
436                        console.trace(aMsg) ; 
437                        break ; 
438                    case LOGLEVEL_DEBUG :
439                        console.debug(aMsg) ; 
440                        break ; 
441                    case LOGLEVEL_INFO :
442                        console.info(aMsg) ; 
443                        break ; 
444                    case LOGLEVEL_NOTICE :
445                        console.notice(aMsg) ; 
446                        break ; 
447                    case LOGLEVEL_WARNING :
448                        console.warn(aMsg) ; 
449                        break ; 
450                    case LOGLEVEL_ERROR :
451                        console.error(aMsg) ; 
452                        break ; 
453                }                
454            }
455        }
456    }
457    
458    // Display =================================================================
459
460    var FDisplaySizes = new Array() ;     
461    this.onDisplaySizeChange = false ; 
462    this.displaySize = false ; 
463    this.displayWidth = 0 ; 
464    this.displayHeight = 0 ; 
465    this.displayOrientation = ORIENTATION_HORIZONTAL ; 
466    
467    function initDisplaySize() {
468        window.addEventListener('resize', doDisplaySizeChange, false) ;
469        doDisplaySizeChange() ; 
470    }
471    
472    function getDisplaySize(aName, aOrientation = ORIENTATION_HORIZONTAL) {
473        for(var i in FDisplaySizes) {
474            var vDisplaySize = FDisplaySizes[i] ; 
475            if ((vDisplaySize.name == aName) && (vDisplaySize.orientation == aOrientation))
476                return vDisplaySize ; 
477        }
478        
479        return false ; 
480    }
481    
482    this.addDisplaySize = function(aName, aMinWidth = false, aMaxWidth = false, aOrientation = ORIENTATION_HORIZONTAL) {
483        var vDisplaySize = getDisplaySize(aName, aOrientation) ; 
484        
485        if (!vDisplaySize) {
486            vDisplaySize = new TFrameworkDisplaySize() ; 
487            vDisplaySize.name = aName ; 
488            
489            vDisplaySize.orientation = aOrientation ; 
490            vDisplaySize.minWidth    = aMinWidth ;             
491            vDisplaySize.maxWidth    = aMaxWidth ; 
492            
493            FDisplaySizes.push(vDisplaySize) ; 
494            doDisplaySizeChange() ; 
495        }
496        
497        return vDisplaySize ; 
498    }
499    
500    function doDisplaySizeChange() {
501        if (!FInitialized)
502            return false ; 
503        
504        that.displayWidth  = FParent.clientWidth ; 
505        that.displayHeight = FParent.clientHeight ; 
506        that.displayOrientation = (that.displayWidth >= that.displayHeight)?ORIENTATION_HORIZONTAL:ORIENTATION_VERTICAL ; 
507
508        if ((that.displaySize) && (that.displaySize.orientation == that.displayOrientation)) {
509            if (that.displaySize.isBound(that.displayWidth, that.displayHeight))
510                return false ; 
511        }
512        
513        for (var i in FDisplaySizes) {
514            var vDisplaySize = FDisplaySizes[i] ; 
515            if ((vDisplaySize.isBound(that.displayWidth, that.displayHeight)) && (vDisplaySize.orientation == that.displayOrientation)) {
516                that.displaySize = vDisplaySize ;                 
517                doDisplaySizeChanged(vDisplaySize) ; 
518                
519                return vDisplaySize ; 
520            }
521        }
522        
523        return false ; 
524    }
525    
526    function doDisplaySizeChanged(aDisplaySize) {
527        fwCore.log('Display size has changed : ' + that.displaySize.name) ; 
528        that.broadcastComponent('msgDisplaySizeChanged', that.displaySize) ; 
529    }
530        
531    // Utils ===================================================================
532    
533    this.createDiv = function(aParent = false, aPosition = false, aLeft = false, aTop = false, aRight = false, aBottom = false, aWidth=false, aHeight=false) {
534	var vDiv = document.createElement('div') ; 
535	that.setDivPosition(vDiv, aPosition, aLeft, aTop, aRight, aBottom, aWidth, aHeight) ; 	
536	if (aParent)
537		aParent.appendChild(vDiv) ; 
538            
539	return vDiv ; 
540    }
541
542    this.createMainDiv = function(aParent = false) {
543	var vDiv = document.createElement('div') ; 
544	that.setDivPosition(vDiv, 'absolute', '0px', '0px', '0px', '0px', '', '') ; 	
545	if (aParent)
546		aParent.appendChild(vDiv) ; 
547            
548	return vDiv ; 
549    }
550    
551    this.setDivPosition = function(aDiv, aPosition = false, aLeft = false, aTop = false, aRight = false, aBottom = false, aWidth=false, aHeight=false) {
552	if (aPosition)  aDiv.style.position = aPosition ; 
553	
554	if (aLeft !== false)	aDiv.style.left     = aLeft ; 
555	if (aTop  !== false)	aDiv.style.top      = aTop ; 
556	if (aRight !== false)	aDiv.style.right    = aRight ; 
557	if (aBottom !== false)	aDiv.style.bottom   = aBottom ; 	
558	
559	if (aWidth !== false)	aDiv.style.width    = aWidth ; 	
560	if (aHeight !== false)	aDiv.style.height   = aHeight ; 	                
561    }
562    
563    this.setDivAlign = function(aDiv, aAlign = false) {
564        switch (aAlign) {
565            case ALIGN_NONE : 
566                that.setDivPosition(aDiv, 'absolute', '0px', '0px', '', '', false, false) ; 
567                break ; 
568            case ALIGN_LEFT : 
569                that.setDivPosition(aDiv, 'absolute', '0px', '0px', '', '0px', false, '') ; 
570                break ; 
571            case ALIGN_TOP : 
572                that.setDivPosition(aDiv, 'absolute', '0px', '0px', '0px', '', '', false) ; 
573                break ; 
574            case ALIGN_RIGHT : 
575                that.setDivPosition(aDiv, 'absolute', '', '0px', '0px', '0px', false, '') ; 
576                break ; 
577            case ALIGN_BOTTOM : 
578                that.setDivPosition(aDiv, 'absolute', '0px', '', '0px', '0px', '', false) ; 
579                break ; 
580            case ALIGN_CLIENT : 
581                that.setDivPosition(aDiv, 'absolute', '0px', '0px', '0px', '0px', '', '') ; 
582                break ; 
583        }        
584    }
585    
586    this.async = function(aFunc) {
587        setTimeout(aFunc, 1) ; 
588    }
589    
590    Init() ;
591}
592//==============================================================================
593function TFrameworkModule() {
594    var that = this ; 
595    
596    this.name = '' ; 
597    this.script = false ; 
598    this.loaded = false ; 
599}
600//==============================================================================
601function TFrameworkParameter() {
602    var that = this ; 
603    
604    this.kind = '' ; 
605    this.name = '' ; 
606    this.value = '' ;
607}
608//==============================================================================
609function TFrameworkResource() {
610    var that = this ; 
611    
612    this.kind = '' ; 
613    this.name = '' ; 
614    this.path = '' ;
615}
616//==============================================================================
617function TFrameworkShared() {
618    var that = this ; 
619    
620    this.name   = '' ; 
621    this.data   = '' ;    
622    this.onLoad     = false ; 
623    this.onLoaded   = false ; 
624            
625    var FMustReload = false ; 
626    var FLoaded     = false ; 
627    
628    this.mustReload = function() {
629        return FMustReload ; 
630    }
631    
632    this.load = function() {
633        fwCore.debug('Loading shared data : ' + that.name) ; 
634        FLoaded = false ; 
635        
636        if (that.onLoad) {
637            that.onLoad(that) ; 
638        }
639    }
640    
641    this.isLoaded = function() {
642        return FLoaded ; 
643    }
644    
645    this.loaded = function() {
646        FMustReload = false ; 
647        FLoaded = true ; 
648        fwCore.debug('Shared data loaded : ' + that.name) ; 
649        
650        if (that.onLoaded) {
651            that.onLoaded(that) ; 
652        }
653        
654        fwCore.checkSharedLoaded() ; 
655    }
656    
657    this.invalidate = function() {
658        FMustReload = true ; 
659    }    
660}
661//==============================================================================
662function TFrameworkDisplaySize() {
663    var that = this ; 
664    
665    this.name = '' ; 
666    this.orientation = ORIENTATION_HORIZONTAL ; 
667    this.minWidth  = 0 ; 
668    this.minWidth  = 0 ; 
669    
670    this.isBound = function(aWidth, aHeight) {
671        var vBounded = (
672            ((aWidth >= that.minWidth) ||  (that.minWidth == false))
673            && ((aWidth <= that.maxWidth) || (that.maxWidth == false))
674        ) ; 
675
676        return vBounded ; 
677    }
678}
679//==============================================================================

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.