/* * Plugin jQuery : Protos * Version : 1.0 // RWO * Author : Iyanayi One */ var Protos = function () { var pluginName = "Protos"; var DebugClass = false; var CurrentUrl = location.pathname.substr(location.pathname.length-1, 1) == '/' ? location.pathname.substr(0, location.pathname.length-1) : location.pathname; function initPlugin(){ Debug('Init'); declarePrototypes(); } // Live declarations (once by reload) function declarePrototypes(){ // ucFirst Prototype String.prototype.ucfirst = function() { return this.charAt(0).toUpperCase() + this.slice(1); } String.prototype.replaceAll = function(search, replacement) { var target = this; return target.replace(new RegExp(search, 'g'), replacement); }; } /********************************************************************************************************/ function Debug(arg, title){ if (!DebugClass) return ; title = title || ''; // Parametre optionnel return console.log(pluginName + " : " + title + (title != '' ? '->':'') + arg ); } /******************************** Externals CallBacks For the Plugins *********************************/ return { init: function () { initPlugin(); }, reload: function () { declarePrototypes(); }, name: function () { return pluginName; }, setDebug : function(state){ state = state || true; DebugClass = state; } //This is also an example to show us how to create new externals procedures }; }(); /* * Plugin jQuery : Utility * Version : 1.0 // RWO * Author : Iyanayi One */ var Utility = function () { var pluginName = "Utility"; var DebugClass = false; var CurrentUrl = location.pathname.substr(location.pathname.length-1, 1) == '/' ? location.pathname.substr(0, location.pathname.length-1) : location.pathname; function initPlugin(){ Debug('Init'); liveUtilities(); } // Live declarations (once by reload) function liveUtilities(){ /* Confirm action before return */ $('[confirm]').off('click').on('click', function(){ var confirmation = $(this).attr('confirm') || "Êtes vous sûr ?"; return confirm(confirmation); }); //Remove on click $('.remove-on-click').off('click').on('click',function(){ $(this).fadeOut(function(){ $(this).remove(); }); }); //Self-removing $('.auto-remove, .self-remove').each(function(){ var elmt = $(this); setTimeout(function(){ elmt.fadeOut(); setTimeout(function(){ elmt.remove(); }, 420); }, 4200); }); } // Load declarations (each content load) function loadUtilities(){ // Fancyboxes defines //$(".fancybox").fancybox({ // 'minWidth' : '60%' //}); // Bloc Movable [goto] $('[goto]').each(function(){ var cible = $(this).attr('goto'); $(this).detach().appendTo(cible).removeAttr('goto'); Debug('just moved a bloc...'); console.log(this); }); //Remove on click $('.remove-on-click').off('click').on('click',function(){ $(this).fadeOut(function(){ $(this).remove(); Debug('just removed a bloc...'); }); }); //Self-removing $('.auto-remove, .self-remove').each(function(){ var elmt = $(this); setTimeout(function(){ elmt.fadeOut(); setTimeout(function(){ elmt.remove(); Debug('auto removed a bloc...'); }, 420); }, 4200); }); //Search Forms in tabs /* $('form[loadin]').off('submit').on('submit',function(){ var cible = $(this).attr('loadin'); var ctrl = $(this).attr('action'); var sync = $(this).attr('sync') || 1; var post = $(this).serialize(); var ajax = ctrl + '/' + sync; $.ajax({url:ajax ,type: "POST", data:post, async:!sync, success:function(rpce){ $(cible).html(rpce); actionEvents(); }}) return false; }); //Live edit data of entity setTimeout(function(){ $('[ctrl]').off('change').on('change',function(){ var ent = $(this).attr('entity'); var act = $(this).attr('ctrl'); var id = $(this).attr('id'); var val = $(this).val(); var sync = $(this).attr('sync') || 1; var post = {"infos[groupe]":val} var ajax = '/ctl/' + ent + '/' + act + '/' + id + '/' + sync; $.ajax({url:ajax ,type: "POST", data:post, async:true}) }); }, 420); */ } /********************************************************************************************************/ function Debug(arg, title){ if (!DebugClass) return ; title = title || ''; // Parametre optionnel return console.log(pluginName + " : " + title + (title != '' ? '->':'') + arg ); } /******************************** Externals CallBacks For the Plugins *********************************/ return { init: function () { initPlugin(); }, reload: function () { loadUtilities(); }, name: function () { return pluginName; }, setDebug : function(state){ state = state || true; DebugClass = state; } //This is also an example to show us how to create new externals procedures }; }(); /* * Plugin jQuery : Sweety * Description : Auto display page with a sweeet opacity animation * Description(fr) : Ce plugin permet l'affichage progressif des pages * Version : 1.1 (with init & reload) * Author : Iyanayi One */ var Sweety = function () { var pluginName = "Sweety"; var DebugClass = false; var CurrentUrl = location.pathname; var SweetyEnabled = true; var DefaultContainerClass = "body"; /*********************************** Functions to run the Plugin **************************************/ /*********************************** Storage **************************************/ function canSweetView(SelectorClass){ SelectorClass = SelectorClass || DefaultContainerClass; // Parametre optionnel Debug($(SelectorClass).size() > 0, 'canSweetView') return ($(SelectorClass).size() > 0); } /***************************************** Sweety core ***************************************************/ function SweetMyViews(){ if (SweetyEnabled){ setTimeout(function(){ $('.ini').addClass('pop'); }, 420); }else $('.ini').removeClass('ini'); } function initSweetViews(SelectorClass){ SelectorClass = SelectorClass || DefaultContainerClass; // Parametre optionnel if (SweetyEnabled){ if (!$(SelectorClass).hasClass('ini')) $(SelectorClass).addClass('ini'); Debug($('.ini').size(), 'iniViews') } } /********************************************************************************************************/ function Debug(arg, title){ if (!DebugClass) return ; title = title || ''; // Parametre optionnel return console.log(pluginName + " : " + title + (title != '' ? '->':'') + arg ); } /******************************** Externals CallBacks For the Plugins *********************************/ return { init: function (forClass) { Debug('Init'); forClass = forClass || ""; // Parametre optionnel if (canSweetView(forClass)){ initSweetViews(forClass); SweetMyViews(); }else Debug ("Cannot sweet anything !") }, reload: function () { SweetMyViews(); }, name: function () { return pluginName; }, setDebug : function(state){ state = state || true; DebugClass = state; } }; }(); /* * Plugin jQuery : Auto Loader * Version : 1.2 // Healp * Author : Iyanayi One */ var Loader = function () { var pluginName = "Loader"; var DebugClass = false; var CurrentUrl = location.pathname.substr(location.pathname.length-1, 1) == '/' ? location.pathname.substr(0, location.pathname.length-1) : location.pathname; //Maj to prevent multiple ref pass CurrentUrl = CurrentUrl.indexOf('-%3') >= 0 ? CurrentUrl.substr(0, CurrentUrl.indexOf('-%3')) : CurrentUrl function initPlugin(){ Debug('Init'); setTimeout(function(){ loadBlocs(); }, 420); ///777 } function loadBlocs(){ var Blocs = $('[load]'); if (Blocs.size()) Debug('Loading '+Blocs.size()+' blocs'); var nbBlocs = Blocs.size(); var nBloc = 1; Blocs.each(function(){ var Bloc = $(this) ; var View = Bloc.attr('load'); var Args = location.search; var Ajax; if (View[0] == '/') Ajax = '/jx' + View; else Ajax = '/jx' + CurrentUrl + '/' + View; Bloc.hide().load(Ajax+Args, function(rpceHtml){ Bloc.removeAttr('load');// Prevent to reload the same bloc twice Bloc.attr('bloc', View);// Indicate the bloc loaded if (rpceHtml.trim().length > 0) // if html not empty (success) Bloc.attr('state', 'ready') else{ // else on marque le bloc en fail Debug('failed', '('+Ajax+')') Bloc.attr('state', 'failed'); } if (nBloc == nbBlocs){ // Affiche les blocs chargés dispBlocs(); // Reload dynamics events Frames.reload(); } nBloc++; }) }); } function dispBlocs(){ var Blocs = $('[state="ready"]'); if (Blocs.size()) Debug(Blocs.size() + ' blocs displayed') Blocs.each(function(){ $(this).fadeIn().removeAttr('state'); }); //cleanBlocs(); } function cleanBlocs(){ var Blocs = $('[state="failed"]'); if (Blocs.size()) Debug(Blocs.size() + ' blocs removed') Blocs.each(function(){ $(this).remove(); }); } /********************************************************************************************************/ function Debug(arg, title){ if (!DebugClass) return ; title = title || ''; // Parametre optionnel return console.log(pluginName+ " : " + title + (title != '' ? '->':'') + arg ); } /******************************** Externals CallBacks For the Plugins *********************************/ return { init: function () { initPlugin(); }, reload: function () { loadBlocs(); }, name: function () { return pluginName; }, setDebug : function(state){ state = state || true; DebugClass = state; } //This is also an example to show us how to create new externals procedures }; }(); /* * Plugin jQuery : Viewer system * Version : 1.2 // Healp * Author : Iyanayi One */ var Viewer = function () { var Plugin = {name:"Viewer", debug :true, enabled:true, watcher:false } var Config = { href: location.protocol + "//"+location.host+"/app", args: location.search, main_selector:"viewer[main]", view_selector:"[view]", body_selector:"corpus", link_selector:'a[jax], nav a' } function initViewer(){ loadViewer(); //loadViewer(); //watchActions(); //Anima.add(watchActions); //window.onbeforeunload = unloadViewer(); //window.onbeforeunload = unloadViewer; } function reloadViewer(){ watchActions(); /*Anima.add(function(){ $(Config.main_selector+'.ini').addClass('pop'); }, 'adding opacity to viewer');*/ } function watchActions(){ if (!Config.watcher) return; // Click on a link $(Config.link_selector).off('click').on('click', function(e){ var href = $(this).attr('jax') || $(this).attr('href'); //$(Config.link_selector).parent('li').removeClass('active') //$(this).parent('li').addClass('active') $(Config.link_selector).removeClass('active') $(this).addClass('active') loadView(href, true); if (!$(this).hasClass('dropdown-toggle')) return false; return false; }) $(window).off('popstate').on('popstate', function (e) { var page = e.originalEvent.state; if (page){ var href = page.href; console.log(href) loadView(href) }else loadView('index') return true; }); if (location.hash.replace('#', '')){ var id_bloc = location.hash; var view = location.hash.replace('#', ''); if ($(id_bloc).size()>0){ if ($('a[href="'+id_bloc+'"]').size()) $('a[href="'+id_bloc+'"]').click(); } } } function loadView(href, pushState){ Debug('Loading view '+href); pushState = pushState || false href = href || 'index' //if (location.pathname == '/'+href) // return false; var Viewer = $(Config.main_selector); var Args = location.search; var base = '/views/'; if (!href) return Debug('no view setted !'); var Ajax = Config.href + base + href + Args; Debug('loading view : '+Ajax); Viewer.addClass('ini').removeClass('pop'); var x = document.createElement("tmp"); $(x).hide(); $(x).load(Ajax, function(rpceHtml){ Viewer.removeAttr('load-view'); if (rpceHtml.trim().length > 0){ // if html not empty (success) var tcbl = $(this).find('anima[title]'); var title = tcbl.size() > 0 ? tcbl.html() : ""; var datas = {href:href}; Viewer.attr('view', href).attr('id', 'view-'+href);// Indicate the bloc loaded Viewer.attr('state', 'ready') if (pushState) history.pushState(datas, title, href); window.scrollTo(0, 35); Viewer.html(rpceHtml); Plugins.reload(); dispViewer(); }else{ // else on marque le bloc en fail Debug('failed', '('+Ajax+')') Viewer.attr('state', 'failed'); Notify.add('Loading failed...', 'danger', 'La page '+Ajax+' est indisponible...') } $(x).remove(); }) } function loadViewer(){ var Viewer = $(Config.main_selector); if (!Viewer.size()) return Debug('Viewer[main] not found !'); else Debug(Viewer.size()+' Viewers found !'); var nbViewer = Viewer.size(); var nView = 1; Viewer.each(function(){ var View = $(this) ; var Name = View.attr('load-view'); var Args = location.search; var base = '/views/'; if (!Name) return; else return loadView(Name); }); } function unloadViewer(e){ //console.log(e) //return $(Config.body_selector).addClass('bye') } function dispViewer(){ var Views = $('[view][state="ready"]'); if (Views.size()) Debug(Views.size() + ' views displayed') Views.each(function(){ $(this).addClass('pop').removeAttr('state'); }); //cleanViewer(); } function hideViewer(){ var Views = $('[view].ini.pop'); if (Views.size()) Debug(Views.size() + ' views hidden') Views.each(function(){ $(this).addClass('bye'); }); //cleanViewer(); } function cleanViewer(){ var Views = $('[view][state="failed"]'); if (Views.size()) Debug(Views.size() + ' views removed') Views.each(function(){ $(this).remove(); }); } /********************************************************************************************************/ function Debug(arg, title){ if (!Plugin.debug) return ; title = title || ''; // Parametre optionnel return console.log(Plugin.name+ " : " + title + (title != '' ? '->':'') + arg ); } /******************************** Externals CallBacks For the Plugins *********************************/ return { init: function () { initViewer(); }, load: function (view) { loadView(view, true); }, reload: function () { reloadViewer(); }, unload: function () { unloadViewer(); }, name: function () { return Plugin.name; }, setDebug : function(state){ state = state || true; Plugin.debug = state; } }; }(); /* * Plugin jQuery : Socket.io Manager * Version : 1.0 // Healp // RWO * Author : Iyanayi One */ var Node = function () { var pluginName = "Node"; var DebugClass = false; var NodeURL = "http://apx.rainbowarriors.one"; var User = {}; User.id = "Visitor-XXX"; User.name = "AnonymousRW"; User.href = location.href; User.addr = "xxx.xxx.xxx.xxx"; User.time = "dd/mm/yyyy H:i:s"; var socket; function initPlugin(){ Debug('Init'); // Connexion avec le serveur NodeJS of Healp socket = io.connect(NodeURL); if (socket) Debug ('Live Connexion Ignited !'); if (User) connect(User); wait4Events(); } function reloadPlugin(){ Debug('Reload'); User.page = location.href; refresh(User); } /*************** Node sync funcs ************************************************************************/ function wait4Events(){ socket.on('notify', function(msg) { msg.title = msg.title || "Hello !
"; msg.body = msg.body || "You just received a message !"; msg.title = msg.title || "success"; Notify.add(''+msg.title+' '+msg.body, msg.type); }) } function connect(User){ Debug ('Connecting user "'+User.name+'"...'); // Send the push notification to the node side app server socket.emit('user_connect', User); } function refresh(User){ // Send the push notification to the node side app server //socket.emit('user_refresh', User); } /********************************************************************************************************/ function Debug(arg, title){ if (!DebugClass) return ; title = title || ''; // Parametre optionnel return console.log(pluginName + " : " + title + (title != '' ? '->':'') + arg ); } /******************************** Externals CallBacks For the Plugins *********************************/ return { init: function () { //initPlugin(); }, reload: function () { //reloadPlugin(); }, name: function () { return pluginName; }, setDebug : function(state){ state = state || true; DebugClass = state; } //This is also an example to show us how to create new externals procedures }; }(); /* * Plugin jQuery : Notification Manager * Version : 1.0 // Healp // RWO * Author : Iyanayi One */ var Notify = function () { var pluginName = "Notify"; var DebugClass = false; function initPlugin(){ Debug('Init'); checkNotifyZone(); } function checkNotifyZone(){ if ($('.notify.zone').size() == 0) addNotifyZone(); } function addNotifyZone(){ Debug('Adding zone'); var zone = document.createElement('div'); $(zone).addClass('notify zone'); $('body').append(zone); } function add(message, status, persitent){ Debug('Adding new notification...'); var alert = document.createElement('div'); $(alert).addClass('alert alert-success remove-on-click') status = status || 'info'; $(alert).addClass('alert-'+status); persitent = persitent || false; if (persitent) $(alert).addClass('auto-remove'); $(alert).html(message) $('.notify.zone').append(alert); Utility.reload(); } /********************************************************************************************************/ function Debug(arg, title){ if (!DebugClass) return ; title = title || ''; // Parametre optionnel return console.log(pluginName + " : " + title + (title != '' ? '->':'') + arg ); } /******************************** Externals CallBacks For the Plugins *********************************/ return { init: function () { initPlugin(); }, reload: function () { }, add: function (message, status, persitent) { return add(message, status, persitent); }, name: function () { return pluginName; }, setDebug : function(state){ state = state || true; DebugClass = state; } //This is also an example to show us how to create new externals procedures }; }(); /* * Luncher : Frames.js ~ Inherited from Healp * Utility : Gestionnaire de plugins Javascripts * Version : 1.0 // for Rainbowarriors.one * Author : Iyanayi // Rainbow Warriors */ var Plugins = function () { // Global core variables var pluginName = "Plugins"; var DebugClass = false; function loadPlugins(){ var Plugins = [Protos, Utility, Sweety, Loader, Viewer, Node, Notify]; Debug('Loading '+Plugins.length+' plugins...'); $.each(Plugins, function(i, daPlugin){ if (daPlugin){ daPlugin.init(); Debug('Ignited !', daPlugin.name()); } else{ Debug('init failed !', daPlugin.name()) console.log(daPlugin) } }); } function reloadPlugins(){ var Plugins = [Utility, Loader, Viewer]; Debug('Reloading '+Plugins.length+' plugins...'); $.each(Plugins, function(i, daPlugin){ if (daPlugin) daPlugin.reload(); else{ Debug('reload failed !', Event.name()) console.log(Event) } }); } /********************************************************************************************************/ function Debug(arg, title){ if (!DebugClass) return ; title = title || ''; // Parametre optionnel return console.log(pluginName + " : " + title + (title != '' ? '->':'') + arg ); } /******************************** Externals CallBacks For the Plugins *********************************/ return { load: function () { loadPlugins(); }, reload: function () { reloadPlugins() }, name: function () { return pluginName; }, setDebug : function(state){ state = state || true; DebugClass = state; } }; }(); /* * Plugin : One Luncher * Author : Iyanayi One */ $(document).ready(Plugins.load);