File: application/webfan/node_modules/webfan/my-webfan.js

Recommend this page to a friend!
  Classes of Till Wehowski   µ.Flow   application/webfan/node_modules/webfan/my-webfan.js   Download  
File: application/webfan/node_modules/webfan/my-webfan.js
Role: Class source
Content type: text/plain
Description: Class source
Class: µ.Flow
General purpose library of objects
Author: By
Last change: Update my-webfan.js
Date: 7 years ago
Size: 59,411 bytes
 

Contents

Class file image Download
/* webfan (C) Till Wehowski, Webfan.de - All rights reserved. */ function browserOnLoad(frame){ frame.addEventListener('beforeunload', function(){ frdl.UI.progress().start(); }); frame.addEventListener('load', function(){ webfan.$Async(function(){ frdl.UI.progress().complete(); },100); }); frdl.ready(function(){ $(frdl.$q('input[frdl-id="'+frame.getAttribute('frdl-id')+'"]', false)).hide(); $(frdl.$q('input[frdl-id="'+frame.getAttribute('frdl-id')+'"]', false)).fadeIn('fast'); try{ frdl.$q('input[frdl-id="'+frame.getAttribute('frdl-id')+'"]', false).setAttribute('placeholder', frame.contentWindow.location.href || frame.src); }catch(err){ frdl.$q('input[frdl-id="'+frame.getAttribute('frdl-id')+'"]', false).setAttribute('placeholder', frame.src); } }); } function openWidget(url){ frdl.ready(function(){ if('undefined'===typeof frdl.UI || 'function' !== typeof frdl.UI.progress){ return webfan.$Async(function(){ openWidget(url); },1000); } $('div[data-webkit-mod="PANEL.WIDGET"]') .attr('data-flow-tab-state-component-url', url) ; $('div[data-webkit-mod="PANEL.WIDGET"]').fadeIn('slow'); /* if(null === frdl.$q('webfan[name="'+url+'"]', false)){ */ frdl.UI.progress().start(); $('div[data-webkit-mod="PANEL.WIDGET"]') .html('<webfan name="'+url+'" type="widget"></webfan>') ; $(document).trigger('readystatechange'); webfan.$Async(function(){ $(document).trigger('readystatechange'); webfan.$Async(function(){ frdl.ready(function(){ frdl.UI.progress().complete(); webfan.$Async(function(){ frdl.ready(frdl.UI.progress().complete); },2000); }); },2000); },1000); /*} */ }); } function eraseWidgets(){ frdl.each(frdl.$q('li[data-flow-tab-state="component"]'), function(i, el){ if('component' !== el.getAttribute('data-flow-tab-state'))return true; var id = el.getAttribute('frdl-id'); window.Tabs().removeTab(id); $('div[data-webkit-mod="PANEL.WIDGET"]') .children() .hide() .remove() ; }); } function _decodeUrl(newUrl){ newUrl=urldecode(newUrl); newUrl=str_replace('~2F~2F', '//', newUrl); newUrl=str_replace('~2F', '/', newUrl); return newUrl; } (function(){ 'use strict'; function GUI(gui){ gui.ready = new frdl.EventEmitter; gui.onReady = gui.ready.required([ 'theme loaded', 'module $frdl.wd().Menu loaded', 'module $frdl.wd loaded', 'module $5:http://'+frdl.route('HOST_CDN_PUBLIC_FRDL')+'/cdn/frdl/flow/components/webfan/workspace/js/desktop.js loaded', 'module $5:http://'+frdl.route('HOST_CDN_PUBLIC_FRDL')+'/cdn/frdl/flow/components/webfan/workspace/js/webfan.gui.MenuCtrl.js loaded', 'tabs loaded' ], function (dataArray) { console.log('gui.onReady event'); frdl.ready(function() { webfan.$Async(function(){ require('webfan/my-webfan-menu', function(MenuDummyNoExports){ frdl.ready(frdl.UI.progress().complete); }); },3500); webfan.$Async(function(){ if(window.location.hash.substr(0,'#/com.webfan.my/browse/'.length)==='#/com.webfan.my/browse/'){ webfan.$Async(function(){ var newUrl = window.location.hash.substr('#/com.webfan.my/browse/'.length, window.location.hash.length); newUrl=_decodeUrl(newUrl); window.Tabs().addTab(new frdl.Url(newUrl).getHost(), newUrl, null, 'browser', true, {name:'browser', params:{url:newUrl}}, true); },500); } },1); webfan.$Async(function(){ $('*[flow-mod="img.loading"]').fadeOut('slow'); $('*[flow-mod="img.loading"]').remove(); frdl.ready(function(){ $("html, body").animate({ scrollTop: 0 }, "slow"); if(true===frdl.UI.isMobileTheme){ $('*[frdl-webkit-id="side-menu-left"] > *[flow-toggler]').trigger('click'); } webfan.$Async(function(){ // frdl.wd(false).hide(); $('.browser-wrap-all').fadeIn('slow'); frdl.ready(frdl.UI.progress().complete); },100); }); },1); gui.isReady = true; }); }, frdl); gui.ready.once('theme loaded', function(){ frdl.UI.progress().start(); frdl.wd(false).hide(); frdl.wd(false).hide(); }); require.state.on('resolved', function(){ gui.ready.emit('module $'+arguments[0].identifier+' loaded', arguments[0]); }); var _configfile ='config.dat'; gui.configfile = function(file){ if(file){ _configfile = ('string' === typeof file && '.' !== file.substr(0,1)) ? file : (('function'===typeof file) ? file() : process.cwd(file)) }else{ return _configfile; } }; gui.getGUIManifest = function(){ return window.webfanWebkitSettings().manifest; }; return gui; } var gui = (true === navigator['-webkit-webfan']) ? GUI(navigator.webfan.GUI() ) : require('webfan/navigator/shim-nw-gui'); gui = GUI(gui); window.gui = gui; var fs = require('fs'); window.__Helper_profileHtml64 = frdl.base64_encode('<div data-frdl-component="http://example.com/webfan/webkit-profile"></div>'); window.openComponent = function(title, url, cssClass){ frdl.UI.progress().start(); eraseWidgets(); webfan.$Async(function(){ eraseWidgets(); webfan.$Async(function(){ window.Tabs().addTab(title, '/com.webfan.my/component', '', 'html', true, {name:'component', params:{url:url}, options : {reload:true}}, true, true, cssClass, true); /* frdl.UI.progress().stop(true); */ },1000); },250); }; window.browserOnLoad=browserOnLoad; window.openDesktopWidgetApp = function(component){ var mid = 'widget-'+Sha1.hash(component)+'-'+component.length; var iconID = 'icon_module_' + mid; location.hash='#';location.hash='#/app=&click=' + iconID; }; frdl.ready(function(){ var bootDelay = 100; var serviceInjectorUrl = '5:http://app.frdl.webfan.de/auth/-webkit-webfan/app-check'; var PATHPFX = '/com.webfan.my/'; var ROOTDEFAULT = webfan['$root-app'](); frdl.a .module('webfan.webkit',[ 'webfan.gui']) .config([ '$sceProvider','$stateProvider', '$urlRouterProvider', '$locationProvider', '$ocLazyLoadProvider', function( $sceProvider, $stateProvider, $urlRouterProvider, $locationProvider, $ocLazyLoadProvider) { $ocLazyLoadProvider.config({ debug : true, events: true }); $locationProvider.html5Mode(false); /* if(true===frdl.UI.isMobileTheme){ $locationProvider.html5Mode({ enabled: false, requireBase: true }); $locationProvider.hashPrefix('#'); $.mobile.pushStateEnabled = false; }else{ $locationProvider.html5Mode(false); } */ $sceProvider.enabled(false); $stateProvider /* .state( { name : 'root', url: "^/", abstract:true, resolve :{ loadSDK: ['$ocLazyLoad', '$injector', function($ocLazyLoad, $injector) { return $ocLazyLoad.load(['webfan.gui.sdk'], { serie: false, cache: true, rerun: false, reconfig: false } ).then(function() { console.log('dependency injection webfan.gui.sdk'); }); }], testInit : function(){ return function(){ return true; }; } routerPrepared: ['$rootScope', function($rootScope) { $rootScope.$on('$routeChangeStart', function(event){ event.preventDefault(); }); return true; }], // fs : FS } }) */ .state( { name : 'browser', url: PATHPFX+'browse/:url', params: { cmd: { dynamic: true } }, views: { "internalView": { controller:function($scope, $stateParams, $state){ /* console.dir($stateParams); */ } }/*, "viewTestB": { templateUrl: AppData.__DIR__+'templates/home.html' }*/ }, resolve :{ } }) .state( { name : 'start', url: PATHPFX+'start/:section', params: { cmd: { dynamic: true } }, views: { "startView": { templateUrl: './templates/start.html' , controller:function($scope, $stateParams, $state){ $scope.lang = { Welcome : __('Welcome', ['']) }; } } }, resolve :{ } }) .state( { name : 'component', url: PATHPFX+'component/:url', params: { cmd: { dynamic: true }, config: { dynamic: true } }, views: { "widgetView": { /* templateUrl: './templates/widget.html' , */ controller:function($scope, $stateParams, $state){ $scope.params = $stateParams; var u = new frdl.Url( _decodeUrl($scope.params.url) ); var url = _decodeUrl($scope.params.url); if('http'===u.getScheme() || 'https'===u.getScheme()){ frdl.alert.confirm('Do you trust and want top open: ' +url+'?', function (e) { if (e) { openWidget(url); } else { frdl.alert.log('Canceled'); } }); }else{ openWidget(url); } $('div[data-webkit-mod="PANEL.WIDGET"]').fadeIn('slow'); $('div[data-webkit-mod="PANEL.WIDGET"]').css('width', 'auto'); $('div[data-webkit-mod="PANEL.WIDGET"]').css('min-width', '320px'); } } }, resolve :{ } }) .state( { name : 'settings', url: PATHPFX+'settings/:section', params: { cmd: { dynamic: true }, config: { dynamic: true } }, views: { "internalView": { templateUrl: './templates/settings.html' , controller:function($sce, $scope, $stateParams, $state){ $scope.userAgent = navigator.userAgent; if(true===navigator.onLine){ frdl.$q('button[flow-mod="BTN:Clear Local Storage Data"]', false).removeAttribute('disabled'); frdl.$q('button[flow-mod="BTN:Clear JS Direct Cache"]', false).removeAttribute('disabled'); if(true === navigator['-webkit-webfan']){ frdl.$q('button[flow-mod="BTN:Clear App Cache"]', false).removeAttribute('disabled'); } } frdl.ready(function(){ webfan.$Async(function(){ $scope.selectDebugModeHTML = $sce.trustAsHtml('<select onchange="frdl.debug.mode(parseInt(this.options[this.selectedIndex].value));frdl.$DB.save(\'settings/debugmode\', frdl.debug.mode().toString());"><option value="'+frdl.debug.mode()+'" selected>Debugmode: '+frdl.debug.mode()+'</option><option value="0">Debugmode: 0</option><option value="1">Debugmode: 1</option><option value="2">Debugmode: 2</option></select>'); $scope.$digest(); },1000); }); } }/*, "viewTestB": { templateUrl: AppData.__DIR__+'templates/home.html' }*/ }, resolve :{ // fs : FS } }) .state({ name : 'install', url: webfan['$browser-scheme']() +'install/:version', params: { config: { dynamic: true } }, views :{ "installView" :{ templateUrl: "./templates/install.app", controller:function($scope, $stateParams, $state){ /* frdl.ready(function(){ webfan.$Async(function(){ var vocabulary = require('5:http://cdn.frdl.webfan.de/cdn/application/webfan/locale/module/install.helper.js', function(mod){ frdl.lang(vocabulary); }); },1); }); */ } }/*, "installSubView" : { templateUrl: "./templates/register.html" }*/ } }) ; }]) .controller('settingsCtrl', ['$sce', '$scope' , '$http' , '$stateParams', '$state', '$rootScope', function($sce, $scope, $http, $stateParams, $state, $stateProvider, $rootScope){ var applyManifest = function(){ frdl.$q('title', false).innerHTML = window.webfanWebkitSettings().manifest.name; if('undefined' !== typeof window.webfanWebkitSettings().manifest.icons){ frdl.each(window.webfanWebkitSettings().manifest.icons, function(i, icon){ if('16x16' === icon.sizes){ var el = frdl.$q('link[rel*="icon"], link[type="image\/x-icon"]', false); el.setAttribute('href', icon.src); el.setAttribute('sizes', icon.sizes); } }); } }; $scope.localizeAsync = function(){ /* frdl.ready(function(){ webfan.$Async(function(){ var vocabulary = require('5:http://cdn.frdl.webfan.de/cdn/application/webfan/locale/module/start.helper.js', function(mod){ frdl.lang(vocabulary); webfan.$Async(function(){ frdl.translate(); },600); }); },500); }); */ }; // $scope.ApplicationState = new frdl.EventEmitter(); var BootConfigLoadEvent = new frdl.EventEmitter(); var __l = false; BootConfigLoadEvent.once('bootconfig', function(){ function emitThemes(){ webfan.$Async(function(){ frdl.ready(function(){ gui.ready.emit('theme loaded', $scope); }); },1); } __l = true; applyManifest(); var c = arguments[0].config, fs = require('fs'); webfan.$Async(function(){ var _sql = "SELECT * FROM webkit.widgets WHERE enabled=true AND default=true"; var promise = frdl.sql.query(_sql, function(err, resultset) { if (err) { console.error(err); } else { if(0<frdl.debug.mode()) console.log('sql--sql :'); if(0<frdl.debug.mode())console.log('' + _sql); if(0<frdl.debug.mode()) console.log('\nsql--data:'); if(0<frdl.debug.mode()) console.dir(resultset); } }); promise.then( function(result) { if(0<frdl.debug.mode())console.log('promise--sql :'); if(0<frdl.debug.mode())console.log('' + _sql); if(0<frdl.debug.mode())console.log('\npromise--data:'); if(0<frdl.debug.mode())console.dir(result); var row, i; if(1>result.data.length){ result.data = [ ['component', 'frdl-component', true, false, true, 'widget://example.com/webfan/webkit', 'div[data-webkit-mod="components"]'], ['theme', 'frdl-component', true, false, true, 'widget://example.com/themes/default', 'div[data-webkit-mod="themes"]'] // ,['component', 'frdl-component', true, false, true, 'widget://example.com/frdl/webfan', '*[data-webkit-mod="page.top"]'] ]; frdl.alert.error('Error loading -webkit widgets!'); } while((row = frdl.sql.fetch_object(result)) && false !== row){ $(row.destination).append('<div data-'+row.type+'="'+row.url+'"></div>'); } $(document).trigger('readystatechange'); webfan.$Async(function(){ $(document).trigger('readystatechange'); webfan.$Async(function(){ webfan.$Async(function(){ webfan.$Async(function(){ frdl.ready(emitThemes); $(document).trigger('readystatechange'); },1); },10); },10); },10); }, function(errResult){ console.error(errResult); } ); var _sql = "SELECT * FROM webkit.tabs_active"; var promise2 = frdl.sql.query(_sql, function(err, resultset) { if (err) { console.error(err); } else { if(0<frdl.debug.mode()) console.log('sql--sql :'); if(0<frdl.debug.mode())console.log('' + _sql); if(0<frdl.debug.mode()) console.log('\nsql--data:'); if(0<frdl.debug.mode()) console.dir(resultset); } }); promise2.then( function(result) { if(0<frdl.debug.mode())console.log('promise--sql :'); if(0<frdl.debug.mode())console.log('' + _sql); if(0<frdl.debug.mode())console.log('\npromise--data:'); if(0<frdl.debug.mode())console.dir(result); var row; while((row = frdl.sql.fetch_object(result)) && false !== row){ if(PATHPFX+'start' === frdl.base64_decode(row.url))return ; if(PATHPFX+'data' === frdl.base64_decode(row.url))return ; if(webfan['$browser-scheme']() + 'install' === frdl.base64_decode(row.url))return ; if('/apc/' === frdl.base64_decode(row.url))return ; window.Tabs().addTab(frdl.base64_decode(row.title), frdl.base64_decode(row.url), frdl.base64_decode(row.html), row.type, row.cancable, row.state, false, false, row.cssClass, true); } console.dir(result); }, function(errResult){ console.error(errResult); } ); webfan.$Async(function(){ if('undefined'=== typeof window.Tabs().getTab(PATHPFX+'start')){ window.Tabs().addTab('Start', PATHPFX+'start', '', 'html', false, {name:'start', params:{}}, false, false, 'icon-attach-home'); } webfan.$Async(function(){ webfan.$Async(function(){ window.Tabs().addTab('Data', PATHPFX+'data', '<div data-frdl-component="widget://example.com/webfan/webfat"></div>', 'html', false, false, false, false, 'icon-attach-webfat'); webfan.$Async(function(){ window.Tabs().addTab('APC', '/apc/', '<div data-frdl-component="widget://example.com/frdl/webfan"></div>', 'html', false, false, false, false, 'icon-attach-apc'); window.Tabs().startTabs(); process.cwd(frdl.fs5.polyfill.getFiler().fs.root); fs.readFile('1.3.6.1.4.1.37553.8.1.8.8.10.1.1/~tab.CACHE', function(err, data){ if(err){ return; } window.Tabs().currentTab=JSON.parse(data); }); webfan.$Async(function(){ if(null===window.Tabs().currentTab){ window.Tabs().openTab(PATHPFX+'start'); } },50); frdl.ready(function(){ webfan.$Async(function(){ gui.ready.emit('tabs loaded', $scope); },300); }); },1); },1); },1); },1); },1); }); $scope.userAgent = navigator.userAgent; $scope.isWebKitStr = $sce.trustAsHtml((true ===navigator['-webkit-webfan']) ? '<span class="webfan-yellowgreen">YES</span>' : '<span class="webfan-red">NO</span>'); $scope.ApplicationRoot = webfan['path.exec'](); $scope.WebAppRoot = webfan['app://'](); $scope.clearLocalStorageAll=function(){ frdl.alert.confirm('Are you sure you want to Clear All Local Storage Data?<p class="error">Attention! You may loose data!</p>', function (e) { if (e) { if(true===navigator.onLine)localStorage.clear(); } else { } }); }; $scope.clearRequireCache=function(){ frdl.alert.confirm('Are you sure you want to Clear JS Direct Cache?<p class="error">Attention! You may loose data!</p>', function (e) { if (e) { if(true===navigator.onLine)require.clear(); } else { } }); }; $scope.clearAppCache=function(){ frdl.alert.confirm('Are you sure you want to Clear App Cache?<p class="error">Attention! You may loose data!</p>', function (e) { if (e) { if(true===navigator.onLine){ gui.App.clearCache(); } } else { } }); }; var b = function(){ if(false===__l){ BootConfigLoadEvent.emit('bootconfig', { config : $scope.manifest, time : new Date().getTime() }); } __l = true; b = function(){}; }; $scope.loadConfig = function(){ if('Chrome' !== frdl.Device().browser){ try{ process.cwd(frdl.fs5.polyfill.getFiler().fs.root); fs.readFile(gui.configfile(), function(err, data){ if(err){ b(); // console.warn(err); return; } $scope.manifest=JSON.parse(data); $scope.config=$scope.manifest; b(); applyManifest(); }); }catch(err){ b(); // console.warn(err); } }else{ process.cwd(frdl.fs5.polyfill.getFiler().fs.root); var c = fs.readFileSync(gui.configfile()); if(false !== c){ try{ $scope.manifest=JSON.parse(c); $scope.config=$scope.manifest; applyManifest(); }catch(err){ b(); console.warn('Cannot read config.dat!'); } } b(); } /* var c = fs.readFileSync(gui.configfile(), true); c.then(function(data){ $scope.manifest=JSON.parse(data); $scope.manifest = defaults($scope.manifest); $scope.config=$scope.manifest; b(); }, function(err){ if(0<frdl.debug.mode())console.warn(err); b(); }); */ }; $scope.checkStatus = function(){ if(true===$scope.manifest.installed)return; /* if(!!Proxy.isPolyfile){ var str = 'Proxy.isPolyfile => App:checkStatus skipped!'; if(!!console)console.warn(str); frdl.alert.error('Cannot install App! (checkStatus)'); return; } */ if(true===$scope.manifest.installed || 'function'!==typeof window.Tabs || 'undefined' === typeof window.Tabs().currentTab || location.hash === '#' + PATHPFX + 'start' || (!!$state.current && 'start'===$state.current.name) || ('function'===typeof window.Tabs && ( 'undefined' === typeof window.Tabs().currentTab || null === window.Tabs().currentTab || 'undefined' === typeof window.Tabs().currentTab.url || window.Tabs().currentTab.url === './about.html' ) ) || 'undefined' === typeof $scope.manifestServer )return webfan.$Async(function(){ $scope.checkStatus(); },15000); webfan.$Async(function(){ if(false===$scope.manifest.installed /* && window.Tabs().currentTab.url !== webfan['$browser-scheme']() +'install'*/ && 'install' !== $state.current.name && 'browser' !== $state.current.name ){ webfan.$Async(function(){ window.Tabs().addTab('Install Setup', webfan['$browser-scheme']() + 'install', '', 'html', true, {name:'install', params:{}}, true); },100); } else if($scope.manifestServer.version !== $scope.manifest.version && ( null === window.Tabs().currentTab || ( window.Tabs().currentTab.url !== './templates/install.app' && window.Tabs().currentTab.url !== './node_modules/updater/updater.html' ) ) ){ if(true===$scope.manifest.autoupdate){ window.webfanWebkitSettings().runUpdate(false); }else{ /* window.Tabs().addTab('Update', './node_modules/updater/updater.html', null, 'frame.trusted', true, undefined, true); webfan.$Async(function(){window.Tabs().openTab('./node_modules/updater/updater.html');},250); */ } } webfan.$Async(function(){ $scope.checkStatus(); },2500); },500); }; if('undefined'===typeof $scope.manifestServer)$scope.manifestServer=$scope.manifest; if(true===navigator.onLine){ $http.get(((true === navigator['-webkit-webfan']) ? ROOTDEFAULT : '') + frdl.$q('link[type="application/manifest+json"]', false).getAttribute('href')) .success(function(data, status, headers, config) { $scope.manifestServer=data; /* $scope.manifestServer.name += ' ('+$scope.manifestServer.id+')'; */ }) .error(function(data, status, headers, config) { console.info('cannot get '+'Application '+' manifest!'); $scope.manifestServer={ name : '-ERROR-', version : '0.0.0' }; }); }else{ $scope.manifestServer=$scope.manifest; } $scope.saveManifest = function(){ process.cwd(frdl.DIRS.AppPath); require('fs').writeFile(gui.configfile(), JSON.stringify($scope.manifest), function(err, data){ if(err){ console.error(err); return; } }/* file, data[, options], callback */); }; $scope.runUpdate = function(refresh, skipCheck){ function updateAppDataSync(updateDir, appDir){ if(null !== sessionStorage.getItem('-webkit-webfan/~update.last.running') && new Date().getTime() - (1 * 15000) < parseInt(sessionStorage.getItem('-webkit-webfan/~update.last.running')) ){ frdl.alert.log('Updated already, please wait a moment...'); return; } sessionStorage.setItem('-webkit-webfan/~update.last.running', new Date().getTime()); var JWT_1 = sessionStorage.getItem('1.3.6.1.4.1.37553.8.1.8.3.1/JWT/handshake'); if(null===JWT_1){ frdl.alert.error('Cannot get JWT for install!'); return; } console.log('Get upgrade script...'); frdl.UI.progress().start(); var o = { updateDir : updateDir, appDir : appDir, argv : (!!frdl.nw) ? frdl.NativeApp.App.argv : ['update', '--flavour=webfapp'], hash : frdl.Sha1.hash( + '0x00' + navigator.appVersion + '0x00' + navigator.userAgent + '0x00' + updateDir + '0x00' + appDir + '0x00' + JSON.stringify(('undefined'!==typeof nw) ? frdl.NativeApp.App.argv : ['update', '--flavour=webfapp']) + '/' + new Date().getFullYear() + '/' + new Date().getMonth() + '/' + new Date().getDay() + '43667' ) }; o.importScript = webfan['$root-app']() + '/autoupdate.js?import=upgrade' + '&hash=' + o.hash; o.cacheID = '5:' + o.importScript; console.log('Update data and config ...'); try{ $.ajax( { url: o.importScript, crossDomain: true, cache:false, headers: {'X-Requested-With': 'XMLHttpRequest', 'X-Frdl-Nw': (!!frdl.nw) ? 'true' : 'false' }, type: 'POST', dataType: 'TEXT', data: { JWT_1 : JWT_1, install_manifest : frdl.base64_encode(JSON.stringify(window.webfanWebkitSettings().manifest)), test : 'test-update' } } ) .done(function(response) { //alert(response); frdl.UI.progress().start() ; var module = new TModule(o.importScript); module.descriptor = module.resolve(o.importScript); module.parent = module || require('frdl'); module.sourceURL = o.importScript; module.source = response; try{ var update = eval(frdl.require.getCompiler('application/javascript')(module.source, module)); var r = (true === update(o) ) ? true : false; window.Tabs().addTab('Settings', PATHPFX + 'settings', '', 'html', true, {name:'settings', params:{}}, true, true, 'icon-attach-schraube'); window.Tabs().removeTab('Install Setup'); // frdl.alert.success('Upgrade finished.'); }catch(err) { console.error(err); frdl.alert.error(err); var r = false; } frdl.UI.progress().complete() ; }) .fail(function(jqXHR, textStatus) { frdl.alert.error('Error: ' + url + 'config.xml ' + jqXHR.status); }) .always(function() { frdl.UI.progress().complete() ; frdl.UI.progress().complete() ; }); }catch(err){ console.error(err); } } /* if( true!==$scope.manifest.installed)return;*/ /* if(!!$scope.lastupdatecheck && new Date().getTime() - 60 * 60 * 1000 < $scope.lastupdatecheck){ webfan.$Async(function(){ $scope.runUpdate(false); },(2 * 60 * 60 * 1000)); return; } */ $scope.lastupdatecheck = new Date().getTime(); if('undefined'===typeof refresh)refresh=false; var url = webfan['$root-app']() + '/autoupdate.js'+((true===refresh)?('?refresh='+new Date().getTime()):'')/*+frdl.Device().OS*/; if (true===$scope.manifest.autoupdate || true === refresh){ /* frdl.getScript(url, function(){ webfan['$-webkit-webfan update'](); }); */ if(true===navigator.onLine){ updateAppDataSync(frdl.DIRS.AppPath,frdl.DIRS.AppPath); }else{ frdl.alert.error('Cannot run update because you are offline,<br />please open an internet connection and retry!'); } } webfan.$Async(function(){ $scope.runUpdate(false); },(6 * 60 * 60 * 1000)) }; webfan.$Async(function(){ $scope.checkStatus(); },3000); //localStorage.setItem('webapp://manifest', window.webfanWebkitSettings().manifest); if('undefined' === typeof $scope.manifest){ $scope.manifest ={ name : '-UNINSTALLED-', version : '0.0.0', installed : false }; // $scope.saveManifest(); } window.webfanWebkitSettings = function(){ return $scope; } ; window.webfanWebkitSettings().loadConfig(); }]) /** <div ng-controller="TabCtrl"> <p> <ul class="tabset"> <li ng-repeat="tab in tabs" class="tabsetTab" frdl-id="{{tab.id}}" > <span ng-bind="tab.title" ng-click="onClickTab(tab)"></span> <span ng-click="removeTab(tab)">X</span> </li> </ul> </p> <p style="height:100%;display:block;"> <div style="height:100%;"> <div ng-repeat="tab in tabs"> <div frdl-id="{{tab.id}}" style="display:none;height:100%;width:100%;" data-flow-mod="tab"> <div ng-bind-html="tab.html"></div> </div> </div> </div> </p> </div> */ .controller('TabCtrl', function($scope, $sce, $state) { $scope.tabs = []; var w = window || window; $scope.currentTab=null; $scope.openTab = function (tab, reload) { var Reload = reload; if(!isNaN(tab)){ tab = $scope.tabs[tab]; }else if('string' ===typeof tab){ tab = $scope.getTab(tab); if(null === tab || 'undefined' === typeof tab)return false; } $scope.currentTab = tab; webfan.$Async(function(){ frdl.wd(false).hide(); },10); /* var isOpen = false; if($('li[frdl-id="'+$scope.currentTab.id+'"]').hasClass('tabsetActive')){ isOpen = true; } */ $('*[data-flow-mod="tab"]') .hide() .css('height', '0px') .css('width', '0px') ; /* $('*[ui-view]').hide(); */ try{ if('undefined'!==typeof tab.state /* && $state.current.name !== tab.state.name */){ $state.go(tab.state.name, tab.state.params, tab.state.options || {}); $('li[frdl-id="'+$scope.currentTab.id+'"]') .addClass('tabsetActive') ; if('component' === tab.state.name){ $('li[frdl-id="'+$scope.currentTab.id+'"]') .attr('data-flow-tab-state', tab.state.name || '') ; } webfan.$Async(function(){ $('*[ui-view]').hide(); var v; for(v in $state.current.views){ /* tab.html += $('*[ui-view="'+v+'"]').html(); */ $('*[ui-view="'+v+'"]') .attr('frdl-webkit-src',$scope.currentTab.url ) .attr('frdl-id',$scope.currentTab.id ) .css('height', '100%') .css('width', '100%') .show(); } $("html, body").animate({ scrollTop: 0 }, "slow"); },10); }else if('undefined'===typeof tab.state){ $state.go('browser', {url:$scope.currentTab.url}, { reload: true }); } }catch(err){ console.warn('NoStateWarning(ToDo):'+err); } webfan.$Async(function(){ $('div[frdl-id="'+$scope.currentTab.id+'"], *[frdl-webkit-src="'+$scope.currentTab.url+'"]') .fadeIn('slow') .css('height', '100%') .css('width', '100%') .css('display', 'block') .css('top', '0px') .css('bottom', '0px') .css('margin', '0 auto') .find((true===Reload) ? '*[data-frdl-mod-browser]' : '*[data-frdl-mod-browser]:not([src])') .attr('src',$scope.currentTab.url ) ; $('li.tabsetActive') .removeClass('tabsetActive') ; $('li[frdl-id="'+$scope.currentTab.id+'"]') .addClass('tabsetActive') ; },30); webfan.$Async(function(){ $(document).trigger('readystatechange'); frdl.UI.Compile(100); },100); // frdl.$q('div[flow-section-id="FileExplorer"]', false).style.display='none'; }; $scope.removeTab = function (tab, save) { var _tab = frdl.clone(tab); $scope.tabs.splice($scope.tabs.indexOf(tab), 1); webfan.$Async(function(){ $('*[frdl-id="'+tab.id+'"]') .hide() .remove() ; },100); if(0===$scope.tabs.length){ $scope.addTab('about:blank', 'about:blank', null, 'browser'); } $scope.openTab(0); try{ if('undefined' === typeof save || true === save){ // frdl.sql.query('begin'); var sqlquery = "DELETE FROM webkit.tabs_active WHERE id='"+_tab.id+"' LIMIT 1"; //LIMIT 1 frdl.sql.query(sqlquery, function(err, result){ if(err){ console.error(err+ ' ' +sqlquery); return; } console.dir(result); frdl.sql.query('commit'); }); } }catch(err){ console.warn(err); } }; $scope.isActiveTab = function(tab) { return tab.id === $scope.currentTab.id; }; $scope.getTab = function(str) { var r = undefined; frdl.each($scope.tabs, function(i, tab){ if(('undefined' !== typeof tab.id && str === tab.id) || ('undefined' !== typeof tab.url && str === tab.url) || ('undefined' !== typeof tab.title && str === tab.title) ){ r=tab; return false; } }); return r; }; /* $scope.browserOnUnLoad=function(ev){ }; var browserOnUnLoad = $scope.browserOnUnLoad; $scope.browserOnLoad=function(ev){ var el = ev.target; el.onbeforeunload=browserOnUnLoad; var tab = $scope.getTab(el.getAttribute('frdl-id')) ; tab.title = ((el.contentWindow || el.contentDocument).document).title || tab.title; }; */ /** todo https://github.com/nwjs/nw.js/wiki/Window#windowevalframe-script Window.eval(frame, script) **/ $scope.addTab = function(title, url, html, type, cancable, state, open, save, cssClass, reload){ var hint_cmd ='Enter something to the command line at the bottom' hint_cmd += '\n-URL beginning with http:// https:// or filesystem:'; hint_cmd += '\n-webfan cli command starting with \'webfan\' (CLI syntax)'; hint_cmd += '\n-Execute javascript by starting the line with the token \'!\' (JS syntax)'; hint_cmd += '\n-search command starting the line with the token \'search\' or others (experimental)'; hint_cmd += '\n-ql command starting with \'ql\' (SQL syntax)'; var hint_cmd_alert = frdl.str_replace('\n', '<br />', hint_cmd); var ExistingTab = $scope.getTab(url); if('undefined'!==typeof ExistingTab){ if(true === open)return $scope.openTab(ExistingTab, reload); return ExistingTab; } var h = '', HTML = '', ID = 'flow-tab-' + Guid.newGuid(), isBrowser = false; if('undefined'===typeof cancable)cancable=true; if(true !== navigator['-webkit-webfan'] && ('browser'===type || 'app'===type)){ type = 'frame'; } if('browser'===type){ // h += '<webview resizable onload="browserOnLoad(this);" data-frdl-mod-browser="'+ID+'" src="'+url+'" frdl-id="'+ID+'" style="border:none; width:100%; height:100%; display:block;top:0;bottom:0;margin: 0 auto;"></webview>'; h += '<iframe resizable onload="browserOnLoad(this);" data-frdl-mod-browser="'+ID+'" src="'+url+'" frdl-id="'+ID+'" style="border:none; width:100%;height:100%; display:block;top:0;bottom:0;margin: 0 auto;" nwdisable nwfaketop></iframe>'; isBrowser=true; }else if('frame'===type){ h += '<iframe resizable onload="browserOnLoad(this);" data-frdl-mod-browser="'+ID+'" src="'+url+'" frdl-id="'+ID+'" style="border:none; width:100%;height:100%; display:block;top:0;bottom:0;margin: 0 auto;" nwdisable nwfaketop></iframe>'; isBrowser=true; }else if('frame.trusted'===type){ h += '<iframe resizable onload="browserOnLoad(this);" data-frdl-mod-browser="'+ID+'" src="'+url+'" frdl-id="'+ID+'" style="border:none; width:100%;height:100%; display:block;top:0;bottom:0;margin: 0 auto;" frdl-nwtrusted></iframe>'; isBrowser=true; }else if('app'===type){ h += '<appview resizable onload="browserOnLoad(this);" data-frdl-mod-browser="'+ID+'" src="'+url+'" frdl-id="'+ID+'" style="border:none; width:100%;height:100%; display:block;top:0;bottom:0;margin: 0 auto;"></appview>'; isBrowser=true; } /* <p ng-bind="tab.url"></p>*/ if(true===isBrowser){ state = {name:'browser', params:{url:url}}; var bhtml = '<frdl data-browserset></frdl>'; bhtml+= '<p class="url-bar-outer-p" flow-to-front>'; bhtml+='<input type="text" flow-mod="command-line" title="'+hint_cmd+'" onkeydown="var ev=event || window.event;if(parseInt(ev.keyCode)!==13)return;browse_webkit(this, ev);" placeholder="'+url+'" frdl-id="'+ID+'" />'; bhtml+='<button class="icon-button-browse" onclick="var ev=event || window.event;browse_webkit(frdl.$q(\'input[frdl-id=\\\''+ID+'\\\']\', false), ev);" ></button>'; bhtml+='<button class="icon-button-browse-back" onclick="window.history.back();" ></button>'; bhtml+='<button class="icon-button-browse-forward" onclick="window.history.forward();" ></button>'; /* bhtml+='<img onclick="browse(frdl.$q(\'input[frdl-id=\\\''+ID+'\\\']\', false));" src="icons/browse.gif" style="border:none;cursor:pointer;"/>'; bhtml+='<img onclick="window.history.back();" src="icons/browse_back.gif" style="border:none;cursor:pointer;"/>'; bhtml+='<img onclick="window.history.forward();" src="icons/browse_forward.gif" style="border:none;cursor:pointer;"/>'; */ bhtml+='</p>'; }else{ var bhtml = '<frdl data-browserset></frdl>'; bhtml+= '<p class="url-bar-outer-p" flow-to-front><input flow-mod="command-line" title="'+hint_cmd+'" class="url-bar icon-attach-icon-link" type="text" onkeydown="var ev=event || window.event;if(parseInt(ev.keyCode)!==13)return;browse_webkit(this, ev);" placeholder="'+url+'" frdl-id="'+ID+'" /></p>'; } if('string'===typeof html)HTML+=html; if(false === frdl.strpos(html, '<frdl data-browserset></frdl>')){ HTML += h + bhtml; } $scope.$evalAsync( function() { $scope.tabs.push({ id : ID, title : title, url : url, type : type, html : $sce.trustAsHtml(HTML), cancable : cancable , state : state || undefined, cssClass : cssClass || undefined }); var tab = $scope.getTab(ID); tab.open = function(Reload){ $scope.openTab(tab, Reload); $('li[frdl-id="'+tab.id+'"]').trigger('click'); frdl.ready(function(){ frdl.translate(); }); webfan.$Async(function(){ $("html, body").animate({ scrollTop: 0 }, "slow"); },1); return tab; }; if(open===true)tab.open(reload); webfan.$Async(function(){ if('string' === typeof tab.cssClass){ $('li[frdl-id="'+tab.id+'"]') .addClass(tab.cssClass) .css('width', 'auto') .css('min-width', '64px') .css('max-width', '355px') ; } if('undefined'!==typeof state && 'component' === state.name){ $('li[frdl-id="'+tab.id+'"]') .attr('data-flow-tab-state', state.name) ; } },500); try{ if('undefined' === typeof save || true === save){ // frdl.sql.query('begin'); if(PATHPFX+'start' === frdl.base64_decode(url))return ; if(PATHPFX+'data' === frdl.base64_decode(url))return ; if(webfan['$browser-scheme']() + 'install' === frdl.base64_decode(url))return ; if('/apc/' === frdl.base64_decode(url))return ; var sqlquery = "INSERT INTO webkit.tabs_active SET id='"+ID+"', title='"+frdl.base64_encode(title)+"', url='"+frdl.base64_encode(url)+"', type='"+type+"', html='"+frdl.base64_encode(HTML)+"', cancable='"+cancable+"', cssClass='"+cssClass+"' "; frdl.sql.query(sqlquery, function(err, result){ if(err){ console.error(err+ ' ' +sqlquery); return; } frdl.sql.query('commit'); }); } }catch(err){ console.warn(err); } }); }; /* end addTab */ /* init tabs */ webfan.$Async(function(){ $scope.$watchCollection('tabs', function(newValue, oldValue) { if(newValue.length !== oldValue.length) { if('undefined'!==typeof frdl.wd().Menu && 'function'===typeof frdl.wd().Menu.getOpenTags){ frdl.wd().Menu.getOpenTags(true); } } }); $scope.$watch('currentTab', function(newValue, oldValue) { if(newValue !== oldValue) { var fs = require('fs'); frdl.fs5.polyfill.getFiler().cd(frdl.fs5.polyfill.getFiler().fs.root); fs.writeFile('1.3.6.1.4.1.37553.8.1.8.8.10.1.1/~tab.CACHE', JSON.stringify(newValue), function(err, data){ if(err){ console.error(err); return; } }, console.warn); } }); },1000); $scope.startTabs = function(Reload){ $('*[data-flow-mod="tab"]') .hide() .css('height', '0px') .css('width', '0px') ; if(null === $scope.currentTab){ return; } $('*[ui-view]').hide(); var v; for(v in $state.current.views){ $('*[ui-view="'+v+'"]') .attr('frdl-webkit-src',$scope.currentTab.url ) .attr('frdl-id',$scope.currentTab.id ) .css('height', '100%') .css('width', '100%') .show(); } $("html, body").animate({ scrollTop: 0 }, "slow"); $('div[frdl-id="'+$scope.currentTab.id+'"], *[frdl-webkit-src="'+$scope.currentTab.url+'"]') .fadeIn('slow') .css('height', '100%') .css('width', '100%') .css('display', 'block') .css('top', '0px') .css('bottom', '0px') .css('margin', '0 auto') .find((true===Reload) ? '*[data-frdl-mod-browser]' : '*[data-frdl-mod-browser]:not([src])') .attr('src',$scope.currentTab.url ) ; $('li.tabsetActive') .removeClass('tabsetActive') ; $('li[frdl-id="'+$scope.currentTab.id+'"]') .addClass('tabsetActive') ; }; $scope.startTabs(); window.Tabs = function(){ return $scope; }; }) .controller('browserCtrl', function($scope, $stateParams, $state){ window.addEventListener("beforeunload", function() { frdl.sql.query('COMMIT'); }, true); $scope.onMessage = function(message){ if('string'===typeof message) return frdl.alert.log('Message from service: '+message); if('function'===typeof message )return message(); }; $scope.whenOnline=function(){ webfan.$Async(function(){ // if(true===navigator.doNotTrack && !navigator['-webkit-webfan']) return; if(true===navigator.onLine){ //todo } },1); window.addEventListener("offline", $scope.whenOffline, true); }; $scope.whenOffline=function(){ if('undefined'!==typeof require.cache()['$'+serviceInjectorUrl] || 'undefined'!==typeof require.cache()[serviceInjectorUrl]){ try{ //todo }catch(err){ console.warn(err); } } window.addEventListener("online", $scope.whenOnline, true); }; webfan.$Async(function(){ if(true===navigator.onLine){ $scope.whenOnline(); }else{ $scope.whenOffline(); } },bootDelay); $scope.$on('$stateChangeSuccess', function(event, toState, toParams, fromState, fromParams){ console.log(toState.name); var isNewParams=(toParams!==fromParams) ? true : false; var isNewState=(toState.name!==fromState.name)?true:false; var isChanged=(!!isNewParams || !!isNewState)?true:false; if(!!isChanged){ //webfan.$Async(function(){ // window.webfanWebkitSettings().loadConfig(); //},1500); //webfan.$Async(function(){ // window.webfanWebkitSettings().localizeAsync(); //},1500); $("html, body").animate({ scrollTop: 0 }, "slow"); if('component' !== toState.name && 'component' === fromState.name ){ $('div[data-webkit-mod="PANEL.WIDGET"]').fadeOut('slow'); } } // if(!!isChanged) var el = frdl.$q('frdl-section[frdl-webkit-id="side-menu-left"] > a[flow-toggler]', false); if('start' === toState.name ){ if(el.parentNode.style.width==='160px'){ }else{ el.parentNode.style.width='160px'; $('ul[flow-section-id=\'sidebar\']').fadeIn('slow'); } }else{ if(el.parentNode.style.width==='3px'){ }else{ el.parentNode.style.width='3px'; $('ul[flow-section-id=\'sidebar\']').fadeOut('slow'); } } frdl.ready(window.webfanWebkitSettings().checkStatus); webfan.$Async(function(){ window.webfanWebkitSettings().localizeAsync(); },1500); webfan.$Async(function(){ $("html, body").animate({ scrollTop: 0 }, "slow"); },500); }); //$scope.$on('$stateChangeSuccess', webfan.$Async(function(){ frdl.ready(window.webfanWebkitSettings().checkStatus); },2000); }) .controller('installCtrl', ['$scope', '$http', '$sce', function($scope, $http, $sce){ if(true===window.webfanWebkitSettings().manifest.installed){ window.Tabs().removeTab('./templates/install.app',false); } $scope.autoupdate=true; // var msgpack =require("msgpack/lib/msgpack"); $scope.config = window.webfanWebkitSettings().manifestServer; // $scope.config = window.webfanWebkitSettings().manifest; // $scope.config = gui.getGUIManifest(); $scope.userAgent =navigator.userAgent; $scope.isWebKitStr = (true ===navigator['-webkit-webfan']) ? 'YES' : 'NO'; $scope.ApplicationRoot = frdl.DIRS.AppPath; $scope.WebAppRoot = webfan['app://'](); $scope.lang = { }; $scope.lang.installWebAppFor = __('My.Webfan WebApp for %s.', [$scope.userAgent]); $scope.install=function(){ if(true !== $scope.accept || true === $scope.config.installed)return false; // console.dir($scope.autoupdate) ; // console.dir(window.webfanWebkitSettings().manifest); // console.dir(window.webfanWebkitSettings().manifestServer); webfan.$Async(function(){ frdl.UI.progress().start() ; webfan.$Async(function(){ // $scope.config.installed = true; $scope.config.autoupdate = (true===$scope.autoupdate) ? true : false; $scope.config.id = window.webfanWebkitSettings().manifestServer.id; var _Fn = function(){ _Fn = function(){}; window.webfanWebkitSettings().manifest = $scope.config; window.webfanWebkitSettings().runUpdate(true, true); }; var fs = frdl.require('fs'); process.cwd(frdl.DIRS.AppPath); fs.writeFile(gui.configfile(), JSON.stringify($scope.config), function(err, data){ if(err){ console.error(err); return; } _Fn(); }); },10); },30); }; }]) .run(function(){ }) }); })(); (function () { 'use strict'; function browse_webkit(browserInput, event){ function cmd_webfan(cmd){ frdl.c(cmd, function(messageLog, argparse){ if(messageLog){ frdl.each(messageLog, function(i,m){ frdl.alert.log('<pre>'+m+'</pre>'); }); }else{ frdl.alert.log('<pre></pre>'); } }, true, self || window); } var b = browserInput; var tabID = b.getAttribute('frdl-id'); var bf = frdl.$q('*[data-frdl-mod-browser="'+tabID+'"]', false); /* browser frame */ /*console.dir(bf); var tab = window.Tabs().getTab(tabID);*/ var newUrl = b.value; if(''===newUrl.trim())return false; b.setAttribute('placeholder', b.value); b.value = ''; var words = newUrl.split(/\s/); var cmd = words[0].toLowerCase(); var sqlStarts = ['alter', 'select', 'update', 'delete', 'create', 'insert', 'show', 'replace', 'drop', 'explain']; try{ var oldUrl = bf.getAttribute('src'); }catch(err){ var oldUrl = ''; } var scheme = new frdl.Url(newUrl).getScheme(); var ev = event || window.event; if('undefined'!==typeof ev && 16 === parseInt(ev.keyCode) && ('http'===scheme || 'https'===scheme || 'filesystem:'===newUrl.substr(0,'filesystem:'.length))){ window.Tabs().addTab(new frdl.Url(newUrl).getHost(), newUrl, null, 'browser', true, undefined, true); //b.value = oldUrl; return; }else if('http'===scheme || 'https'===scheme || 'filesystem'===scheme){ /*bf.setAttribute('nwdisable', true); bf.setAttribute('nwfaketop', true); if(bf.hasAttribute('frdl-nwtrusted'))bf.removeAttribute('frdl-nwtrusted'); bf.setAttribute('src', newUrl); */ window.Tabs().addTab(new frdl.Url(newUrl).getHost(), newUrl, null, 'browser', true, {name:'browser', params:{url:newUrl}}, true); // b.value = oldUrl; return; }else if('webfan'===scheme || 'web+fan'===scheme){ //location.hash='#'+newUrl; console.log('ToDo webfan://'+ newUrl); }else if('webfan'=== cmd){ cmd_webfan(newUrl); }else if( 'search'===cmd || 'suche'===cmd || 'recherché'===cmd || '#'===cmd ){ var searchterm = newUrl.substr(cmd.length, newUrl.length).trim(); var url = 'http://suche.webfan.de/?q=' + frdl.urlencode(searchterm); window.Tabs().addTab('Search '+ frdl.htmlentities(searchterm), url, null, 'browser', true, {name:'browser', params:{url:url}}, true); } else if('!'===newUrl.substr(0,1) || 'js' === cmd){ try{ eval(newUrl.substr(1,newUrl.length)); }catch(err){ console.error(err); frdl.alert.error(err); } }else if('ql' === cmd || 'sql' === cmd || -1 !== sqlStarts.indexOf(cmd)){ if(-1 === sqlStarts.indexOf(cmd)){ newUrl = newUrl.substr(cmd.length, newUrl.length).trim(); } cmd_webfan(newUrl); } else /*if('#js'===newUrl.substr(0,3))*/{ cmd_webfan('webfan ' + newUrl.trim()); }/* else{ return false; }*/ } window.browse_webkit=browse_webkit; }());