window.addEventListener( 'message', function( event ) { if ( event.origin.indexOf( 'webdisclosure' ) > 0 ) { var h = +event.data || 0; console.log( 'SymexPostMessage: ' + h ); if ( h > 0 ) { jQuery( '.symex-iframe' ).css( 'height', h ); } } } ); var globalLib = { toNumber: function( price ) { price = ( price || 0 ).toString().replace( ',', '.' ); price = price.toString().replace( eval( '/\\s+/g' ), '' ); price = parseFloat( price ) || 0; if ( price < 0 ) { price *= -1; } return price; }, googleAnalytics: function( url ) { if ( typeof ga !== 'undefined' ) { ga( 'send', 'pageview', { 'page': url } ); } } }; /* * Config the app */ var globalApp = angular.module( 'globalApp', [] ); globalApp.config( function( $locationProvider ) { $locationProvider.html5Mode( false ); } ); /* * Components */ globalApp.component( 'page404', { templateUrl: '/components/404.html', controller: [ '$location', function( $location ) { globalLib.googleAnalytics( $location.url() ); } ] } ); globalApp.component( 'spSharePriceMarkets', { templateUrl: '/components/sp2/share-price-markets.html', controller: [ '$http', '$location', '$scope', function( $http, $location, $scope ) { var this_ = this; this_.data = {}; this_.data.market = null; this_.data.index = null; var loadData = function() { this_.isLoading = true; $http // .post( '/rest/sp2/share-price-markets.php', $location.search() ) // .then( function( response ) { this_.isLoading = false; if ( response.data.lang ) { this_.lang = response.data.lang; this_.markets = response.data.markets; this_.indexes = response.data.indexes; this_.stocks = response.data.stocks; this_.urls = response.data.urls; this_.pg = response.data.pg; this_.data.market = response.data.market_; this_.data.index = response.data.index_; } } ); } this_.setMarket = function( market ) { this_.data.market = market; var p = $location.search(); p.market = market; p.index = null; p.page = null; $location.search( p ); }; this_.setIndex = function() { var p = $location.search(); p.index = this_.data.index; p.market = null; p.page = null; $location.search( p ); }; this_.setPage = function( page ) { var p = $location.search(); p.page = page; $location.search( p ); // $( window ).scrollTop( 0 ); }; $scope.$on( '$locationChangeSuccess', function() { loadData(); globalLib.googleAnalytics( $location.url() ); } ); } ] } ); globalApp.component( 'spWgAwards', { templateUrl: '/components/sp2/wg-awards.html', bindings: { title: '<', varType: '@' }, controller: [ '$http', function( $http ) { var this_ = this; this_.loadData = function() { this_.isLoading = true; $http // .post( '/rest/sp2/wg-awards.php', { varType: this_.varType } ) // .then( function( response ) { this_.isLoading = false; if ( response.data.lang ) { this_.lang = response.data.lang; this_.stocks = response.data.stocks; this_.urls = response.data.urls; } } ); }; // Go... this_.$onInit = function() { this_.loadData(); }; } ] } ); globalApp.component( 'spWgMarketMap', { templateUrl: '/components/sp2/wg-market-map.html', bindings: { market: '@', title: '<' }, controller: [ '$http', function( $http ) { var this_ = this; this_.loadData = function() { this_.isLoading = true; $http // .post( '/rest/sp2/wg-market-map.php', { market: this_.market } ) // .then( function( response ) { this_.isLoading = false; if ( response.data.lang ) { this_.lang = response.data.lang; this_.stocks = response.data.stocks; this_.urls = response.data.urls; } } ); }; // Go... this_.$onInit = function() { this_.loadData(); }; } ] } ); globalApp.component( 'spWgIndexes', { templateUrl: '/components/sp2/wg-indexes.html', bindings: { title: '<' }, controller: [ '$http', '$timeout', function( $http, $timeout ) { var this_ = this; this_.isLoading = null; this_.stock_ = null; var tmpTicker = null; var tmpPays = null; var tmpWidth = null; var loadData = function() { this_.isLoading = true; $http // .post( '/rest/sp2/wg-indexes.php' ) // .then( function( response ) { this_.isLoading = false; if ( response.data.lang ) { this_.lang = response.data.lang; this_.stocks = response.data.stocks; $timeout( function() { this_.chartBeta( this_.stocks[ 0 ] ); }, 100 ); } } ); }; this_.chartBeta = function( stock ) { var ticker = null; var pays = null; var obj = $( '.wg-indexes-chart' ); if ( stock ) { this_.stock_ = stock; ticker = tmpTicker = stock.ticker; pays = tmpPays = stock.pays; tmpWidth = null; } else { ticker = tmpTicker; pays = tmpPays; } if ( obj.length !== 1 ) { return false; } if ( tmpWidth && tmpWidth === obj.width() ) { return; } var height = 160; var width = obj.width(); tmpWidth = width; if ( width < 180 ) { return; } var url = ''; url += '//charts.symex.be/intraday/chart.php'; url += '?customer=lesoir'; url += '&period=intra'; url += '&qty=1'; url += '&lang=fr'; url += '&height=' + height; url += '&width=' + width; url += '&ticker=' + ticker + ',' + pays; var chart = ''; chart += ''; obj.html( chart ); }; this_.$onInit = function() { loadData(); }; this_.$postLink = function() { $( window ).on( 'resize.spWgIndexesChart', function() { this_.chartBeta(); } ); }; this_.$onDestroy = function() { $( window ).off( 'resize.spWgIndexesChart' ); }; } ] } ); globalApp.component( 'spWgCurrencies', { templateUrl: '/components/sp2/wg-currencies.html', bindings: { title: '<' }, controller: [ '$http', '$location', function( $http, $location ) { var this_ = this; this_.isLoading = null; this_.lang = null; this_.mainCurrs = null; this_.urls = null; var loadData = function() { this_.isLoading = true; $http // .post( '/rest/sp2/wg-currencies.php', $location.search() ) // .then( function( response ) { this_.isLoading = false; if ( response.data.lang ) { this_.lang = response.data.lang; this_.mainCurrs = response.data.mainCurrs; this_.urls = response.data.urls; } } ); }; this_.$onInit = function() { loadData(); }; } ] } ); globalApp.component( 'spWgCurrsConvertor', { templateUrl: '/components/sp2/wg-currs-convertor.html', bindings: { title: '<' }, controller: [ '$http', '$location', function( $http, $location ) { var this_ = this; this_.baseCurrency = null; this_.calcCurrs = null; this_.isLoading = null; this_.isSending = null; this_.lang = null; this_.urls = null; this_.calcData = {}; this_.calcData.currA = 'EUR'; this_.calcData.currB = 'USD'; this_.calcData.value = 1; this_.calcRes = {}; this_.calcRes.coef = null; this_.calcRes.total = null; this_.chartDefs = {}; this_.chartDefs.tickPays = null; this_.chartDefs.width = null; var loadData = function() { this_.isLoading = true; $http // .post( '/rest/sp2/wg-currs-convertor.php' ) // .then( function( response ) { this_.isLoading = false; if ( response.data.lang ) { this_.baseCurrency = response.data.baseCurrency; this_.calcCurrs = response.data.calcCurrs; this_.lang = response.data.lang; this_.urls = response.data.urls; this_.calcCoef(); } } ); }; this_.calcCoef = function() { if ( this_.isSending ) { return; } this_.isSending = true; $http // .post( '/rest/sp2/_calc-currencies.php', this_.calcData ) // .then( function( response ) { this_.isSending = false; this_.calcRes.coef = response.data.coef; this_.calcRes.total = response.data.total; } ); this_.chartBeta( this_.calcCurrs[ this_.calcData.currB ].ticker ); }; this_.chartBeta = function( tickPays ) { var obj = $( '.wg-currs-convertor-chart' ); if ( obj.length !== 1 ) { return false; } if ( tickPays === null ) { return false; } if ( tickPays ) { this_.chartDefs.tickPays = tickPays; this_.chartDefs.width = null; } if ( this_.chartDefs.width === obj.width() ) { return; } this_.chartDefs.height = 160; this_.chartDefs.width = obj.width(); if ( this_.chartDefs.width < 180 ) { return; } var url = ''; url += '//charts.symex.be/historical/chart.php'; url += '?customer=lesoir'; url += '&period=years'; url += '&qty=3'; url += '&lang=fr'; url += '&height=' + this_.chartDefs.height; url += '&width=' + this_.chartDefs.width; url += '&ticker=' + this_.chartDefs.tickPays; var chart = ''; chart += ''; obj.html( chart ); }; this_.$onInit = function() { loadData(); }; this_.$postLink = function() { $( window ).on( 'resize.spWgCuursConvertorChart', function() { this_.chartBeta(); } ); }; this_.$onDestroy = function() { $( window ).off( 'resize.spWgCuursConvertorChart' ); }; } ] } ); globalApp.component( 'spWgCommodities', { templateUrl: '/components/sp2/wg-commodities.html', bindings: { title: '<' }, controller: [ '$http', '$location', function( $http, $location ) { var this_ = this; this_.isLoading = null; this_.lang = null; this_.mainComms = null; this_.urls = null; var loadData = function() { this_.isLoading = true; $http // .post( '/rest/sp2/wg-commodities.php' ) // .then( function( response ) { this_.isLoading = false; if ( response.data.lang ) { this_.lang = response.data.lang; this_.mainComms = response.data.mainComms; this_.urls = response.data.urls; } } ); }; this_.$onInit = function() { loadData(); }; } ] } ); globalApp.component( 'spWgMarquee', { templateUrl: '/components/sp2/wg-marquee.html?v20190306', controller: [ '$http', function( $http ) { var this_ = this; this_.lang = null; this_.stocksA = null; this_.stocksB = null; this_.urls = null; this_.loadData = function() { this_.isLoading = true; $http // .post( '/rest/sp2/wg-marquee.php', { varType: this_.varType } ) // .then( function( response ) { this_.isLoading = false; if ( response.data.lang ) { this_.lang = response.data.lang; this_.stocksA = response.data.stocksA; this_.stocksB = response.data.stocksB; this_.urls = response.data.urls; } } ); }; // Go... this_.$onInit = function() { this_.loadData(); }; } ] } ); globalApp.component( 'spCompanyData', { templateUrl: '/components/sp2/company-data.html?v20190306', bindings: { ticker: '@' }, controller: [ '$http', '$location', '$timeout', function( $http, $location, $timeout ) { var this_ = this; this_.isLoading = null; this_.lang = null; this_.stock = null; this_.stockHisto = null; this_.urls = null; var chart = function( ticker, pays ) { var obj = $( '[data-role=stock-data-chart]' ); if ( obj.length !== 1 ) { return false; } var height = 300; var width = obj.width(); if ( obj.data( 'width' ) == width ) { return true; } obj.html( ' ' ); var url = ''; url += '//charts.symex.be/historical/chart.php'; url += '?customer=lesoir'; url += '&period=months'; url += '&qty=1'; url += '&lang=fr'; url += '&height=' + height; url += '&width=' + width; url += '&ticker=' + ticker + ',' + pays; var chart = ''; chart += ''; obj.data( 'width', width ); obj.html( chart ); }; var loadData = function() { this_.isLoading = true; $http // .post( '/rest/sp2/company-data.php', { ticker: this_.ticker } ) // .then( function( response ) { this_.isLoading = false; this_.lang = response.data.lang; this_.stock = response.data.stock; this_.stockHisto = response.data.stockHisto; this_.urls = response.data.urls; // Run the chart if ( this_.stock ) { $timeout( function() { chart( this_.stock.ticker, this_.stock.pays ); }, 0 ); } } ); }; this_.$onInit = function() { loadData(); globalLib.googleAnalytics( $location.url() ); }; this_.$postLink = function() { $( window ).on( 'resize.stockDataChart', function() { if ( this_.stock ) { chart( this_.stock.ticker, this_.stock.pays ); } } ); }; this_.$onDestroy = function() { $( window ).off( 'resize.stockDataChart' ); }; } ] } ); globalApp.component( 'spCompanyChart', { templateUrl: '/components/sp2/company-chart.html?v20190306', bindings: { ticker: '@' }, controller: [ '$http', '$location', '$timeout', function( $http, $location, $timeout ) { var this_ = this; this_.chartSettings = null; this_.isLoading = null; this_.lang = null; this_.stock = null; this_.urls = null; var chart = function( reload ) { var obj = $( '[data-role=stock-data-chart]' ); if ( obj.length !== 1 ) { return false; } var width = obj.width(); var height = this_.chartSettings.height; var ticker = this_.chartSettings.ticker; if ( width < 500 ) { height = this_.chartSettings.heightSmart; } if ( !reload && this_.chartSettings.width == width ) { return true; } for ( var i in this_.chartSettings.ticks ) { if ( this_.chartSettings.ticks[ i ].isSet ) { ticker += ( ';' + this_.chartSettings.ticks[ i ].code ); } } var baseUrl = this_.chartSettings.histoUrl; if ( this_.chartSettings.period === 'intra' || // this_.chartSettings.period === 'week' ) { baseUrl = this_.chartSettings.intraUrl; } obj.html( ' ' ); var url = ''; url += baseUrl; url += '?customer=' + this_.chartSettings.customer; url += '&period=' + this_.chartSettings.period; url += '&qty=' + this_.chartSettings.qty; url += '&vol=' + this_.chartSettings.vol; url += '&sum=' + ( width < 500 ? 0 : this_.chartSettings.sum ); url += '&lang=' + this_.chartSettings.lang; url += '&height=' + height; url += '&width=' + width; url += '&ticker=' + ticker; var chart = ''; chart += ''; this_.chartSettings.width = width; obj.html( chart ); }; var loadData = function() { this_.isLoading = true; $http // .post( '/rest/sp2/company-chart.php', { ticker: this_.ticker } ) // .then( function( response ) { this_.chartSettings = response.data.chartSettings; this_.isLoading = false; this_.lang = response.data.lang; this_.stock = response.data.stock; this_.urls = response.data.urls; // Run the chart if ( this_.chartSettings ) { $timeout( function() { chart(); }, 0 ); } } ); }; this_.setCompare = function( event ) { var obj = $( event.target ); var ticker = obj.data( 'ticker' ); for ( var i in this_.chartSettings.ticks ) { if ( this_.chartSettings.ticks[ i ].code === ticker ) { if ( obj.hasClass( 'active' ) ) { obj.removeClass( 'active' ); this_.chartSettings.ticks[ i ].isSet = false; } else { obj.addClass( 'active' ); this_.chartSettings.ticks[ i ].isSet = true; } } } chart( true ); }; this_.setChartPeriod = function( event ) { var obj = $( event.target ); var period = obj.data( 'period' ); var p = period.split( ',' )[ 0 ]; var q = period.split( ',' )[ 1 ]; this_.chartSettings.period = p; this_.chartSettings.qty = q; obj.parent().find( 'a' ).removeClass( 'active' ); obj.addClass( 'active' ); chart( true ); }; this_.$onInit = function() { loadData(); globalLib.googleAnalytics( $location.url() ); }; this_.$postLink = function() { $( window ).on( 'resize.stockDataChart', function() { chart(); } ); }; this_.$onDestroy = function() { $( window ).off( 'resize.stockDataChart' ); }; } ] } ); globalApp.component( 'spWgSearch', { templateUrl: '/components/sp2/wg-search.html', bindings: { type: '@' }, controller: [ '$http', // function( $http ) { var this_ = this; this_.data = {}; this_.data.searched = null; this_.data.type = null; this_.isLoading = null; this_.stocks = null; this_.urls = null; this_.search = function() { if ( !this_.data.searched || this_.data.searched.length < 2 ) { return; } this_.isLoading = true; $http // .post( '/rest/sp2/wg-search.php', this_.data ) // .then( function( response ) { this_.isLoading = false; this_.stocks = response.data.stocks; this_.urls = response.data.urls; } ); }; // ! Bindings are available only after init event this_.$onInit = function() { this_.data.type = this_.type; }; } ] } ); globalApp.component( 'spCommodityData', { templateUrl: '/components/sp2/commodity-data.html?v20190306', bindings: { ticker: '@' }, controller: [ '$http', '$location', '$timeout', function( $http, $location, $timeout ) { var this_ = this; this_.isLoading = null; this_.lang = null; this_.stock = null; this_.stockHisto = null; this_.urls = null; var chart = function( ticker, pays ) { var obj = $( '[data-role=commodity-data-chart]' ); if ( obj.length !== 1 ) { return false; } var height = 300; var width = obj.width(); if ( obj.data( 'width' ) == width ) { return true; } obj.html( ' ' ); var url = ''; url += '//charts.symex.be/historical/chart.php'; url += '?customer=lesoir'; url += '&period=years'; url += '&qty=1'; url += '&lang=fr'; url += '&height=' + height; url += '&width=' + width; url += '&ticker=' + ticker + ',' + pays; var chart = ''; chart += ''; obj.data( 'width', width ); obj.html( chart ); }; var loadData = function() { this_.isLoading = true; $http // .post( '/rest/sp2/commodity-data.php', { ticker: this_.ticker } ) // .then( function( response ) { this_.isLoading = false; this_.lang = response.data.lang; this_.stock = response.data.stock; this_.stockHisto = response.data.stockHisto; this_.urls = response.data.urls; // Run the chart if ( this_.stock ) { $timeout( function() { chart( this_.stock.ticker, this_.stock.pays ); }, 0 ); } } ); }; this_.$onInit = function() { loadData(); globalLib.googleAnalytics( $location.url() ); }; this_.$postLink = function() { $( window ).on( 'resize.commodityDataChart', function() { if ( this_.stock ) { chart( this_.stock.ticker, this_.stock.pays ); } } ); }; this_.$onDestroy = function() { $( window ).off( 'resize.commodityDataChart' ); }; } ] } ); globalApp.component( 'spCommunications', { templateUrl: '/components/sp2/communications.html', controller: [ '$http', '$location', '$sce', function( $http, $location, $sce ) { var this_ = this; this_.isLoading = null; this_.lang = null; this_.urls = null; this_.toUrl = function( url ) { return $sce.trustAsResourceUrl( url ); }; var loadData = function() { this_.isLoading = true; $http // .post( '/rest/sp2/communications.php' ) // .then( function( response ) { this_.isLoading = false; this_.lang = response.data.lang; this_.urls = response.data.urls; } ); }; this_.$onInit = function() { loadData(); }; } ] } ); globalApp.component( 'spCommsContent', { templateUrl: '/components/sp2/comms-content.html', bindings: { id: '@', ticker: '@' }, controller: [ '$http', '$location', '$sce', function( $http, $location, $sce ) { var this_ = this; this_.isLoading = null; this_.lang = null; this_.stock = null; this_.urls = null; this_.toUrl = function( url ) { return $sce.trustAsResourceUrl( url ); }; var loadData = function() { this_.isLoading = true; $http // .post( '/rest/sp2/comms-content.php', { id: this_.id, ticker: this_.ticker } ) // .then( function( response ) { this_.isLoading = false; this_.lang = response.data.lang; this_.stock = response.data.stock; this_.urls = response.data.urls; } ); }; this_.$onInit = function() { loadData(); }; } ] } ); globalApp.component( 'spCompanyComms', { templateUrl: '/components/sp2/company-comms.html', bindings: { ticker: '@' }, controller: [ '$http', '$location', '$sce', function( $http, $location, $sce ) { var this_ = this; this_.isLoading = null; this_.lang = null; this_.stock = null; this_.urls = null; this_.toUrl = function( url ) { return $sce.trustAsResourceUrl( url ); }; var loadData = function() { this_.isLoading = true; $http // .post( '/rest/sp2/company-comms.php', { ticker: this_.ticker } ) // .then( function( response ) { this_.isLoading = false; this_.lang = response.data.lang; this_.stock = response.data.stock; this_.urls = response.data.urls; } ); }; this_.$onInit = function() { loadData(); }; } ] } );