PageRenderTime 45ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/public/js/custom.js

https://github.com/Mark1988huang/ninjafund
JavaScript | 936 lines | 680 code | 197 blank | 59 comment | 45 complexity | 52b414202c03c7c579c17a8476b7c42f MD5 | raw file
  1. $(function() {
  2. //===== Form to Wizard plugin =====//
  3. $("#wizForm").formwizard({
  4. formPluginEnabled: false,
  5. validationEnabled: true,
  6. focusFirstInput : false,
  7. formOptions :{
  8. success: function(data){$("#status").fadeTo(500,1,function(){ $(this).html("You are now registered!").fadeTo(5000, 0); })},
  9. beforeSubmit: function(data){$("#data").html("data sent to the server: " + $.param(data));},
  10. dataType: 'json',
  11. resetForm: true
  12. },
  13. disableUIStyles : true,
  14. validationOptions : {
  15. rules: {
  16. req: "required",
  17. sel: "required",
  18. chb: "required",
  19. email: {
  20. required: true,
  21. email: true
  22. }
  23. },
  24. messages: {
  25. req: "This field is required",
  26. sel: "Oops, required!",
  27. chb: "Check it",
  28. email: {
  29. required: "Please specify your email",
  30. email: "Correct format is name@domain.com"
  31. }
  32. }
  33. }
  34. }
  35. );
  36. //===== UI dialog =====//
  37. $( "#dialog-message" ).dialog({
  38. autoOpen: false,
  39. modal: true,
  40. buttons: {
  41. Ok: function() {
  42. $( this ).dialog( "close" );
  43. }
  44. }
  45. });
  46. $( "#opener" ).click(function() {
  47. $( "#dialog-message" ).dialog( "open" );
  48. return false;
  49. });
  50. //===== PrettyPhoto lightbox plugin =====//
  51. $("a[rel^='prettyPhoto']").prettyPhoto();
  52. //===== Custom single file input =====//
  53. $("input.fileInput").filestyle({
  54. imageheight : 26,
  55. imagewidth : 89,
  56. width : 292
  57. });
  58. //===== Dual select boxes =====//
  59. $.configureBoxes();
  60. //===== Time picker =====//
  61. $('.timepicker').timeEntry({
  62. show24Hours: true, // 24 hours format
  63. showSeconds: true, // Show seconds?
  64. spinnerImage: 'images/ui/spinnerUpDown.png', // Arrows image
  65. spinnerSize: [17, 26, 0], // Image size
  66. spinnerIncDecOnly: true // Only up and down arrows
  67. });
  68. //===== Wizard =====//
  69. $('.wizard').smartWizard({
  70. selected: 0, // Selected Step, 0 = first step
  71. keyNavigation: true, // Enable/Disable key navigation(left and right keys are used if enabled)
  72. enableAllSteps: false, // Enable/Disable all steps on first load
  73. transitionEffect: 'slideleft', // Effect on navigation, none/fade/slide/slideleft
  74. contentURL:null, // specifying content url enables ajax content loading
  75. contentCache:true, // cache step contents, if false content is fetched always from ajax url
  76. cycleSteps: false, // cycle step navigation
  77. enableFinishButton: false, // makes finish button enabled always
  78. errorSteps:[], // array of step numbers to highlighting as error steps
  79. labelNext:'Next', // label for Next button
  80. labelPrevious:'Previous', // label for Previous button
  81. labelFinish:'Finish', // label for Finish button
  82. // Events
  83. onLeaveStep: null, // triggers when leaving a step
  84. onShowStep: null, // triggers when showing a step
  85. onFinish: null // triggers when Finish button is clicked
  86. });
  87. //===== File manager =====//
  88. $('#fileManager').elfinder({
  89. url : 'php/connector.php',
  90. })
  91. //===== Alert windows =====//
  92. $(".bAlert").click( function() {
  93. jAlert('This is a custom alert box. Title and this text can be easily editted', 'Alert Dialog Sample');
  94. });
  95. $(".bConfirm").click( function() {
  96. jConfirm('Can you confirm this?', 'Confirmation Dialog', function(r) {
  97. jAlert('Confirmed: ' + r, 'Confirmation Results');
  98. });
  99. });
  100. $(".bPromt").click( function() {
  101. jPrompt('Type something:', 'Prefilled value', 'Prompt Dialog', function(r) {
  102. if( r ) alert('You entered ' + r);
  103. });
  104. });
  105. $(".bHtml").click( function() {
  106. jAlert('You can use HTML, such as <strong>bold</strong>, <em>italics</em>, and <u>underline</u>!');
  107. });
  108. //===== Accordion =====//
  109. $('div.menu_body:eq(0)').show();
  110. $('.acc .head:eq(0)').show().css({color:"#2B6893"});
  111. $(".acc .head").click(function() {
  112. $(this).css({color:"#2B6893"}).next("div.menu_body").slideToggle(300).siblings("div.menu_body").slideUp("slow");
  113. $(this).siblings().css({color:"#404040"});
  114. });
  115. //===== WYSIWYG editor =====//
  116. $('.wysiwyg').wysiwyg({
  117. iFrameClass: "wysiwyg-input",
  118. controls: {
  119. bold : { visible : true },
  120. italic : { visible : true },
  121. underline : { visible : true },
  122. strikeThrough : { visible : false },
  123. justifyLeft : { visible : true },
  124. justifyCenter : { visible : true },
  125. justifyRight : { visible : true },
  126. justifyFull : { visible : true },
  127. indent : { visible : true },
  128. outdent : { visible : true },
  129. subscript : { visible : false },
  130. superscript : { visible : false },
  131. undo : { visible : true },
  132. redo : { visible : true },
  133. insertOrderedList : { visible : true },
  134. insertUnorderedList : { visible : true },
  135. insertHorizontalRule : { visible : false },
  136. h1: {
  137. visible: true,
  138. className: 'h1',
  139. command: ($.browser.msie || $.browser.safari) ? 'formatBlock' : 'heading',
  140. arguments: ($.browser.msie || $.browser.safari) ? '<h1>' : 'h1',
  141. tags: ['h1'],
  142. tooltip: 'Header 1'
  143. },
  144. h2: {
  145. visible: true,
  146. className: 'h2',
  147. command: ($.browser.msie || $.browser.safari) ? 'formatBlock' : 'heading',
  148. arguments: ($.browser.msie || $.browser.safari) ? '<h2>' : 'h2',
  149. tags: ['h2'],
  150. tooltip: 'Header 2'
  151. },
  152. h3: {
  153. visible: true,
  154. className: 'h3',
  155. command: ($.browser.msie || $.browser.safari) ? 'formatBlock' : 'heading',
  156. arguments: ($.browser.msie || $.browser.safari) ? '<h3>' : 'h3',
  157. tags: ['h3'],
  158. tooltip: 'Header 3'
  159. },
  160. h4: {
  161. visible: true,
  162. className: 'h4',
  163. command: ($.browser.msie || $.browser.safari) ? 'formatBlock' : 'heading',
  164. arguments: ($.browser.msie || $.browser.safari) ? '<h4>' : 'h4',
  165. tags: ['h4'],
  166. tooltip: 'Header 4'
  167. },
  168. h5: {
  169. visible: true,
  170. className: 'h5',
  171. command: ($.browser.msie || $.browser.safari) ? 'formatBlock' : 'heading',
  172. arguments: ($.browser.msie || $.browser.safari) ? '<h5>' : 'h5',
  173. tags: ['h5'],
  174. tooltip: 'Header 5'
  175. },
  176. h6: {
  177. visible: true,
  178. className: 'h6',
  179. command: ($.browser.msie || $.browser.safari) ? 'formatBlock' : 'heading',
  180. arguments: ($.browser.msie || $.browser.safari) ? '<h6>' : 'h6',
  181. tags: ['h6'],
  182. tooltip: 'Header 6'
  183. },
  184. cut : { visible : true },
  185. copy : { visible : true },
  186. paste : { visible : true },
  187. html : { visible: true },
  188. increaseFontSize : { visible : false },
  189. decreaseFontSize : { visible : false },
  190. },
  191. events: {
  192. click: function(event) {
  193. if ($("#click-inform:checked").length > 0) {
  194. event.preventDefault();
  195. alert("You have clicked jWysiwyg content!");
  196. }
  197. }
  198. }
  199. });
  200. //$('.wysiwyg').wysiwyg("insertHtml", "Sample code");
  201. //===== ToTop =====//
  202. $().UItoTop({ easingType: 'easeOutQuart' });
  203. //===== Spinner options =====//
  204. var itemList = [
  205. {url: "http://ejohn.org", title: "John Resig"},
  206. {url: "http://bassistance.de/", title: "J&ouml;rn Zaefferer"},
  207. {url: "http://snook.ca/jonathan/", title: "Jonathan Snook"},
  208. {url: "http://rdworth.org/", title: "Richard Worth"},
  209. {url: "http://www.paulbakaus.com/", title: "Paul Bakaus"},
  210. {url: "http://www.yehudakatz.com/", title: "Yehuda Katz"},
  211. {url: "http://www.azarask.in/", title: "Aza Raskin"},
  212. {url: "http://www.karlswedberg.com/", title: "Karl Swedberg"},
  213. {url: "http://scottjehl.com/", title: "Scott Jehl"},
  214. {url: "http://jdsharp.us/", title: "Jonathan Sharp"},
  215. {url: "http://www.kevinhoyt.org/", title: "Kevin Hoyt"},
  216. {url: "http://www.codylindley.com/", title: "Cody Lindley"},
  217. {url: "http://malsup.com/jquery/", title: "Mike Alsup"}
  218. ];
  219. var opts = {
  220. 's1': {decimals:2},
  221. 's2': {stepping: 0.25},
  222. 's3': {currency: '$'},
  223. 's4': {},
  224. 's5': {
  225. //
  226. // Two methods of adding external items to the spinner
  227. //
  228. // method 1: on initalisation call the add method directly and format html manually
  229. init: function(e, ui) {
  230. for (var i=0; i<itemList.length; i++) {
  231. ui.add('<a href="'+ itemList[i].url +'" target="_blank">'+ itemList[i].title +'</a>');
  232. }
  233. },
  234. // method 2: use the format and items options in combination
  235. format: '<a href="%(url)" target="_blank">%(title)</a>',
  236. items: itemList
  237. }
  238. };
  239. for (var n in opts)
  240. $("#"+n).spinner(opts[n]);
  241. $("button").click(function(e){
  242. var ns = $(this).attr('id').match(/(s\d)\-(\w+)$/);
  243. if (ns != null)
  244. $('#'+ns[1]).spinner( (ns[2] == 'create') ? opts[ns[1]] : ns[2]);
  245. });
  246. //===== Contacts list =====//
  247. $('#myList').listnav({
  248. initLetter: 'a',
  249. includeAll: true,
  250. includeOther: true,
  251. flagDisabled: true,
  252. noMatchText: 'Nothing matched your filter, please click another letter.',
  253. prefixes: ['the','a'] ,
  254. });
  255. //===== ShowCode plugin for <pre> tag =====//
  256. $('.showCode').sourcerer('js html css php'); // Display all languages
  257. $('.showCodeJS').sourcerer('js'); // Display JS only
  258. $('.showCodeHTML').sourcerer('html'); // Display HTML only
  259. $('.showCodePHP').sourcerer('php'); // Display PHP only
  260. $('.showCodeCSS').sourcerer('css'); // Display CSS only
  261. //===== Calendar =====//
  262. var date = new Date();
  263. var d = date.getDate();
  264. var m = date.getMonth();
  265. var y = date.getFullYear();
  266. $('#calendar').fullCalendar({
  267. header: {
  268. left: 'prev,next',
  269. center: 'title',
  270. right: 'month,basicWeek,basicDay'
  271. },
  272. editable: true,
  273. events: [
  274. {
  275. title: 'All day event',
  276. start: new Date(y, m, 1)
  277. },
  278. {
  279. title: 'Long event',
  280. start: new Date(y, m, 5),
  281. end: new Date(y, m, 8)
  282. },
  283. {
  284. id: 999,
  285. title: 'Repeating event',
  286. start: new Date(y, m, 2, 16, 0),
  287. end: new Date(y, m, 3, 18, 0),
  288. allDay: false
  289. },
  290. {
  291. id: 999,
  292. title: 'Repeating event',
  293. start: new Date(y, m, 9, 16, 0),
  294. end: new Date(y, m, 10, 18, 0),
  295. allDay: false
  296. },
  297. {
  298. title: 'Actually any color could be applied for background',
  299. start: new Date(y, m, 30, 10, 30),
  300. end: new Date(y, m, d+1, 14, 0),
  301. allDay: false,
  302. color: '#B55D5C'
  303. },
  304. {
  305. title: 'Lunch',
  306. start: new Date(y, m, 14, 12, 0),
  307. end: new Date(y, m, 15, 14, 0),
  308. allDay: false
  309. },
  310. {
  311. title: 'Birthday PARTY',
  312. start: new Date(y, m, 18),
  313. end: new Date(y, m, 20),
  314. allDay: false
  315. },
  316. {
  317. title: 'Click for Google',
  318. start: new Date(y, m, 27),
  319. end: new Date(y, m, 29),
  320. url: 'http://google.com/'
  321. }
  322. ]
  323. });
  324. //===== Dynamic data table =====//
  325. oTable = $('#example').dataTable({
  326. "bJQueryUI": true,
  327. "sPaginationType": "full_numbers",
  328. "sDom": '<""f>t<"F"lp>'
  329. });
  330. //===== Form elements styling =====//
  331. $("select, input:checkbox, input:radio").uniform();
  332. //===== Form validation engine =====//
  333. $("#valid").validationEngine();
  334. //===== Datepickers =====//
  335. $( ".datepicker" ).datepicker({
  336. defaultDate: +7,
  337. autoSize: true,
  338. appendText: '(dd-mm-yyyy)',
  339. dateFormat: 'dd-mm-yy',
  340. });
  341. $( ".datepickerInline" ).datepicker({
  342. defaultDate: +7,
  343. autoSize: true,
  344. appendText: '(dd-mm-yyyy)',
  345. dateFormat: 'dd-mm-yy',
  346. numberOfMonths: 1
  347. });
  348. //===== Progressbar (Jquery UI) =====//
  349. $( "#progressbar" ).progressbar({
  350. value: 37
  351. });
  352. //===== Tooltip =====//
  353. $('.leftDir').tipsy({fade: true, gravity: 'e'});
  354. $('.rightDir').tipsy({fade: true, gravity: 'w'});
  355. $('.topDir').tipsy({fade: true, gravity: 's'});
  356. $('.botDir').tipsy({fade: true, gravity: 'n'});
  357. //===== Information boxes =====//
  358. $(".hideit").click(function() {
  359. $(this).fadeOut(400);
  360. });
  361. //=====Resizable table columns =====//
  362. var onSampleResized = function(e){
  363. var columns = $(e.currentTarget).find("th");
  364. var msg = "columns widths: ";
  365. columns.each(function(){ msg += $(this).width() + "px; "; })
  366. };
  367. $(".resize").colResizable({
  368. liveDrag:true,
  369. gripInnerHtml:"<div class='grip'></div>",
  370. draggingClass:"dragging",
  371. onResize:onSampleResized});
  372. //===== Left navigation submenu animation =====//
  373. $("ul.sub li a").hover(function() {
  374. $(this).stop().animate({ color: "#3a6fa5" }, 400);
  375. },function() {
  376. $(this).stop().animate({ color: "#494949" }, 400);
  377. });
  378. //===== Image gallery control buttons =====//
  379. $(".pics ul li").hover(
  380. function() { $(this).children(".actions").show("fade", 200); },
  381. function() { $(this).children(".actions").hide("fade", 200); }
  382. );
  383. //===== Color picker =====//
  384. $('#colorpickerField').ColorPicker({
  385. onSubmit: function(hsb, hex, rgb, el) {
  386. $(el).val(hex);
  387. $(el).ColorPickerHide();
  388. },
  389. onBeforeShow: function () {
  390. $(this).ColorPickerSetColor(this.value);
  391. }
  392. })
  393. .bind('keyup', function(){
  394. $(this).ColorPickerSetColor(this.value);
  395. });
  396. //===== Autogrowing textarea =====//
  397. $(".auto").autoGrow();
  398. //===== Autotabs. Inline data rows =====//
  399. $('.onlyNums input').autotab_magic().autotab_filter('numeric');
  400. $('.onlyText input').autotab_magic().autotab_filter('text');
  401. $('.onlyAlpha input').autotab_magic().autotab_filter('alpha');
  402. $('.onlyRegex input').autotab_magic().autotab_filter({ format: 'custom', pattern: '[^0-9\.]' });
  403. $('.allUpper input').autotab_magic().autotab_filter({ format: 'alphanumeric', uppercase: true });
  404. //===== jQuery UI sliders =====//
  405. $( ".uiSlider" ).slider();
  406. $( ".uiSliderInc" ).slider({
  407. value:100,
  408. min: 0,
  409. max: 500,
  410. step: 50,
  411. slide: function( event, ui ) {
  412. $( "#amount" ).val( "$" + ui.value );
  413. }
  414. });
  415. $( "#amount" ).val( "$" + $( ".uiSliderInc" ).slider( "value" ) );
  416. $( ".uiRangeSlider" ).slider({
  417. range: true,
  418. min: 0,
  419. max: 500,
  420. values: [ 75, 300 ],
  421. slide: function( event, ui ) {
  422. $( "#rangeAmount" ).val( "$" + ui.values[ 0 ] + " - $" + ui.values[ 1 ] );
  423. }
  424. });
  425. $( "#rangeAmount" ).val( "$" + $( ".uiRangeSlider" ).slider( "values", 0 ) +" - $" + $( ".uiRangeSlider" ).slider( "values", 1 ));
  426. $( ".uiMinRange" ).slider({
  427. range: "min",
  428. value: 37,
  429. min: 1,
  430. max: 700,
  431. slide: function( event, ui ) {
  432. $( "#minRangeAmount" ).val( "$" + ui.value );
  433. }
  434. });
  435. $( "#minRangeAmount" ).val( "$" + $( ".uiMinRange" ).slider( "value" ) );
  436. $( ".uiMaxRange" ).slider({
  437. range: "max",
  438. min: 1,
  439. max: 100,
  440. value: 20,
  441. slide: function( event, ui ) {
  442. $( "#maxRangeAmount" ).val( ui.value );
  443. }
  444. });
  445. $( "#maxRangeAmount" ).val( $( ".uiMaxRange" ).slider( "value" ) );
  446. $( "#eq > span" ).each(function() {
  447. // read initial values from markup and remove that
  448. var value = parseInt( $( this ).text(), 10 );
  449. $( this ).empty().slider({
  450. value: value,
  451. range: "min",
  452. animate: true,
  453. orientation: "vertical"
  454. });
  455. });
  456. //===== Breadcrumbs =====//
  457. $("#breadCrumb").jBreadCrumb();
  458. //===== Autofocus =====//
  459. $('.autoF').focus();
  460. //===== Tabs =====//
  461. $.fn.simpleTabs = function(){
  462. //Default Action
  463. $(this).find(".tab_content").hide(); //Hide all content
  464. $(this).find("ul.tabs li:first").addClass("activeTab").show(); //Activate first tab
  465. $(this).find(".tab_content:first").show(); //Show first tab content
  466. //On Click Event
  467. $("ul.tabs li").click(function() {
  468. $(this).parent().parent().find("ul.tabs li").removeClass("activeTab"); //Remove any "active" class
  469. $(this).addClass("activeTab"); //Add "active" class to selected tab
  470. $(this).parent().parent().find(".tab_content").hide(); //Hide all tab content
  471. var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
  472. $(activeTab).show(); //Fade in the active content
  473. return false;
  474. });
  475. };//end function
  476. $("div[class^='widget']").simpleTabs(); //Run function on any div with class name of "Simple Tabs"
  477. //===== Placeholder for all browsers =====//
  478. $("input").each(
  479. function(){
  480. if($(this).val()=="" && $(this).attr("placeholder")!=""){
  481. $(this).val($(this).attr("placeholder"));
  482. $(this).focus(function(){
  483. if($(this).val()==$(this).attr("placeholder")) $(this).val("");
  484. });
  485. $(this).blur(function(){
  486. if($(this).val()=="") $(this).val($(this).attr("placeholder"));
  487. });
  488. }
  489. });
  490. //===== User nav dropdown =====//
  491. $('.dd').click(function () {
  492. $('ul.menu_body').slideToggle(100);
  493. });
  494. $(document).bind('click', function(e) {
  495. var $clicked = $(e.target);
  496. if (! $clicked.parents().hasClass("dd"))
  497. $("ul.menu_body").hide(10);
  498. });
  499. $('.acts').click(function () {
  500. $('ul.actsBody').slideToggle(100);
  501. });
  502. //===== Collapsible elements management =====//
  503. $('.exp').collapsible({
  504. defaultOpen: 'current',
  505. cookieName: 'navAct',
  506. cssOpen: 'active',
  507. cssClose: 'inactive',
  508. speed: 300
  509. });
  510. $('.opened').collapsible({
  511. defaultOpen: 'opened,toggleOpened',
  512. cssOpen: 'inactive',
  513. cssClose: 'normal',
  514. speed: 200
  515. });
  516. $('.closed').collapsible({
  517. defaultOpen: '',
  518. cssOpen: 'inactive',
  519. cssClose: 'normal',
  520. speed: 200
  521. });
  522. //===== Flot settings. You can place your own flot settings here =====//
  523. /* Lines */
  524. $(function () {
  525. var sin = [], cos = [];
  526. for (var i = 0; i < 10; i += 0.5) {
  527. sin.push([i, Math.sin(i)]);
  528. cos.push([i, Math.cos(i)]);
  529. }
  530. var plot = $.plot($(".chart"),
  531. [ { data: sin, label: "sin(x)"}, { data: cos, label: "cos(x)" } ], {
  532. series: {
  533. lines: { show: true },
  534. points: { show: true }
  535. },
  536. grid: { hoverable: true, clickable: true },
  537. yaxis: { min: -1.1, max: 1.1 },
  538. xaxis: { min: 0, max: 9 }
  539. });
  540. function showTooltip(x, y, contents) {
  541. $('<div id="tooltip">' + contents + '</div>').css( {
  542. position: 'absolute',
  543. display: 'none',
  544. top: y + 5,
  545. left: x + 5,
  546. border: '1px solid #000',
  547. padding: '2px',
  548. 'z-index': '9999',
  549. 'background-color': '#202020',
  550. 'color': '#fff',
  551. 'font-size': '11px',
  552. opacity: 0.8
  553. }).appendTo("body").fadeIn(200);
  554. }
  555. var previousPoint = null;
  556. $(".chart").bind("plothover", function (event, pos, item) {
  557. $("#x").text(pos.x.toFixed(2));
  558. $("#y").text(pos.y.toFixed(2));
  559. if ($("#enableTooltip:checked").length > 0) {
  560. if (item) {
  561. if (previousPoint != item.dataIndex) {
  562. previousPoint = item.dataIndex;
  563. $("#tooltip").remove();
  564. var x = item.datapoint[0].toFixed(2),
  565. y = item.datapoint[1].toFixed(2);
  566. showTooltip(item.pageX, item.pageY,
  567. item.series.label + " of " + x + " = " + y);
  568. }
  569. }
  570. else {
  571. $("#tooltip").remove();
  572. previousPoint = null;
  573. }
  574. }
  575. });
  576. $(".chart").bind("plotclick", function (event, pos, item) {
  577. if (item) {
  578. $("#clickdata").text("You clicked point " + item.dataIndex + " in " + item.series.label + ".");
  579. plot.highlight(item.series, item.datapoint);
  580. }
  581. });
  582. });
  583. /* Lines with autodrowing */
  584. $(function () {
  585. // we use an inline data source in the example, usually data would
  586. // be fetched from a server
  587. var data = [], totalPoints = 200;
  588. function getRandomData() {
  589. if (data.length > 0)
  590. data = data.slice(1);
  591. // do a random walk
  592. while (data.length < totalPoints) {
  593. var prev = data.length > 0 ? data[data.length - 1] : 50;
  594. var y = prev + Math.random() * 10 - 5;
  595. if (y < 0)
  596. y = 0;
  597. if (y > 100)
  598. y = 100;
  599. data.push(y);
  600. }
  601. // zip the generated y values with the x values
  602. var res = [];
  603. for (var i = 0; i < data.length; ++i)
  604. res.push([i, data[i]])
  605. return res;
  606. }
  607. // setup control widget
  608. var updateInterval = 1000;
  609. $("#updateInterval").val(updateInterval).change(function () {
  610. var v = $(this).val();
  611. if (v && !isNaN(+v)) {
  612. updateInterval = +v;
  613. if (updateInterval < 1)
  614. updateInterval = 1;
  615. if (updateInterval > 2000)
  616. updateInterval = 2000;
  617. $(this).val("" + updateInterval);
  618. }
  619. });
  620. // setup plot
  621. var options = {
  622. yaxis: { min: 0, max: 100 },
  623. xaxis: { min: 0, max: 100 },
  624. colors: ["#afd8f8"],
  625. series: {
  626. lines: {
  627. lineWidth: 2,
  628. fill: true,
  629. fillColor: { colors: [ { opacity: 0.6 }, { opacity: 0.2 } ] },
  630. //"#dcecf9"
  631. steps: false
  632. }
  633. }
  634. };
  635. var plot = $.plot($(".autoUpdate"), [ getRandomData() ], options);
  636. function update() {
  637. plot.setData([ getRandomData() ]);
  638. // since the axes don't change, we don't need to call plot.setupGrid()
  639. plot.draw();
  640. setTimeout(update, updateInterval);
  641. }
  642. update();
  643. });
  644. /* Bars */
  645. $(function () {
  646. var d2 = [[0.6, 29], [2.6, 13], [4.6, 46], [6.6, 30], [8.6, 48], [10.6, 22], [12.6, 40], [14.6, 32], [16.6, 39], [18.6, 16], [20.6, 27], [22.6, 22], [24.6, 2], [26.6, 45], [28.6, 23], [30.6, 28], [32.6, 30], [34.6, 40], [36.6, 20], [38.6, 47], [40.6, 12], [42.6, 49], [44.6, 28], [46.6, 15], [48.6, 24]];
  647. var plot = $.plot($(".bars"),
  648. [ { data: d2} ], {
  649. series: {
  650. bars: {
  651. show: true,
  652. lineWidth: 0.5,
  653. barWidth: 0.85,
  654. fill: true,
  655. fillColor: { colors: [ { opacity: 0.8 }, { opacity: 1 } ] },
  656. align: "left",
  657. horizontal: false,
  658. },
  659. },
  660. grid: { hoverable: true, clickable: true },
  661. yaxis: { min: 0, max: 50 },
  662. xaxis: { min: 0, max: 50 },
  663. });
  664. });
  665. /* Pie charts */
  666. $(function () {
  667. var data = [];
  668. var series = Math.floor(Math.random()*10)+1;
  669. for( var i = 0; i<series; i++)
  670. {
  671. data[i] = { label: "Series"+(i+1), data: Math.floor(Math.random()*100)+1 }
  672. }
  673. $.plot($("#graph1"), data,
  674. {
  675. series: {
  676. pie: {
  677. show: true,
  678. radius: 1,
  679. label: {
  680. show: true,
  681. radius: 2/3,
  682. formatter: function(label, series){
  683. return '<div style="font-size:11px;text-align:center;padding:2px;color:white;">'+label+'<br/>'+Math.round(series.percent)+'%</div>';
  684. },
  685. threshold: 0.1
  686. }
  687. }
  688. },
  689. legend: {
  690. show: false
  691. },
  692. grid: {
  693. hoverable: false,
  694. clickable: true
  695. },
  696. });
  697. $("#interactive").bind("plothover", pieHover);
  698. $("#interactive").bind("plotclick", pieClick);
  699. $.plot($("#graph2"), data,
  700. {
  701. series: {
  702. pie: {
  703. show: true,
  704. radius:300,
  705. label: {
  706. show: true,
  707. formatter: function(label, series){
  708. return '<div style="font-size:11px;text-align:center;padding:2px;color:white;">'+label+'<br/>'+Math.round(series.percent)+'%</div>';
  709. },
  710. threshold: 0.1
  711. }
  712. }
  713. },
  714. legend: {
  715. show: false
  716. },
  717. grid: {
  718. hoverable: false,
  719. clickable: true
  720. }
  721. });
  722. $("#interactive").bind("plothover", pieHover);
  723. $("#interactive").bind("plotclick", pieClick);
  724. });
  725. function pieHover(event, pos, obj)
  726. {
  727. if (!obj)
  728. return;
  729. percent = parseFloat(obj.series.percent).toFixed(2);
  730. $("#hover").html('<span style="font-weight: bold; color: '+obj.series.color+'">'+obj.series.label+' ('+percent+'%)</span>');
  731. }
  732. function pieClick(event, pos, obj)
  733. {
  734. if (!obj)
  735. return;
  736. percent = parseFloat(obj.series.percent).toFixed(2);
  737. alert(''+obj.series.label+': '+percent+'%');
  738. }
  739. });