if (! toggle_visibility) { var toggle_visibility = function(id) { var e = document.getElementById(id); if(e.style.display == 'block') e.style.display = 'none'; else e.style.display = 'block'; } } if (!blogBrowser) { var blogBrowser = Class.create(); blogBrowser.addMethods({ initialize: function() { var options = { url: '/l/blogs/?displaymode=json', target: $('_fileBrowser'), spinner: '/css/images/spinner.gif', channelId: '', withFilter: false }; Object.extend(options, arguments[0]); this.target = options.target; this.spinner = options.spinner; this.url = options.url; this.withFilter = options.withFilter; this.withSection = options.withSection; this.buildFrame.bind(this)(); this.setLoading(); this.lastLoadFromFilter = false; this.aborted = 0; this.channelId = this.getChannelId(); if (!this.channelId) { this.channelId = options.channelId; } this.loadBlogs(); }, loadBlogs: function() { this.lastLoadFromFilter = false; this.setLoading(); var path = arguments[0] || '/'; this.currentpath = path; var qUrl = this.url; myreader = new Ajax.Request(qUrl, { onSuccess: function(t,json) { this.cleanFrame(); if (!json) { if (t.responseJSON) json = t.responseJSON; } if (!json) { this.setText('Unexptected Error!'); return false; } count = 0; for (var i = 0; i < json.results.length && i < 5; i++) { if (count % 2) { style = "background-color: #ffffff"; } else { style = "background-color: #f8f8f8"; } var name = json.results[i].name; var date = json.results[i].date; var id = json.results[i].id; var title = json.results[i].title; var url = json.results[i].url; d = this.createEntry(name,date,id,title,url); this.appendNode(d); count++; } if (json.results.length < 1) { this.removeBrowser(); } }.bind(this), onComplete: function(t,json) { this.cleanFrame(); if (!json) { if (t.responseJSON) json = t.responseJSON; } if (!json) { this.setText('Unexptected Error!'); return false; } count = 0; for (var i = 0; i < json.results.length; i++) { if (count % 2) { style = "background-color: #ffffff"; } else { style = "background-color: #f8f8f8"; } var name = json.results[i].name; var date = json.results[i].date; var id = json.results[i].id; var title = json.results[i].title; var url = json.results[i].url; d = this.createEntry(name,date,id,title,url); this.appendNode(d); count++; } if (json.results.length < 1) { this.removeBrowser(); } }.bind(this), onFailure: function(){ this.cleanFrame(); this.setText('Failure...'); }.bind(this) }); }, createEntry: function(name,date,ud,title,url) { var d = document.createElement('DIV'); d.className = 'blogName'; var a = document.createElement("A"); a.setAttribute('href',url); a.appendChild(document.createTextNode(name)); var br = document.createElement("BR"); var e = document.createElement('DIV'); e.className = 'blogEntry'; e.appendChild(document.createTextNode(title)); var da = document.createElement('DIV'); da.className = 'blogDate'; da.appendChild(document.createTextNode('Post del ' + date)); d.appendChild(a); d.appendChild(br); d.appendChild(e); d.appendChild(da); return d; }, getChannelId: function() { return ajaxCMS.channelId; }, buildFrame: function() { if (this.withSection) { var s = document.createElement('h1'); s.innerHTML = ajaxCMS.channelName; this.target.appendChild(s); } var d = document.createElement('DIV'); d.className = 'fileBrowser'; this.target.appendChild(d); this.frame = d; if (this.withFilter) { var filter = document.createElement('DIV'); filter.className = 'fileFilter'; var input = document.createElement('input'); input.setAttribute('type','text'); input.className = 'fileFilterInput'; input.onkeyup = this.onFilterChange.bind(this); input.setAttribute('title','Inserisci le parole chiave separate da uno spazio'); //input.onchange = this.onFilterChange.bind(this); this.inputField = input; this.target.appendChild(document.createElement('DIV').appendChild(document.createTextNode('Cerca in questa sezione'))); filter.appendChild(input); this.target.appendChild(filter); } }, onFilterChange: function() { value = this.inputField.value; if (value.length < 4 || value == '') { if (value == '' && this.lastLoadFromFilter) { this.loadFiles(); } return true; //wait! } this.loadFilesFromFilter(value); //console.log("Value: '" + this.inputField.value + "'"); }, cleanFrame: function() { var el = false; while( el = this.frame.firstChild ) { this.frame.removeChild(el); } }, removeBrowser: function() { var parent = this.target.parentNode; parent.removeChild(this.target); }, appendNode: function(n) { this.frame.appendChild(n); }, setText: function(t) { this.frame.appendChild(document.createTextNode(t)); }, setLoading: function() { this.cleanFrame(); var d = document.createElement('DIV'); d.className = 'spinner'; var i = document.createElement('IMG'); i.src = this.spinner; this.frame.appendChild (i); this.frame.appendChild(document.createTextNode(' Ricerca dei blog...')); } }); function parseUri (str) { var o = parseUri.options, m = o.parser[o.strictMode ? "strict" : "loose"].exec(str), uri = {}, i = 14; while (i--) uri[o.key[i]] = m[i] || ""; uri[o.q.name] = {}; uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) { if ($1) uri[o.q.name][$1] = $2; }); return uri; }; parseUri.options = { strictMode: false, key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"], q: { name: "queryKey", parser: /(?:^|&)([^&=]*)=?([^&]*)/g }, parser: { strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/, loose: /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/ } }; }