* then whenever html is loaded via AJAX, we can run run through the handlers and add them.
*
*/
-
-
+
MTrack = {
-
+ init : function()
+ {
+
+ Roo.onReady(function () {
+ //MTrack.footerSetAndWait();
+ if (authUser) {
+ window.setTimeout(MTrack.keepLoggedIn, 30000);
+
+ }
+
+
+
+ });
+
+ Roo.onReady( function () {
+ var path = [ 'Tree' ];
+ //if (repoName) path.push( repoName );
+ // ??/ jump?
+
+ var href = (window.location.pathname + window.location.search).substring(baseURL.length);
+ try {
+ window.history.pushState( { url: href }, document.title , window.location.pathname + window.location.search );
+ } catch (e) {}
+ MTrack.currentURL = href;
+ Roo.Ajax.request( {
+ method: 'GET',
+ url : window.location.pathname + window.location.search,
+ params: { ajax_body : 1 } ,
+ success : function (data) {
+ var ab = Roo.get('ajaxbody');
+ ab.dom.innerHTML = data.responseText;
+ MTrack.addHandlers(ab);
+ MTrack.missingHashes(ab, href)
+ }
+ });
+ });
+
+ },
registry : [],
/**
* usage:
- * MTrack.register('a.changeset-link', 'click', function() ....)
+ * MTrack.register('a.changeset-link', 'each', function() ....)
+ * MTrack.register('a.changeset-link', 'on', 'click', function() ....)
*
*/
- register : function( selector, event, arg1, arg2)
+ register : function( selector, method, arg1, arg2)
{
MTrack.registry.push( {
selector : selector,
});
},
+
addHandlers : function (toWhat)
{
// forEach? - no IE support?
toWhat = toWhat || document.body; //
// run the main registry
- MTrack.registry.forEach(function(cfg) {
- var el = Roo.get(toWhat).select(cfg.selector,true)
- el[cfg.method].apply(el, cfg.event ? [ event, args ] : [ args ] );
+ Roo.each(MTrack.registry, function(cfg) {
+ //Roo.log("Add select:" + cfg.selector);
+ try {
+ var el = Roo.get(toWhat).select(cfg.selector,true)
+ el[cfg.method].apply(el, cfg.event ? [ cfg.event, cfg.args ] : [ cfg.args ] );
+ } catch(e) {
+ Roo.log("Error applying select:" + cfg.selector);
+ Roo.log(e);
+ // do not throw any more..
+
+ }
});
// any other weird crap goes here.
// sortable: false
//});
+ },
+
+ currentURL : false,
+ missingHashRequest : false,
+
+
+ // This is the main body load tool...
+ // it still needs to handle anchors...
+
+
+ ajaxLoad : function(url,slideleft)
+ {
+ Roo.get(document.body).scrollTo('top',0,true);
+ this.currentURL = url;
+ var target = Roo.get("ajaxbody");
+ var content = Roo.get("content");
+ target.setStyle('position', 'relative');
+
+ Roo.select('.mask').show(); // must show first?
+ Roo.select('.mask-loading').show();
+ // content has a border...
+ var t = content.getBox().y ;// - Roo.get(document).getScroll().top;// - 13;
+ var l = content.getBox().x ;// - Roo.get(document).getScroll().left;// - 13;
+ var w = content.getBox().width+ 26;
+ var h = content.getBox().height + 26;
+
+ Roo.select('.mask').first().setLocation(l,t);
+ Roo.select('.mask').first().setSize( w , h, false );
+
+ Roo.select('.mask-loading').first().setLocation(
+ l + ( w / 2) - 16, t + 16
+ );
+
+ //if (MTrack.missingHashRequest) {
+ Roo.Ajax.abort();
+ // MTrack.missingHashRequest = false;
+ //}
+ Roo.get('loader').hide();
+ Roo.get('loader').setStyle('position', 'relative');
+ Roo.Ajax.request({
+ method: 'GET',
+ url : baseURL + url,
+ params : { ajax_body : 1 },
+ success : function(data) {
+
+ Roo.select('.mask').hide();
+ Roo.get('loader').update(data.responseText);
+ Roo.get('loader').show();
+ Roo.get('loader').setWidth( w );
+ Roo.get('loader').setLocation( slideleft? l+w : l-w , t );
+
+ // old layer - move it away..
+ target.animate(
+ {
+ left: { from : 0 , to : slideleft ? -1 * w : w }
+ },
+ .5,
+ function() {
+ // reset it at end of animation - as it ends up with the new content.
+ //target.setLocation( 0 , t );
+ },
+ 'easeOut', 'motion'
+ );
+
+ Roo.get('loader').animate(
+ {
+ left: { from : slideleft? l+w : l-w , to : l }
+ },
+ .5,
+ function () {
+ target.update( Roo.get('loader').dom.innerHTML);
+ Roo.get('loader').hide();
+ Roo.get('loader').update("");
+ target.show();// make sure!!
+ target.setLocation( l ,t );
+
+ MTrack.missingHashes(target, url);
+ MTrack.addHandlers(target);
+ // scroll up...
+
+ },
+ 'easeOut', 'motion'
+ );
+ }
+ //console.log('loaded dif');
+
+
+ });
+
+ return false;
+ },
+
+
+ missingHashRequest : false,
+ missingHashes: function(el,url) {
+ console.log('finding missing hashes?');
+ var hashes = [];
+ el.select('.browse-missing-hash').each(function() {
+ hashes.push(this.dom.id);
+ });
+
+ if (!hashes.length) {
+ Roo.log("no missing hashes");
+ return;
+ }
+ Roo.Ajax.abort();
+ Roo.Ajax.request({
+ method : 'POST',
+ url : baseURL + url,
+ params : { hashes : hashes.join(',') },
+ success : function(res) {
+ var data = Roo.decode(res.responseText);
+
+ //console.log(data.data);
+ if (data.data) {
+ for(var hash in data.data) {
+ var o = data.data[hash];
+ Roo.select('#'+ hash).first().dom.innerHTML = o.changeby + ' : ' + o.changelog;
+ Roo.select('#age-'+ hash).first().dom.innerHTML = o.age ; // do magic replacement!!!
+ Roo.select('#rev-'+ hash).first().dom.innerHTML = o.rev ; // do magic replacement!!!
+ MTrack.addHandlers(Roo.select('#age-'+ hash).first());
+ MTrack.missingHashRequest = false;
+ }
+
+ }
+ // console.log(data)
+ }
+ });
+
+ },
+ last_dh : false,
+ last_wh : false,
+
+ footerPosition : function (force) {
+ return;
+ var ele = Roo.get('footer');
+ if (!force &&
+ (MTrack.last_dh != Roo.lib.Dom.getDocumentHeight() || MTrack.last_wh != Roo.lib.Dom.getViewHeight())) {
+ force = true;
+ }
+
+ if (force) {
+ // Force a from-scratch layout assessment; put the footer back in
+ // it's natural location in the doc
+ ele.setStyle({
+ position: "relative",
+ "margin-top": "3em",
+ top: 0
+ });
+ }
+ if (Roo.lib.Dom.getDocumentHeight() <= Roo.lib.Dom.getViewHeight()) {
+ ele.setStyle({
+ position: "absolute",
+ "margin-top": "0",
+ top: (
+ Roo.get(document).getScroll().top +
+ Roo.lib.Dom.getViewHeight() -
+ ele.getSize().height - 1
+ )+"px"
+ });
+ } else {
+ ele.setStyle({
+ position: "relative",
+ "margin-top": "3em"
+ });
+ }
+ MTrack.last_dh = Roo.lib.Dom.getDocumentHeight();
+ MTrack.last_wh = Roo.lib.Dom.getViewHeight();
+ },
+
+
+ keepLoggedIn: function()
+ {
+ Roo.Ajax.request({
+ url : baseURL + '/Login.html',
+ method: 'POST',
+ data : { refresh : 1 },
+ success : function() {
+
+ window.setTimeout(MTrack.keepLoggedIn, 30000);
+ // what if it's false..currentURL = false;
+
+
+ }
+
+ })
+
+
+
+ },
+ /*
+
+ $(window)
+ .scroll(mtrack_footer_position)
+ .resize(mtrack_footer_position);
+
+ */
+
+ footerSetAndWait : function () {
+ return;
+ /*this.footerPosition();
+ window.setTimeout(function () {
+ MTrack.footerSetAndWait();
+ }, 1500);
+ */
}
+
+
+
}
Roo.onReady(function() {
Roo.select('#banner select').on('change', function(e) {
// ajax change project, and refresh body..
Roo.Ajax.request({
- url : baseURL + '/Project.html',
+ method: 'GET',
+ url : baseURL + '/core_project',
params : { active_project_id : this.value },
success : function() {
// what if it's false..currentURL = false;
});
+ MTrack.init();
+
+try {
+ window.onpopstate = function(ev) {
+
+ if (!ev.state || typeof(ev.state.url) == 'undefined') {
+ return;
+ }
+ MTrack.ajaxLoad(ev.state.url, false);
+};
+} catch (e) {}
+
+
+
+
+
+
// any date picers.. - on milestones?
MTrack.register('.dateinput', 'each', function(e) {
var ee = new Roo.form.DateField({
- dateFormat: 'yy-mm-dd' // nice and compatible..
+ dateFormat: 'Y-m-d' // nice and compatible..
});
ee.applyTo(e);
// minDate: 0,
} );
+
+MTrack.register('a.browse-link', 'on', 'click', function(event)
+{
+ event.preventDefault();
+
+ var href= this.dom.getAttribute('href').substring(baseURL.length);
+ try {
+ window.history.pushState( { url: href }, "Browse : " + href , this.dom.href );
+ Roo.log("history push state");
+ } catch (e) {
+ Roo.log(e);
+
+ }
+ var slideleft = this.is('.browse-link-up') ? 0 : 1;
+ MTrack.ajaxLoad(href,slideleft);
+});
+
+
+
//// ------------------- OLD STUFF NEEDS TIDY UP ----------------------
/*
{separator:'---------------' },
{name:'Quotes', openWith:'(!(> |!|>)!)'},
{name:'Code', openWith:'{{{\\n', closeWith:'\\n}}}'},
- {separator:'---------------' },
+ {separator:'---------------' },1
{name:'Preview', call:'preview', className:'preview'}
]
});
$('input[title!=""]').mtrackWatermark();
- // Arrange for the footer to sink to the bottom of the window, if the window
- // contents are not very tall
- var last_dh = 0;
- var last_wh = 0;
- function mtrack_footer_position(force) {
- var ele = $('#footer');
- if (!force &&
- (last_dh != $(document).height() || last_wh != $(window).height)) {
- force = true;
- }
- if (force) {
- // Force a from-scratch layout assessment; put the footer back in
- // it's natural location in the doc
- ele.css({
- position: "relative",
- "margin-top": "3em",
- top: 0
- });
- }
- if ($(document).height() <= $(window).height()) {
- ele.css({
- position: "absolute",
- "margin-top": "0",
- top: (
- $(window).scrollTop() +
- $(window).height() -
- ele.height() - 1
- )+"px"
- });
- } else {
- ele.css({
- position: "relative",
- "margin-top": "3em"
- });
- }
- last_dh = $(document).height();
- last_wh = $(window).height();
- }
- window.mtrack_footer_position = mtrack_footer_position;
- $(window)
- .scroll(mtrack_footer_position)
- .resize(mtrack_footer_position);
- function mtrack_footer_set_and_wait() {
- mtrack_footer_position();
- setTimeout(function () {
- mtrack_footer_set_and_wait();
- }, 1500);
- }
- mtrack_footer_set_and_wait();
+
});