PageRenderTime 51ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/charisma/js/charisma.js

https://github.com/zaddone/Member
JavaScript | 702 lines | 530 code | 103 blank | 69 comment | 63 complexity | aed20817dd5122ead319576b1693feb2 MD5 | raw file
Possible License(s): Apache-2.0
  1. $(document).ready(function(){
  2. //themes, change CSS with JS
  3. //default theme(CSS) is cerulean, change it if needed
  4. var current_theme = $.cookie('current_theme')==null ? 'cerulean' :$.cookie('current_theme');
  5. switch_theme(current_theme);
  6. $('#themes a[data-value="'+current_theme+'"]').find('i').addClass('icon-ok');
  7. $('#themes a').click(function(e){
  8. e.preventDefault();
  9. current_theme=$(this).attr('data-value');
  10. $.cookie('current_theme',current_theme,{expires:365});
  11. switch_theme(current_theme);
  12. $('#themes i').removeClass('icon-ok');
  13. $(this).find('i').addClass('icon-ok');
  14. });
  15. function switch_theme(theme_name)
  16. {
  17. $('#bs-css').attr('href','css/bootstrap-'+theme_name+'.css');
  18. }
  19. //ajax menu checkbox
  20. $('#is-ajax').click(function(e){
  21. $.cookie('is-ajax',$(this).prop('checked'),{expires:365});
  22. });
  23. $('#is-ajax').prop('checked',$.cookie('is-ajax')==='true' ? true : false);
  24. //disbaling some functions for Internet Explorer
  25. if($.browser.msie)
  26. {
  27. $('#is-ajax').prop('checked',false);
  28. $('#for-is-ajax').hide();
  29. $('#toggle-fullscreen').hide();
  30. $('.login-box').find('.input-large').removeClass('span10');
  31. }
  32. //highlight current / active link
  33. $('ul.main-menu li a').each(function(){
  34. if($($(this))[0].href==String(window.location))
  35. $(this).parent().addClass('active');
  36. });
  37. //establish history variables
  38. var
  39. History = window.History, // Note: We are using a capital H instead of a lower h
  40. State = History.getState(),
  41. $log = $('#log');
  42. //bind to State Change
  43. History.Adapter.bind(window,'statechange',function(){ // Note: We are using statechange instead of popstate
  44. var State = History.getState(); // Note: We are using History.getState() instead of event.state
  45. $.ajax({
  46. url:State.url,
  47. success:function(msg){
  48. $('#content').html($(msg).find('#content').html());
  49. $('#loading').remove();
  50. $('#content').fadeIn();
  51. var newTitle = $(msg).filter('title').text();
  52. $('title').text(newTitle);
  53. docReady();
  54. }
  55. });
  56. });
  57. //ajaxify menus
  58. $('a.ajax-link').click(function(e){
  59. if($.browser.msie) e.which=1;
  60. if(e.which!=1 || !$('#is-ajax').prop('checked') || $(this).parent().hasClass('active')) return;
  61. e.preventDefault();
  62. if($('.btn-navbar').is(':visible'))
  63. {
  64. $('.btn-navbar').click();
  65. }
  66. $('#loading').remove();
  67. $('#content').fadeOut().parent().append('<div id="loading" class="center">Loading...<div class="center"></div></div>');
  68. var $clink=$(this);
  69. History.pushState(null, null, $clink.attr('href'));
  70. $('ul.main-menu li.active').removeClass('active');
  71. $clink.parent('li').addClass('active');
  72. });
  73. //animating menus on hover
  74. $('ul.main-menu li:not(.nav-header)').hover(function(){
  75. $(this).animate({'margin-left':'+=5'},300);
  76. },
  77. function(){
  78. $(this).animate({'margin-left':'-=5'},300);
  79. });
  80. //other things to do on document ready, seperated for ajax calls
  81. docReady();
  82. });
  83. function docReady(){
  84. //prevent # links from moving to top
  85. $('a[href="#"][data-top!=true]').click(function(e){
  86. e.preventDefault();
  87. });
  88. //rich text editor
  89. $('.cleditor').cleditor();
  90. //datepicker
  91. $('.datepicker').datepicker();
  92. //notifications
  93. $('.noty').click(function(e){
  94. e.preventDefault();
  95. var options = $.parseJSON($(this).attr('data-noty-options'));
  96. noty(options);
  97. });
  98. //uniform - styler for checkbox, radio and file input
  99. $("input:checkbox, input:radio, input:file").not('[data-no-uniform="true"],#uniform-is-ajax').uniform();
  100. //chosen - improves select
  101. $('[data-rel="chosen"],[rel="chosen"]').chosen();
  102. //tabs
  103. $('#myTab a:first').tab('show');
  104. $('#myTab a').click(function (e) {
  105. e.preventDefault();
  106. $(this).tab('show');
  107. });
  108. //makes elements soratble, elements that sort need to have id attribute to save the result
  109. $('.sortable').sortable({
  110. revert:true,
  111. cancel:'.btn,.box-content,.nav-header',
  112. update:function(event,ui){
  113. //line below gives the ids of elements, you can make ajax call here to save it to the database
  114. //console.log($(this).sortable('toArray'));
  115. }
  116. });
  117. //slider
  118. $('.slider').slider({range:true,values:[10,65]});
  119. //tooltip
  120. $('[rel="tooltip"],[data-rel="tooltip"]').tooltip({"placement":"bottom",delay: { show: 400, hide: 200 }});
  121. //auto grow textarea
  122. $('textarea.autogrow').autogrow();
  123. //popover
  124. $('[rel="popover"],[data-rel="popover"]').popover();
  125. //file manager
  126. var elf = $('.file-manager').elfinder({
  127. url : 'misc/elfinder-connector/connector.php' // connector URL (REQUIRED)
  128. }).elfinder('instance');
  129. //iOS / iPhone style toggle switch
  130. $('.iphone-toggle').iphoneStyle();
  131. //star rating
  132. $('.raty').raty({
  133. score : 4 //default stars
  134. });
  135. //uploadify - multiple uploads
  136. $('#file_upload').uploadify({
  137. 'swf' : 'misc/uploadify.swf',
  138. 'uploader' : 'misc/uploadify.php'
  139. // Put your options here
  140. });
  141. //gallery controlls container animation
  142. $('ul.gallery li').hover(function(){
  143. $('img',this).fadeToggle(1000);
  144. $(this).find('.gallery-controls').remove();
  145. $(this).append('<div class="well gallery-controls">'+
  146. '<p><a href="#" class="gallery-edit btn"><i class="icon-edit"></i></a> <a href="#" class="gallery-delete btn"><i class="icon-remove"></i></a></p>'+
  147. '</div>');
  148. $(this).find('.gallery-controls').stop().animate({'margin-top':'-1'},400,'easeInQuint');
  149. },function(){
  150. $('img',this).fadeToggle(1000);
  151. $(this).find('.gallery-controls').stop().animate({'margin-top':'-30'},200,'easeInQuint',function(){
  152. $(this).remove();
  153. });
  154. });
  155. //gallery image controls example
  156. //gallery delete
  157. $('.thumbnails').on('click','.gallery-delete',function(e){
  158. e.preventDefault();
  159. //get image id
  160. //alert($(this).parents('.thumbnail').attr('id'));
  161. $(this).parents('.thumbnail').fadeOut();
  162. });
  163. //gallery edit
  164. $('.thumbnails').on('click','.gallery-edit',function(e){
  165. e.preventDefault();
  166. //get image id
  167. //alert($(this).parents('.thumbnail').attr('id'));
  168. });
  169. //gallery colorbox
  170. $('.thumbnail a').colorbox({rel:'thumbnail a', transition:"elastic", maxWidth:"95%", maxHeight:"95%"});
  171. //gallery fullscreen
  172. $('#toggle-fullscreen').button().click(function () {
  173. var button = $(this), root = document.documentElement;
  174. if (!button.hasClass('active')) {
  175. $('#thumbnails').addClass('modal-fullscreen');
  176. if (root.webkitRequestFullScreen) {
  177. root.webkitRequestFullScreen(
  178. window.Element.ALLOW_KEYBOARD_INPUT
  179. );
  180. } else if (root.mozRequestFullScreen) {
  181. root.mozRequestFullScreen();
  182. }
  183. } else {
  184. $('#thumbnails').removeClass('modal-fullscreen');
  185. (document.webkitCancelFullScreen ||
  186. document.mozCancelFullScreen ||
  187. $.noop).apply(document);
  188. }
  189. });
  190. //tour
  191. if($('.tour').length && typeof(tour)=='undefined')
  192. {
  193. var tour = new Tour();
  194. tour.addStep({
  195. element: ".span10:first", /* html element next to which the step popover should be shown */
  196. placement: "top",
  197. title: "Custom Tour", /* title of the popover */
  198. content: "You can create tour like this. Click Next." /* content of the popover */
  199. });
  200. tour.addStep({
  201. element: ".theme-container",
  202. placement: "left",
  203. title: "Themes",
  204. content: "You change your theme from here."
  205. });
  206. tour.addStep({
  207. element: "ul.main-menu a:first",
  208. title: "Dashboard",
  209. content: "This is your dashboard from here you will find highlights."
  210. });
  211. tour.addStep({
  212. element: "#for-is-ajax",
  213. title: "Ajax",
  214. content: "You can change if pages load with Ajax or not."
  215. });
  216. tour.addStep({
  217. element: ".top-nav a:first",
  218. placement: "bottom",
  219. title: "Visit Site",
  220. content: "Visit your front end from here."
  221. });
  222. tour.restart();
  223. }
  224. //datatable
  225. $('.datatable').dataTable({
  226. "sDom": "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'span12'i><'span12 center'p>>",
  227. "sPaginationType": "bootstrap",
  228. "oLanguage": {
  229. "sLengthMenu": "_MENU_ records per page"
  230. }
  231. } );
  232. $('.btn-close').click(function(e){
  233. e.preventDefault();
  234. $(this).parent().parent().parent().fadeOut();
  235. });
  236. $('.btn-minimize').click(function(e){
  237. e.preventDefault();
  238. var $target = $(this).parent().parent().next('.box-content');
  239. if($target.is(':visible')) $('i',$(this)).removeClass('icon-chevron-up').addClass('icon-chevron-down');
  240. else $('i',$(this)).removeClass('icon-chevron-down').addClass('icon-chevron-up');
  241. $target.slideToggle();
  242. });
  243. $('.btn-setting').click(function(e){
  244. e.preventDefault();
  245. $('#myModal').modal('show');
  246. });
  247. //initialize the external events for calender
  248. $('#external-events div.external-event').each(function() {
  249. // it doesn't need to have a start or end
  250. var eventObject = {
  251. title: $.trim($(this).text()) // use the element's text as the event title
  252. };
  253. // store the Event Object in the DOM element so we can get to it later
  254. $(this).data('eventObject', eventObject);
  255. // make the event draggable using jQuery UI
  256. $(this).draggable({
  257. zIndex: 999,
  258. revert: true, // will cause the event to go back to its
  259. revertDuration: 0 // original position after the drag
  260. });
  261. });
  262. //initialize the calendar
  263. $('#calendar').fullCalendar({
  264. header: {
  265. left: 'prev,next today',
  266. center: 'title',
  267. right: 'month,agendaWeek,agendaDay'
  268. },
  269. editable: true,
  270. droppable: true, // this allows things to be dropped onto the calendar !!!
  271. drop: function(date, allDay) { // this function is called when something is dropped
  272. // retrieve the dropped element's stored Event Object
  273. var originalEventObject = $(this).data('eventObject');
  274. // we need to copy it, so that multiple events don't have a reference to the same object
  275. var copiedEventObject = $.extend({}, originalEventObject);
  276. // assign it the date that was reported
  277. copiedEventObject.start = date;
  278. copiedEventObject.allDay = allDay;
  279. // render the event on the calendar
  280. // the last `true` argument determines if the event "sticks" (http://arshaw.com/fullcalendar/docs/event_rendering/renderEvent/)
  281. $('#calendar').fullCalendar('renderEvent', copiedEventObject, true);
  282. // is the "remove after drop" checkbox checked?
  283. if ($('#drop-remove').is(':checked')) {
  284. // if so, remove the element from the "Draggable Events" list
  285. $(this).remove();
  286. }
  287. }
  288. });
  289. //chart with points
  290. if($("#sincos").length)
  291. {
  292. var sin = [], cos = [];
  293. for (var i = 0; i < 14; i += 0.5) {
  294. sin.push([i, Math.sin(i)/i]);
  295. cos.push([i, Math.cos(i)]);
  296. }
  297. var plot = $.plot($("#sincos"),
  298. [ { data: sin, label: "sin(x)/x"}, { data: cos, label: "cos(x)" } ], {
  299. series: {
  300. lines: { show: true },
  301. points: { show: true }
  302. },
  303. grid: { hoverable: true, clickable: true, backgroundColor: { colors: ["#fff", "#eee"] } },
  304. yaxis: { min: -1.2, max: 1.2 },
  305. colors: ["#539F2E", "#3C67A5"]
  306. });
  307. function showTooltip(x, y, contents) {
  308. $('<div id="tooltip">' + contents + '</div>').css( {
  309. position: 'absolute',
  310. display: 'none',
  311. top: y + 5,
  312. left: x + 5,
  313. border: '1px solid #fdd',
  314. padding: '2px',
  315. 'background-color': '#dfeffc',
  316. opacity: 0.80
  317. }).appendTo("body").fadeIn(200);
  318. }
  319. var previousPoint = null;
  320. $("#sincos").bind("plothover", function (event, pos, item) {
  321. $("#x").text(pos.x.toFixed(2));
  322. $("#y").text(pos.y.toFixed(2));
  323. if (item) {
  324. if (previousPoint != item.dataIndex) {
  325. previousPoint = item.dataIndex;
  326. $("#tooltip").remove();
  327. var x = item.datapoint[0].toFixed(2),
  328. y = item.datapoint[1].toFixed(2);
  329. showTooltip(item.pageX, item.pageY,
  330. item.series.label + " of " + x + " = " + y);
  331. }
  332. }
  333. else {
  334. $("#tooltip").remove();
  335. previousPoint = null;
  336. }
  337. });
  338. $("#sincos").bind("plotclick", function (event, pos, item) {
  339. if (item) {
  340. $("#clickdata").text("You clicked point " + item.dataIndex + " in " + item.series.label + ".");
  341. plot.highlight(item.series, item.datapoint);
  342. }
  343. });
  344. }
  345. //flot chart
  346. if($("#flotchart").length)
  347. {
  348. var d1 = [];
  349. for (var i = 0; i < Math.PI * 2; i += 0.25)
  350. d1.push([i, Math.sin(i)]);
  351. var d2 = [];
  352. for (var i = 0; i < Math.PI * 2; i += 0.25)
  353. d2.push([i, Math.cos(i)]);
  354. var d3 = [];
  355. for (var i = 0; i < Math.PI * 2; i += 0.1)
  356. d3.push([i, Math.tan(i)]);
  357. $.plot($("#flotchart"), [
  358. { label: "sin(x)", data: d1},
  359. { label: "cos(x)", data: d2},
  360. { label: "tan(x)", data: d3}
  361. ], {
  362. series: {
  363. lines: { show: true },
  364. points: { show: true }
  365. },
  366. xaxis: {
  367. ticks: [0, [Math.PI/2, "\u03c0/2"], [Math.PI, "\u03c0"], [Math.PI * 3/2, "3\u03c0/2"], [Math.PI * 2, "2\u03c0"]]
  368. },
  369. yaxis: {
  370. ticks: 10,
  371. min: -2,
  372. max: 2
  373. },
  374. grid: {
  375. backgroundColor: { colors: ["#fff", "#eee"] }
  376. }
  377. });
  378. }
  379. //stack chart
  380. if($("#stackchart").length)
  381. {
  382. var d1 = [];
  383. for (var i = 0; i <= 10; i += 1)
  384. d1.push([i, parseInt(Math.random() * 30)]);
  385. var d2 = [];
  386. for (var i = 0; i <= 10; i += 1)
  387. d2.push([i, parseInt(Math.random() * 30)]);
  388. var d3 = [];
  389. for (var i = 0; i <= 10; i += 1)
  390. d3.push([i, parseInt(Math.random() * 30)]);
  391. var stack = 0, bars = true, lines = false, steps = false;
  392. function plotWithOptions() {
  393. $.plot($("#stackchart"), [ d1, d2, d3 ], {
  394. series: {
  395. stack: stack,
  396. lines: { show: lines, fill: true, steps: steps },
  397. bars: { show: bars, barWidth: 0.6 }
  398. }
  399. });
  400. }
  401. plotWithOptions();
  402. $(".stackControls input").click(function (e) {
  403. e.preventDefault();
  404. stack = $(this).val() == "With stacking" ? true : null;
  405. plotWithOptions();
  406. });
  407. $(".graphControls input").click(function (e) {
  408. e.preventDefault();
  409. bars = $(this).val().indexOf("Bars") != -1;
  410. lines = $(this).val().indexOf("Lines") != -1;
  411. steps = $(this).val().indexOf("steps") != -1;
  412. plotWithOptions();
  413. });
  414. }
  415. //pie chart
  416. var data = [
  417. { label: "Internet Explorer", data: 12},
  418. { label: "Mobile", data: 27},
  419. { label: "Safari", data: 85},
  420. { label: "Opera", data: 64},
  421. { label: "Firefox", data: 90},
  422. { label: "Chrome", data: 112}
  423. ];
  424. if($("#piechart").length)
  425. {
  426. $.plot($("#piechart"), data,
  427. {
  428. series: {
  429. pie: {
  430. show: true
  431. }
  432. },
  433. grid: {
  434. hoverable: true,
  435. clickable: true
  436. },
  437. legend: {
  438. show: false
  439. }
  440. });
  441. function pieHover(event, pos, obj)
  442. {
  443. if (!obj)
  444. return;
  445. percent = parseFloat(obj.series.percent).toFixed(2);
  446. $("#hover").html('<span style="font-weight: bold; color: '+obj.series.color+'">'+obj.series.label+' ('+percent+'%)</span>');
  447. }
  448. $("#piechart").bind("plothover", pieHover);
  449. }
  450. //donut chart
  451. if($("#donutchart").length)
  452. {
  453. $.plot($("#donutchart"), data,
  454. {
  455. series: {
  456. pie: {
  457. innerRadius: 0.5,
  458. show: true
  459. }
  460. },
  461. legend: {
  462. show: false
  463. }
  464. });
  465. }
  466. // we use an inline data source in the example, usually data would
  467. // be fetched from a server
  468. var data = [], totalPoints = 300;
  469. function getRandomData() {
  470. if (data.length > 0)
  471. data = data.slice(1);
  472. // do a random walk
  473. while (data.length < totalPoints) {
  474. var prev = data.length > 0 ? data[data.length - 1] : 50;
  475. var y = prev + Math.random() * 10 - 5;
  476. if (y < 0)
  477. y = 0;
  478. if (y > 100)
  479. y = 100;
  480. data.push(y);
  481. }
  482. // zip the generated y values with the x values
  483. var res = [];
  484. for (var i = 0; i < data.length; ++i)
  485. res.push([i, data[i]])
  486. return res;
  487. }
  488. // setup control widget
  489. var updateInterval = 30;
  490. $("#updateInterval").val(updateInterval).change(function () {
  491. var v = $(this).val();
  492. if (v && !isNaN(+v)) {
  493. updateInterval = +v;
  494. if (updateInterval < 1)
  495. updateInterval = 1;
  496. if (updateInterval > 2000)
  497. updateInterval = 2000;
  498. $(this).val("" + updateInterval);
  499. }
  500. });
  501. //realtime chart
  502. if($("#realtimechart").length)
  503. {
  504. var options = {
  505. series: { shadowSize: 1 }, // drawing is faster without shadows
  506. yaxis: { min: 0, max: 100 },
  507. xaxis: { show: false }
  508. };
  509. var plot = $.plot($("#realtimechart"), [ getRandomData() ], options);
  510. function update() {
  511. plot.setData([ getRandomData() ]);
  512. // since the axes don't change, we don't need to call plot.setupGrid()
  513. plot.draw();
  514. setTimeout(update, updateInterval);
  515. }
  516. update();
  517. }
  518. }
  519. //additional functions for data table
  520. $.fn.dataTableExt.oApi.fnPagingInfo = function ( oSettings )
  521. {
  522. return {
  523. "iStart": oSettings._iDisplayStart,
  524. "iEnd": oSettings.fnDisplayEnd(),
  525. "iLength": oSettings._iDisplayLength,
  526. "iTotal": oSettings.fnRecordsTotal(),
  527. "iFilteredTotal": oSettings.fnRecordsDisplay(),
  528. "iPage": Math.ceil( oSettings._iDisplayStart / oSettings._iDisplayLength ),
  529. "iTotalPages": Math.ceil( oSettings.fnRecordsDisplay() / oSettings._iDisplayLength )
  530. };
  531. }
  532. $.extend( $.fn.dataTableExt.oPagination, {
  533. "bootstrap": {
  534. "fnInit": function( oSettings, nPaging, fnDraw ) {
  535. var oLang = oSettings.oLanguage.oPaginate;
  536. var fnClickHandler = function ( e ) {
  537. e.preventDefault();
  538. if ( oSettings.oApi._fnPageChange(oSettings, e.data.action) ) {
  539. fnDraw( oSettings );
  540. }
  541. };
  542. $(nPaging).addClass('pagination').append(
  543. '<ul>'+
  544. '<li class="prev disabled"><a href="#">&larr; '+oLang.sPrevious+'</a></li>'+
  545. '<li class="next disabled"><a href="#">'+oLang.sNext+' &rarr; </a></li>'+
  546. '</ul>'
  547. );
  548. var els = $('a', nPaging);
  549. $(els[0]).bind( 'click.DT', { action: "previous" }, fnClickHandler );
  550. $(els[1]).bind( 'click.DT', { action: "next" }, fnClickHandler );
  551. },
  552. "fnUpdate": function ( oSettings, fnDraw ) {
  553. var iListLength = 5;
  554. var oPaging = oSettings.oInstance.fnPagingInfo();
  555. var an = oSettings.aanFeatures.p;
  556. var i, j, sClass, iStart, iEnd, iHalf=Math.floor(iListLength/2);
  557. if ( oPaging.iTotalPages < iListLength) {
  558. iStart = 1;
  559. iEnd = oPaging.iTotalPages;
  560. }
  561. else if ( oPaging.iPage <= iHalf ) {
  562. iStart = 1;
  563. iEnd = iListLength;
  564. } else if ( oPaging.iPage >= (oPaging.iTotalPages-iHalf) ) {
  565. iStart = oPaging.iTotalPages - iListLength + 1;
  566. iEnd = oPaging.iTotalPages;
  567. } else {
  568. iStart = oPaging.iPage - iHalf + 1;
  569. iEnd = iStart + iListLength - 1;
  570. }
  571. for ( i=0, iLen=an.length ; i<iLen ; i++ ) {
  572. // remove the middle elements
  573. $('li:gt(0)', an[i]).filter(':not(:last)').remove();
  574. // add the new list items and their event handlers
  575. for ( j=iStart ; j<=iEnd ; j++ ) {
  576. sClass = (j==oPaging.iPage+1) ? 'class="active"' : '';
  577. $('<li '+sClass+'><a href="#">'+j+'</a></li>')
  578. .insertBefore( $('li:last', an[i])[0] )
  579. .bind('click', function (e) {
  580. e.preventDefault();
  581. oSettings._iDisplayStart = (parseInt($('a', this).text(),10)-1) * oPaging.iLength;
  582. fnDraw( oSettings );
  583. } );
  584. }
  585. // add / remove disabled classes from the static elements
  586. if ( oPaging.iPage === 0 ) {
  587. $('li:first', an[i]).addClass('disabled');
  588. } else {
  589. $('li:first', an[i]).removeClass('disabled');
  590. }
  591. if ( oPaging.iPage === oPaging.iTotalPages-1 || oPaging.iTotalPages === 0 ) {
  592. $('li:last', an[i]).addClass('disabled');
  593. } else {
  594. $('li:last', an[i]).removeClass('disabled');
  595. }
  596. }
  597. }
  598. }
  599. });