sammy icon indicating copy to clipboard operation
sammy copied to clipboard

Best practice for sammy js

Open El-Mahbub opened this issue 7 years ago • 0 comments

How is the best practice with sammy js ? I have this codes, what is it best practice ? But i think it is not a best practice. My codes : ` var app, app_name, base_url, url = [], cdn, websocket; var body, navbar, container_content, left_side, main_side, main_content, other_side, right_side, footer; var uid, user_id, name;

// Config var config = { host : 'http://localhost:8080/xampp/MyApp/', app_name : window.location.pathname.split('/').length > 1 ? window.location.pathname.split('/')[2] : window.location.pathname.split('/')[1], target : 'body' }

// Autoload var autoload = { base_url: config.host, error_404: '' };

// Url's var url = { login: '#/', profile: 'profile/index/', kronologi: 'profile/kronologi/', status_profile: 'profile/status/', global: 'page/global_page', status_global: 'page/status_global/', recomended: 'page/all_recomended' }

// System Object.keys(url).forEach(function (key) { url[key] = config.host + url[key]; });

base_url = autoload.base_url; app_name = config.app_name; name = $('#nama-profile').children().text();

// Controller var routes = $.sammy(function(){ app = this; this.element_selector = config.target; this.run_interval_every = 60000; this.get('#/', function (context) {

});
this.get('#/login', function (context) {
	app.redirect('#/');
});
this.get('#/signup', function (context) {
	
});
this.get('#/profile/index/:username', function (context) {
	var params = this.params['username'];
	profile(context.$element(),url.profile+params,params);
});
this.get('#/global/', function (context) {
	render(context.$element(),url.global,'status_global');
});
this.get('#/gallery/:username', function (context) {
	
});;
this.get('#/adsennse/:username', function (context) {
	
});
this.get('#/report/:id', function (context) {
	
});
this.get('#/help/', function (context) {
	
});
this.get('#/feedback/:id', function (context) {
	
});
this.get('#/about/', function (context) {
	
});
this.get('#/log_out/:id', function (context) {
	
});

}).run('#/');

// Views

// Profile function profile(el,controller,name) { render(el,controller,'kronologi'); change_title(str_replace(app_name,'/','')+' - '+str_replace(name,'',' ')); $(document).find('.title-user').html('

Profil '+str_replace(name,'

',' ')+'');

} function kronologi(el,controller,user_id) { render(el,controller,'status_profile'); }

// Global

function global(el,controller) { change_title(str_replace(app_name,'/','')+' - '+'Global'); $(document).find('.title-user').html('

Global page

'); render(el,controller,''); }

// Helpers

function render(params1,params2,params3) { $.ajax({ url: params2, type: 'post', beforeSend:function (argument) {

	},
	error:function (data) {
		error_load($(params1),data);	
	},
	success: function (data) {
		$(params1).html(data);
		navbar = $('nav');
		container_content = $('#container');
		left_side = $('#menu_user');
		main_side = $('.profile_content');
		main_content = $('.main_profile');
		content_status = $('#status-profile');
		other_side = $('.statistic_user');
		right_side = $('#online_side');
		footer = $('footer');
		uid = $('.title-user').attr('ux');
		user_id = $('.title-user').attr('ui');
		uid === '' ? window.location.href = url.login : null;
		if(params3 !== ''){
			switch (params3) {
				case 'kronologi':
					kronologi(main_content,url.kronologi+user_id,user_id);
					break;
				case 'status_profile':
					loadStatus(content_status,url.status_profile+user_id+'/');
					status();
					break;
				case 'status_global':
					global(other_side,url.recomended);
					loadStatus(main_content,url.status_global+uid+'/');
					break;
			}
		}
		else { null; }
		}
});
return true;

} function site_url(args){ return config.host + args; } function loadStatus(el,urlTarget) { $(el).loadStatus({ loading : "", no_news : "", error_text : "Terjadi kesalahan memuat konten", url : urlTarget, start : 1 }); } function change_title(argument) { $(document).find('title').text(argument); } function str_replace(args,haystack,needle) { return args.replace(haystack,needle); }`

Hope you can give me the best practice in documentation, because i know about jquery but just litle for sammy :-)

El-Mahbub avatar Oct 13 '17 03:10 El-Mahbub