.cd-tabs-navigation {
margin: 0;
padding: 0;
display: block;
}
.cd-tabs-navigation:after {
content: "";
display: table;
clear: both;
}
.cd-tabs-navigation li {
float: left;
display: table-cell;
width: 20%;
height: 50px;
line-height: 50px;
background: #fff;
border-right: 1px solid #D6D6D6;
border-bottom: 1px solid #D6D6D6;
overflow: hidden;
vertical-align: middle;
}
.cd-tabs-navigation a {
display: inline-table;
text-transform: uppercase;
text-align: center;
font-size: 11px;
color: #4e4d4d;
width: 100%;
line-height: 1;
padding: 0 15px;
margin: auto 0;
vertical-align: middle;
}
.cd-tabs-navigation a:hover {
color: #b42d32;
}
.cd-tabs-navigation li.selected {
background-color: #b42d32 !important;
color: #FFF;
}
.cd-tabs-navigation li.selected a, .cd-tabs-navigation li.selected a:hover {
color: #FFF;
}
Saturday, September 26, 2015
Thursday, September 24, 2015
javascript with jquery core methods for my h2o cms
/*! h2o v1.0.3 | (c) hiimeloyun@gmail.com*/
window.h2o = window.h2o || {
extend: function (x, y) {
var self = this;
if (typeof y !== 'undefined' && y) {
self = y;
}
for (var i in x) {
self[i] = x[i];
}
return self;
}
};
h2o.extend({
ajax_locked: false,
site_protocol: window.location.protocol,
site_hostname: window.location.hostname,
jstr: typeof JSON !== "undefined" ? JSON.stringify : function (obj) {
var arr = [];
$.each(obj, function (key, val) {
var next = key + ": ";
next += $.isPlainObject(val) ? h2o.jstr(val) : val;
arr.push(next);
});
return "{ " + arr.join(", ") + " }";
},
postData: function () {
var r20 = /%20/g;
//('name','value')
if (arguments.length === 2) {
var key = arguments[0];
var value = arguments[1];
return encodeURIComponent(key) + "=" + encodeURIComponent(value).replace(r20, "+");
} else {
var s = [], add = function (key, value) {
// If value is a function, invoke it and return its value
s.push(encodeURIComponent(key) + "=" + encodeURIComponent(value).replace(r20, "+"));
}, arg = arguments[0];
//any string
if (typeof arg === 'string') {
return encodeURIComponent(arg).replace(r20, "+");
} else {
//any container object
if (!Array.isArray(arg)) {
if (typeof arg === 'object' && typeof jQuery !== 'undefined') {
arg = $(arg).postItems();
}
}
//[{name:'name',value:'value'}]
for (var i = 0; i < arg.length; i++) {
add(arg[i].name, arg[i].value);
}
return s.join("&").replace(r20, "+");
}
}
}
});
h2o.extend({
base_url: (function () {
var myScripts = document.getElementsByTagName('script');
var myScript = myScripts[myScripts.length - 1];
var myArgs = myScript.src.split('?');
var myModule = '';
if (myArgs.length > 1) {
myModule = myArgs[1];
}
var host = h2o.site_hostname;
var baseurl = h2o.site_protocol + '//' + host;
var fip = host.split('.')[0];
var isip = (0 < fip && fip < 256);
if (isip === false && host.indexOf('.') > 0) {
baseurl = baseurl + (myModule.length > 0 ? '/' + myModule : '');
} else {
var jssrc = myArgs[0];
var jssrc_seg = jssrc.split('/');
var rootfolder = jssrc_seg[3];
baseurl = baseurl + (rootfolder.length > 0 ? '/' + rootfolder : '');
}
return baseurl;
})()
});
h2o.extend({
viewResult: function (result, into) {
if (typeof into === 'object') {
if ($(into).prop('tagName') === 'UL') {
$('<li/>').appendTo($(into)).html(result).hide().fadeIn('slow').refreshLayout();
} else {
$(into).html(result).hide().fadeIn('slow').refreshLayout();
}
} else if (typeof into === 'function') {
into(result);
}
},
get: function (link, into, responseType) {
if (typeof responseType === 'undefined' || !responseType) {
responseType = 'html';
}
$.ajax({
type: 'get',
dataType: responseType,
url: link,
success: function (result) {
h2o.viewResult(result, into);
}, beforeSend: function () {
if (typeof into === 'object') {
$(into).htmlWaiting();
}
}, statusCode: {
404: function () {
alert("Веб хаяг олдсонгүй!");
}
}
});
},
post: function (link, form, into, responseType) {
if (h2o.ajax_locked) {
alert('Та түр хүлээнэ үү!');
return;
}
h2o.ajax_locked = true;
if (typeof responseType === 'undefined' || !responseType) {
responseType = 'html';
}
if (typeof form === 'undefined' || !form) {
form = link;
link = ($(form).prop('tagName') === 'FORM') ? form.attr('action') : form.attr('data-action');
}
var sendParams = null;
if (typeof form === 'string') {
sendParams = form;
} else {
if ($(form).prop('tagName') === 'FORM')
sendParams = $(form).serialize();
else
sendParams = h2o.postData(form);
}
$.ajax({
type: 'post',
dataType: responseType,
url: link,
data: sendParams,
success: function (result) {
h2o.viewResult(result, into);
}, beforeSend: function () {
if (typeof into === 'object') {
$(into).htmlWaiting();
}
}, error: function (request, status, error) {
alert(request.responseText);
}, complete: function (result) {
h2o.ajax_locked = false;
}
});
},
action: function (link, funcBefore, funcAfter, method, responseType) {
if (typeof method === 'undefined') {
method = 'get';
}
if (typeof responseType === 'undefined') {
responseType = 'json';
}
$.ajax({
type: method,
dataType: responseType,
url: link,
cache: false,
success: function (result) {
if (funcAfter)
funcAfter(result);
else
funcBefore(result);
}, beforeSend: function () {
if (funcAfter)
funcBefore();
}, statusCode: {
404: function () {
alert("Веб хаяг олдсонгүй!");
}
}
});
},
redirect: function (link) {
if (window.location.href) {
window.location.href = link;
} else {
window.location = link;
}
},
// window scroll function
scrollToID: function (id, speed) {
var offSet = 50;
var targetOffset = $(id).offset().top - offSet;
var mainNav = $('#main-nav');
$('html,body').animate({scrollTop: targetOffset}, speed);
if (typeof mainNav !== 'undefined' && mainNav.hasClass("open")) {
mainNav.css("height", "1px").removeClass("in").addClass("collapse");
mainNav.removeClass("open");
}
},
navlink: function (obj, into) {
if (typeof into === 'undefined' || !into || into === null) {
into = h2o.panel();
}
return $(obj).each(function () {
$(this).click(function () {
h2o.get($(this).attr('href'), into);
return false;
});
});
},
set_meta: function (ajson, cjson) {
/*<meta name="author" content="">*/
$('title').text(ajson.meta_title + ' - ' + h2o.site_hostname);
$('meta[name]').each(function (ndx, tag) {
var name = $(tag).attr('name');
if (typeof name !== 'undefined') {
if (name === 'title') {
$(tag).attr('content', ajson.meta_title);
}
if (name === 'description') {
$(tag).attr('content', ajson.meta_description);
}
if (name === 'keywords') {
var cmeta_title = (typeof cjson !== 'undefined') ? cjson.meta_title : ajson.meta_title;
$(tag).attr('content', cmeta_title + ', ' + ajson.meta_keywords + ' - ' + h2o.site_hostname);
}
if (name === 'author') {
$(tag).attr('content', ajson.meta_author);
}
}
});
}
});
h2o.extend({
imgsViewer: function (obj) {
var fadeDuration = 2000, slideDuration = 4000, currentIndex = 1, nextIndex = 1,
nextSlide = function () {
nextIndex = currentIndex + 1;
if (nextIndex > $(obj).children().size()) {
nextIndex = 1;
}
var next = $(obj).find('li:nth-child(' + nextIndex + ')');
var curr = $(obj).find('li:nth-child(' + currentIndex + ')');
next.addClass('ishow').animate({opacity: 1.0}, fadeDuration);
curr.removeClass('ishow').animate({opacity: 0.0}, fadeDuration);
currentIndex = nextIndex;
setTimeout(nextSlide, slideDuration);
};
$(obj).find('li').css({opacity: 0.0});
$(obj).find('li:nth-child(' + nextIndex + ')')
.addClass('ishow').animate({opacity: 1.0}, fadeDuration);
setTimeout(nextSlide, slideDuration);
return this;
},
bgImager: function (arg) {
var self = this, pane = $('#bg-images'), c = 0, t = 4000, bgi = null, bgis = arg,
changeBg = function () {
if (pane.find('.img').size() > 0) {
var prevImg = pane.find('.img').eq(0);
bgi.show().insertBefore(prevImg).next().fadeTo(1000, 0, function () {
$(this).remove();
nextBg();
});
} else {
bgi.appendTo(pane).fadeTo(1000, 1, function () {
nextBg();
});
}
},
nextBg = function () {
c = Math.RandInt(0, bgis.length);
if (c >= bgis.length) {
c = 0;
}
var img = $('<img/>').addClass('img');
$(img).load(function () {
bgi = $(this).hide();
if (pane.find('.img').size() > 0) {
setTimeout(changeBg, t);
} else {
changeBg();
}
}).attr('src', h2o.base_url + '/' + bgis[c]);
},
initBg = function (s) {//s is second
if (pane.css('margin-top') === '1px') {
return false;
}
$(window).bind('resize.bgimager', function () {
var win_w = $(window).width();
pane.find('.img').each(function (index, img) {
var img_w = $(img).width();
if (img_w >= win_w) {
var w = (win_w - img_w) / 2;
$(img).css('left', w);
}
});
});
t = 1000 * s;
nextBg();
};
self.init = initBg;
return this;
},
initGmap: function () {
var googleMaps = google && typeof google !== 'undefined' ? google.maps : 'undefined';
if (typeof googleMaps !== 'undefined') {
var self = this.initGmap || h2o.initGmap;
h2o.extend({mapEditState: false, bounds: []}, self);
var mapCanvas = document.getElementById('map_canvas');
var mapInput = document.getElementById('googlemap');
var latitude = self.bound_lat;
var longitude = self.bound_lng;
var marker_latitude = self.marker_lat;
var marker_longitude = self.marker_lng;
var bound_Latlng = new googleMaps.LatLng(latitude, longitude);
var marker_Latlng = new googleMaps.LatLng(marker_latitude, marker_longitude);
var mapOptions = {
center: bound_Latlng,
zoom: self.bound_zoom,
mapTypeId: googleMaps.MapTypeId.HYBRID
};
var map = new googleMaps.Map(mapCanvas, mapOptions);
var styles = [
{
featureType: "all",
elementType: "labels",
stylers: [
{visibility: "on"}
]
}
];
map.setOptions({styles: styles});
var marker = new googleMaps.Marker({
position: marker_Latlng,
map: map,
draggable: true,
title: "Сонгосон байршил"
//icon: 'brown_markerA.png'
});
var markedPlaceSave = function () {
var location = marker.getPosition();
var zoom = map.getZoom();
var bounds = map.getBounds();
var ne = bounds.getNorthEast();
var sw = bounds.getSouthWest();
self.bounds = ne.lat() + ',' + ne.lng() + ',' + sw.lat() + ',' + sw.lng()
+ ',' + zoom + ',' + location.lat() + ',' + location.lng();
var msg = 'gmb=' + self.bounds;
if (mapInput) {
mapInput.value = self.bounds;
}
var latlngSpans = $('#map-usage-body .latlng span');
latlngSpans.first().html(location.lat());
latlngSpans.last().html(location.lng());
if (self.mapEditState) {
var link = h2o.base_url + '/zarwrite/gmap?' + msg;
h2o.action(link, function (result) {
if (result.success) {
$('.googlemap .title').html('Байршил: ' + result.data[5] + ', ' + result.data[6]);
} else {
alert(result.message);
}
});
}
};
googleMaps.event.addListener(map, 'click', function (event) {
var location = event.latLng;
marker.setPosition(location);
markedPlaceSave();
});
googleMaps.event.addListener(marker, 'dragend', function (event) {
var location = event.latLng;
marker.setPosition(location);
markedPlaceSave();
});
googleMaps.event.addListener(map, 'bounds_changed', function () {
try {
markedPlaceSave();
} catch (err) {
alert(err);
}
});
}
},
reloadCaptchaImg: function (capimg) {
var link = h2o.base_url + '/captcha/image?' + getTimeAsLong();
$.ajax({
url: link,
success: function (result) {
var par = capimg.parent();
capimg.remove();
capimg = $('<img src="' + result + '"/>');
capimg.appendTo(par);
capimg.animate({'opacity': '1'}, {
duration: 300
});
}
});
},
insertedFileCancel: function (closeSpan) {
closeSpan.click(function (evt) {
evt.preventDefault();
var par = closeSpan.parents('div').first();
var mid = par.find('a').attr('data-id');
par.remove();
var link = h2o.base_url + '/media/deleteFile?fileid=' + mid;
h2o.action(link, function (result) {
if (result.error) {
alert(result.message);
}
});
});
},
initFileUpload: function (fileCtl) {
'use strict';
// Change this to the location of your server-side upload handler:
var url = window.location.hostname === 'blueimp.github.io' ?
'//jquery-file-upload.appspot.com/' : h2o.base_url + '/media/upload';
var uploadButton = $('<button/>')
.addClass('btn btn-primary')
.prop('disabled', true)
.text('Processing...')
.on('click', function () {
var $this = $(this), data = $this.data();
$this.off('click').text('Abort').on('click', function () {
$this.remove();
data.abort();
});
data.submit().always(function () {
$this.remove();
});
});
var maxNumberOfFiles = 8;
fileCtl.click(function (event) {
if ($('#files > div').size() >= maxNumberOfFiles) {
event.preventDefault();
alert(maxNumberOfFiles + ' -с илүү файл хуулах боломжгүй!');
}
});
try {
fileCtl.fileupload({
url: url,
dataType: 'json',
autoUpload: true, //false
acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i,
maxFileSize: 5000000, // 5 MB
limitConcurrentUploads: 1,
maxNumberOfFiles: maxNumberOfFiles,
// Enable image resizing, except for Android and Opera,
// which actually support image resizing, but fail to
// send Blob objects via XHR requests:
disableImageResize: /Android(?!.*Chrome)|Opera/
.test(window.navigator.userAgent),
previewMaxWidth: 50,
previewMaxHeight: 50,
previewCrop: true
}).on('fileuploadadd', function (e, data) {
if ($('#files > div').size() >= maxNumberOfFiles) {
alert(maxNumberOfFiles + ' -с илүү файл хуулах боломжгүй!');
return false;
}
data.context = $('<div/>').appendTo('#files');
$.each(data.files, function (index, file) {
var closeSpan = $('<span/>').text('Болих').prepend($('<i class="glyphicon glyphicon-remove"></i>'));
h2o.insertedFileCancel(closeSpan);
var node = $('<p/>').attr('title', file.name).append(closeSpan);
if (!index) {
//node.append('<br>').append(uploadButton.clone(true).data(data));
}
node.appendTo(data.context);
});
}).on('fileuploadprocessalways', function (e, data) {
var index = data.index,
file = data.files[index],
node = $(data.context.children()[index]);
if (file.preview) {
node.prepend('<br>').prepend(file.preview);
}
if (file.error) {
node.append($('<span class="text-danger"/>').text(file.error));
}
if (index + 1 === data.files.length) {
data.context.find('button').text('Upload').prop('disabled', !!data.files.error);
}
}).on('fileuploadprogressall', function (e, data) {
var progress = parseInt(data.loaded / data.total * 100, 10);
$('#progress .progress-bar').css('width', progress + '%');
}).on('fileuploaddone', function (e, data) {
$.each(data.result.files, function (index, file) {
if (file.url) {
var link = $('<a>').attr('target', '_blank').attr('data-id', file.id).prop('href', file.url);
$(data.context.children()[index]).wrap(link);
} else if (file.error) {
var error = $('<span class="text-danger"/>').text(file.error);
$(data.context.children()[index]).append(error);
}
});
}).on('fileuploadfail', function (e, data) {
$.each(data.files, function (index) {
var error = $('<span class="text-danger"/>').text('Алдаа!');
$(data.context.children()[index]).append(error);
});
}).prop('disabled', !$.support.fileInput).parent().addClass($.support.fileInput ? undefined : 'disabled');
} catch (err) {
alert(err);
}
},
send_contact: function (button) {
var form = $(button).parents('dl').parent();
form.find('.label').addClass('hidden');
h2o.post(h2o.base_url + '/contact/send', form, function (result) {
if (result.success) {
$(form).find('.label-success').removeClass('hidden');
$(form).find('input,textarea').val('');
} else {
$(form).find('.label-danger').removeClass('hidden');
if (result.message) {
alert(result.message);
}
}
}
, 'json');
}
});
h2o.extend({
initResBgImages: function () {
var c_url = h2o.base_url + '/res/images/bg/7200';
h2o.action(c_url, function (result) {
h2o.bgImager(result).init(6);
});
}
});
window.h2o = window.h2o || {
extend: function (x, y) {
var self = this;
if (typeof y !== 'undefined' && y) {
self = y;
}
for (var i in x) {
self[i] = x[i];
}
return self;
}
};
h2o.extend({
ajax_locked: false,
site_protocol: window.location.protocol,
site_hostname: window.location.hostname,
jstr: typeof JSON !== "undefined" ? JSON.stringify : function (obj) {
var arr = [];
$.each(obj, function (key, val) {
var next = key + ": ";
next += $.isPlainObject(val) ? h2o.jstr(val) : val;
arr.push(next);
});
return "{ " + arr.join(", ") + " }";
},
postData: function () {
var r20 = /%20/g;
//('name','value')
if (arguments.length === 2) {
var key = arguments[0];
var value = arguments[1];
return encodeURIComponent(key) + "=" + encodeURIComponent(value).replace(r20, "+");
} else {
var s = [], add = function (key, value) {
// If value is a function, invoke it and return its value
s.push(encodeURIComponent(key) + "=" + encodeURIComponent(value).replace(r20, "+"));
}, arg = arguments[0];
//any string
if (typeof arg === 'string') {
return encodeURIComponent(arg).replace(r20, "+");
} else {
//any container object
if (!Array.isArray(arg)) {
if (typeof arg === 'object' && typeof jQuery !== 'undefined') {
arg = $(arg).postItems();
}
}
//[{name:'name',value:'value'}]
for (var i = 0; i < arg.length; i++) {
add(arg[i].name, arg[i].value);
}
return s.join("&").replace(r20, "+");
}
}
}
});
h2o.extend({
base_url: (function () {
var myScripts = document.getElementsByTagName('script');
var myScript = myScripts[myScripts.length - 1];
var myArgs = myScript.src.split('?');
var myModule = '';
if (myArgs.length > 1) {
myModule = myArgs[1];
}
var host = h2o.site_hostname;
var baseurl = h2o.site_protocol + '//' + host;
var fip = host.split('.')[0];
var isip = (0 < fip && fip < 256);
if (isip === false && host.indexOf('.') > 0) {
baseurl = baseurl + (myModule.length > 0 ? '/' + myModule : '');
} else {
var jssrc = myArgs[0];
var jssrc_seg = jssrc.split('/');
var rootfolder = jssrc_seg[3];
baseurl = baseurl + (rootfolder.length > 0 ? '/' + rootfolder : '');
}
return baseurl;
})()
});
h2o.extend({
viewResult: function (result, into) {
if (typeof into === 'object') {
if ($(into).prop('tagName') === 'UL') {
$('<li/>').appendTo($(into)).html(result).hide().fadeIn('slow').refreshLayout();
} else {
$(into).html(result).hide().fadeIn('slow').refreshLayout();
}
} else if (typeof into === 'function') {
into(result);
}
},
get: function (link, into, responseType) {
if (typeof responseType === 'undefined' || !responseType) {
responseType = 'html';
}
$.ajax({
type: 'get',
dataType: responseType,
url: link,
success: function (result) {
h2o.viewResult(result, into);
}, beforeSend: function () {
if (typeof into === 'object') {
$(into).htmlWaiting();
}
}, statusCode: {
404: function () {
alert("Веб хаяг олдсонгүй!");
}
}
});
},
post: function (link, form, into, responseType) {
if (h2o.ajax_locked) {
alert('Та түр хүлээнэ үү!');
return;
}
h2o.ajax_locked = true;
if (typeof responseType === 'undefined' || !responseType) {
responseType = 'html';
}
if (typeof form === 'undefined' || !form) {
form = link;
link = ($(form).prop('tagName') === 'FORM') ? form.attr('action') : form.attr('data-action');
}
var sendParams = null;
if (typeof form === 'string') {
sendParams = form;
} else {
if ($(form).prop('tagName') === 'FORM')
sendParams = $(form).serialize();
else
sendParams = h2o.postData(form);
}
$.ajax({
type: 'post',
dataType: responseType,
url: link,
data: sendParams,
success: function (result) {
h2o.viewResult(result, into);
}, beforeSend: function () {
if (typeof into === 'object') {
$(into).htmlWaiting();
}
}, error: function (request, status, error) {
alert(request.responseText);
}, complete: function (result) {
h2o.ajax_locked = false;
}
});
},
action: function (link, funcBefore, funcAfter, method, responseType) {
if (typeof method === 'undefined') {
method = 'get';
}
if (typeof responseType === 'undefined') {
responseType = 'json';
}
$.ajax({
type: method,
dataType: responseType,
url: link,
cache: false,
success: function (result) {
if (funcAfter)
funcAfter(result);
else
funcBefore(result);
}, beforeSend: function () {
if (funcAfter)
funcBefore();
}, statusCode: {
404: function () {
alert("Веб хаяг олдсонгүй!");
}
}
});
},
redirect: function (link) {
if (window.location.href) {
window.location.href = link;
} else {
window.location = link;
}
},
// window scroll function
scrollToID: function (id, speed) {
var offSet = 50;
var targetOffset = $(id).offset().top - offSet;
var mainNav = $('#main-nav');
$('html,body').animate({scrollTop: targetOffset}, speed);
if (typeof mainNav !== 'undefined' && mainNav.hasClass("open")) {
mainNav.css("height", "1px").removeClass("in").addClass("collapse");
mainNav.removeClass("open");
}
},
navlink: function (obj, into) {
if (typeof into === 'undefined' || !into || into === null) {
into = h2o.panel();
}
return $(obj).each(function () {
$(this).click(function () {
h2o.get($(this).attr('href'), into);
return false;
});
});
},
set_meta: function (ajson, cjson) {
/*<meta name="author" content="">*/
$('title').text(ajson.meta_title + ' - ' + h2o.site_hostname);
$('meta[name]').each(function (ndx, tag) {
var name = $(tag).attr('name');
if (typeof name !== 'undefined') {
if (name === 'title') {
$(tag).attr('content', ajson.meta_title);
}
if (name === 'description') {
$(tag).attr('content', ajson.meta_description);
}
if (name === 'keywords') {
var cmeta_title = (typeof cjson !== 'undefined') ? cjson.meta_title : ajson.meta_title;
$(tag).attr('content', cmeta_title + ', ' + ajson.meta_keywords + ' - ' + h2o.site_hostname);
}
if (name === 'author') {
$(tag).attr('content', ajson.meta_author);
}
}
});
}
});
h2o.extend({
imgsViewer: function (obj) {
var fadeDuration = 2000, slideDuration = 4000, currentIndex = 1, nextIndex = 1,
nextSlide = function () {
nextIndex = currentIndex + 1;
if (nextIndex > $(obj).children().size()) {
nextIndex = 1;
}
var next = $(obj).find('li:nth-child(' + nextIndex + ')');
var curr = $(obj).find('li:nth-child(' + currentIndex + ')');
next.addClass('ishow').animate({opacity: 1.0}, fadeDuration);
curr.removeClass('ishow').animate({opacity: 0.0}, fadeDuration);
currentIndex = nextIndex;
setTimeout(nextSlide, slideDuration);
};
$(obj).find('li').css({opacity: 0.0});
$(obj).find('li:nth-child(' + nextIndex + ')')
.addClass('ishow').animate({opacity: 1.0}, fadeDuration);
setTimeout(nextSlide, slideDuration);
return this;
},
bgImager: function (arg) {
var self = this, pane = $('#bg-images'), c = 0, t = 4000, bgi = null, bgis = arg,
changeBg = function () {
if (pane.find('.img').size() > 0) {
var prevImg = pane.find('.img').eq(0);
bgi.show().insertBefore(prevImg).next().fadeTo(1000, 0, function () {
$(this).remove();
nextBg();
});
} else {
bgi.appendTo(pane).fadeTo(1000, 1, function () {
nextBg();
});
}
},
nextBg = function () {
c = Math.RandInt(0, bgis.length);
if (c >= bgis.length) {
c = 0;
}
var img = $('<img/>').addClass('img');
$(img).load(function () {
bgi = $(this).hide();
if (pane.find('.img').size() > 0) {
setTimeout(changeBg, t);
} else {
changeBg();
}
}).attr('src', h2o.base_url + '/' + bgis[c]);
},
initBg = function (s) {//s is second
if (pane.css('margin-top') === '1px') {
return false;
}
$(window).bind('resize.bgimager', function () {
var win_w = $(window).width();
pane.find('.img').each(function (index, img) {
var img_w = $(img).width();
if (img_w >= win_w) {
var w = (win_w - img_w) / 2;
$(img).css('left', w);
}
});
});
t = 1000 * s;
nextBg();
};
self.init = initBg;
return this;
},
initGmap: function () {
var googleMaps = google && typeof google !== 'undefined' ? google.maps : 'undefined';
if (typeof googleMaps !== 'undefined') {
var self = this.initGmap || h2o.initGmap;
h2o.extend({mapEditState: false, bounds: []}, self);
var mapCanvas = document.getElementById('map_canvas');
var mapInput = document.getElementById('googlemap');
var latitude = self.bound_lat;
var longitude = self.bound_lng;
var marker_latitude = self.marker_lat;
var marker_longitude = self.marker_lng;
var bound_Latlng = new googleMaps.LatLng(latitude, longitude);
var marker_Latlng = new googleMaps.LatLng(marker_latitude, marker_longitude);
var mapOptions = {
center: bound_Latlng,
zoom: self.bound_zoom,
mapTypeId: googleMaps.MapTypeId.HYBRID
};
var map = new googleMaps.Map(mapCanvas, mapOptions);
var styles = [
{
featureType: "all",
elementType: "labels",
stylers: [
{visibility: "on"}
]
}
];
map.setOptions({styles: styles});
var marker = new googleMaps.Marker({
position: marker_Latlng,
map: map,
draggable: true,
title: "Сонгосон байршил"
//icon: 'brown_markerA.png'
});
var markedPlaceSave = function () {
var location = marker.getPosition();
var zoom = map.getZoom();
var bounds = map.getBounds();
var ne = bounds.getNorthEast();
var sw = bounds.getSouthWest();
self.bounds = ne.lat() + ',' + ne.lng() + ',' + sw.lat() + ',' + sw.lng()
+ ',' + zoom + ',' + location.lat() + ',' + location.lng();
var msg = 'gmb=' + self.bounds;
if (mapInput) {
mapInput.value = self.bounds;
}
var latlngSpans = $('#map-usage-body .latlng span');
latlngSpans.first().html(location.lat());
latlngSpans.last().html(location.lng());
if (self.mapEditState) {
var link = h2o.base_url + '/zarwrite/gmap?' + msg;
h2o.action(link, function (result) {
if (result.success) {
$('.googlemap .title').html('Байршил: ' + result.data[5] + ', ' + result.data[6]);
} else {
alert(result.message);
}
});
}
};
googleMaps.event.addListener(map, 'click', function (event) {
var location = event.latLng;
marker.setPosition(location);
markedPlaceSave();
});
googleMaps.event.addListener(marker, 'dragend', function (event) {
var location = event.latLng;
marker.setPosition(location);
markedPlaceSave();
});
googleMaps.event.addListener(map, 'bounds_changed', function () {
try {
markedPlaceSave();
} catch (err) {
alert(err);
}
});
}
},
reloadCaptchaImg: function (capimg) {
var link = h2o.base_url + '/captcha/image?' + getTimeAsLong();
$.ajax({
url: link,
success: function (result) {
var par = capimg.parent();
capimg.remove();
capimg = $('<img src="' + result + '"/>');
capimg.appendTo(par);
capimg.animate({'opacity': '1'}, {
duration: 300
});
}
});
},
insertedFileCancel: function (closeSpan) {
closeSpan.click(function (evt) {
evt.preventDefault();
var par = closeSpan.parents('div').first();
var mid = par.find('a').attr('data-id');
par.remove();
var link = h2o.base_url + '/media/deleteFile?fileid=' + mid;
h2o.action(link, function (result) {
if (result.error) {
alert(result.message);
}
});
});
},
initFileUpload: function (fileCtl) {
'use strict';
// Change this to the location of your server-side upload handler:
var url = window.location.hostname === 'blueimp.github.io' ?
'//jquery-file-upload.appspot.com/' : h2o.base_url + '/media/upload';
var uploadButton = $('<button/>')
.addClass('btn btn-primary')
.prop('disabled', true)
.text('Processing...')
.on('click', function () {
var $this = $(this), data = $this.data();
$this.off('click').text('Abort').on('click', function () {
$this.remove();
data.abort();
});
data.submit().always(function () {
$this.remove();
});
});
var maxNumberOfFiles = 8;
fileCtl.click(function (event) {
if ($('#files > div').size() >= maxNumberOfFiles) {
event.preventDefault();
alert(maxNumberOfFiles + ' -с илүү файл хуулах боломжгүй!');
}
});
try {
fileCtl.fileupload({
url: url,
dataType: 'json',
autoUpload: true, //false
acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i,
maxFileSize: 5000000, // 5 MB
limitConcurrentUploads: 1,
maxNumberOfFiles: maxNumberOfFiles,
// Enable image resizing, except for Android and Opera,
// which actually support image resizing, but fail to
// send Blob objects via XHR requests:
disableImageResize: /Android(?!.*Chrome)|Opera/
.test(window.navigator.userAgent),
previewMaxWidth: 50,
previewMaxHeight: 50,
previewCrop: true
}).on('fileuploadadd', function (e, data) {
if ($('#files > div').size() >= maxNumberOfFiles) {
alert(maxNumberOfFiles + ' -с илүү файл хуулах боломжгүй!');
return false;
}
data.context = $('<div/>').appendTo('#files');
$.each(data.files, function (index, file) {
var closeSpan = $('<span/>').text('Болих').prepend($('<i class="glyphicon glyphicon-remove"></i>'));
h2o.insertedFileCancel(closeSpan);
var node = $('<p/>').attr('title', file.name).append(closeSpan);
if (!index) {
//node.append('<br>').append(uploadButton.clone(true).data(data));
}
node.appendTo(data.context);
});
}).on('fileuploadprocessalways', function (e, data) {
var index = data.index,
file = data.files[index],
node = $(data.context.children()[index]);
if (file.preview) {
node.prepend('<br>').prepend(file.preview);
}
if (file.error) {
node.append($('<span class="text-danger"/>').text(file.error));
}
if (index + 1 === data.files.length) {
data.context.find('button').text('Upload').prop('disabled', !!data.files.error);
}
}).on('fileuploadprogressall', function (e, data) {
var progress = parseInt(data.loaded / data.total * 100, 10);
$('#progress .progress-bar').css('width', progress + '%');
}).on('fileuploaddone', function (e, data) {
$.each(data.result.files, function (index, file) {
if (file.url) {
var link = $('<a>').attr('target', '_blank').attr('data-id', file.id).prop('href', file.url);
$(data.context.children()[index]).wrap(link);
} else if (file.error) {
var error = $('<span class="text-danger"/>').text(file.error);
$(data.context.children()[index]).append(error);
}
});
}).on('fileuploadfail', function (e, data) {
$.each(data.files, function (index) {
var error = $('<span class="text-danger"/>').text('Алдаа!');
$(data.context.children()[index]).append(error);
});
}).prop('disabled', !$.support.fileInput).parent().addClass($.support.fileInput ? undefined : 'disabled');
} catch (err) {
alert(err);
}
},
send_contact: function (button) {
var form = $(button).parents('dl').parent();
form.find('.label').addClass('hidden');
h2o.post(h2o.base_url + '/contact/send', form, function (result) {
if (result.success) {
$(form).find('.label-success').removeClass('hidden');
$(form).find('input,textarea').val('');
} else {
$(form).find('.label-danger').removeClass('hidden');
if (result.message) {
alert(result.message);
}
}
}
, 'json');
}
});
h2o.extend({
initResBgImages: function () {
var c_url = h2o.base_url + '/res/images/bg/7200';
h2o.action(c_url, function (result) {
h2o.bgImager(result).init(6);
});
}
});
Wednesday, September 23, 2015
how to get site base url in javascript
js dotoroo base_url aa avah neg iimerhuu arga baij boloh yum
<?php echo base_url(); ?>
or
base_url: (function () {
var myScripts = document.getElementsByTagName('script');
var myScript = myScripts[myScripts.length - 1];
var myArgs = myScript.src.split('?');
var myModule = '';
if (myArgs.length > 1) {
myModule = myArgs[1];
}
var host = window.location.hostname;
var baseurl = window.location.protocol + '//' + host;
var fip = host.split('.')[0];
var isip = (0 < fip && fip < 256);
if (isip === false && host.indexOf('.') > 0) {
baseurl = baseurl + (myModule.length > 0 ? '/' + myModule : '');
} else {
var jssrc = myArgs[0];
var jssrc_seg = jssrc.split('/');
var rootfolder = jssrc_seg[3];
baseurl = baseurl + (rootfolder.length > 0 ? '/' + rootfolder : '');
}
return baseurl;
})()
<?php echo base_url(); ?>
or
base_url: (function () {
var myScripts = document.getElementsByTagName('script');
var myScript = myScripts[myScripts.length - 1];
var myArgs = myScript.src.split('?');
var myModule = '';
if (myArgs.length > 1) {
myModule = myArgs[1];
}
var host = window.location.hostname;
var baseurl = window.location.protocol + '//' + host;
var fip = host.split('.')[0];
var isip = (0 < fip && fip < 256);
if (isip === false && host.indexOf('.') > 0) {
baseurl = baseurl + (myModule.length > 0 ? '/' + myModule : '');
} else {
var jssrc = myArgs[0];
var jssrc_seg = jssrc.split('/');
var rootfolder = jssrc_seg[3];
baseurl = baseurl + (rootfolder.length > 0 ? '/' + rootfolder : '');
}
return baseurl;
})()
Subscribe to:
Posts (Atom)