Advertisement
Guest User

Untitled

a guest
Apr 30th, 2011
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $(document).ready(function() {
  2.     // Setup the buttons to call our new Alert/Prompt/Confirm methods
  3.     $('#alert').click(function() {
  4.         Alert('Custom alert() functions are cool.');
  5.     });
  6.     $('#prompt').click(function() {
  7.         Prompt('How would you describe qTip2?', 'Awesome!', function(response) {
  8.             // do something with response
  9.         });
  10.     });
  11.     $('#confirm').click(function() {
  12.         Confirm('Click Ok if you love qTip2', function(yes) {
  13.             // do something with yes
  14.         });
  15.     });
  16.      
  17.     $('#modal').qtip({
  18.         id: 'modalwindow', // Since we're only creating one modal, give it an ID so we can style it
  19.         content: {
  20.             text: $('div#modalwindow'),
  21.             title: {
  22.                 text: 'Modal qTip',
  23.                 button: true
  24.             }
  25.         },
  26.         position: {
  27.             my: 'center', // ...at the center of the viewport
  28.             at: 'center',
  29.             target: $(window)
  30.         },
  31.         show: {
  32.             event: 'click', // Show it on click...
  33.             solo: true, // ...and hide all other tooltips...
  34.             modal: true // ...and make it modal
  35.         },
  36.         hide: false,
  37.     });
  38.    
  39.     $('#settingsbutton').qtip({
  40.         id: 'settings', // Since we're only creating one modal, give it an ID so we can style it
  41.         content: {
  42.             text: '<img class="spinner" src="images/blank.gif"/><span class="spinnertext"> Loading...</span>',
  43.             ajax: {
  44.                 url: 'load.php?page=settings',
  45.                 once: false,
  46.             },
  47.             title: {
  48.                 text: 'Settings',
  49.                 button: true
  50.             }
  51.         },
  52.         position: {
  53.             my: 'center', // ...at the center of the viewport
  54.             at: 'center',
  55.             target: $(window)
  56.         },
  57.         show: {
  58.             event: 'click', // Show it on click...
  59.             solo: true, // ...and hide all other tooltips...
  60.             modal: true // ...and make it modal
  61.         },
  62.         hide: false,
  63.     });
  64.    
  65.     $(".context").contextMenu({
  66.         menu: 'torrentControl'
  67.     },
  68.     function(action, el, pos) {
  69.         alert("Action: " + action + "\n\n" +
  70.               "Element ID: " + $(el).attr("id") + "\n\n" +
  71.               "X: " + pos.x + "  Y: " + pos.y + " (relative to element)\n\n" +
  72.               "X: " + pos.docX + "  Y: " + pos.docY+ " (relative to document)"
  73.         );
  74.     });
  75.    
  76.     $('#slider').slider({
  77.             steps: 1,
  78.             animate: 'false',
  79.             min: 1,
  80.             max: 31,
  81.             value: 2,
  82.             range: 'min',
  83.             slide: function(event, ui) {
  84.                 $('.ui-slider-handle').qtip({
  85.                     content: {
  86.                         text: ui.value,
  87.                     },
  88.                     position: {
  89.                         at: 'top center',
  90.                         my: 'bottom center',
  91.                         target: $('.ui-slider-handle')
  92.                     }
  93.                 })
  94.             }
  95.     });
  96. });
  97.  
  98. function dialogue(content, title) {
  99.     $('<div />').qtip({
  100.         content: {
  101.             text: content,
  102.             title: title
  103.         },
  104.         position: {
  105.             my: 'center', at: 'center', // Center it...
  106.             target: $(window) // ... in the window
  107.         },
  108.         show: {
  109.             ready: true, // Show it straight away
  110.             modal: {
  111.                 on: true, // Make it modal (darken the rest of the page)...
  112.                 blur: false // ... but don't close the tooltip when clicked
  113.             }
  114.         },
  115.         hide: false, // We'll hide it maunally so disable hide events
  116.         events: {
  117.             // Hide the tooltip when any buttons in the dialogue are clicked
  118.             render: function(event, api) {
  119.                 $('a.button', api.elements.content).click(api.hide);
  120.             },
  121.             // Destroy the tooltip once it's hidden as we no longer need it!
  122.             hide: function(event, api) { api.destroy(); }
  123.         }
  124.     });
  125. }
  126.  
  127. // Our Alert method
  128. function Alert(message) {
  129.     message = message;
  130.     buttons = '<a class="button regular"><span class="inner"><span class="label" style="min-width:50px;" nowrap="">Close</span></span></a>';
  131.    
  132.     dialogue( message + '<br /><br />' + buttons, 'Alert!' );
  133. }
  134.  
  135. // Our Prompt method
  136. function Prompt(question, initial, callback) {
  137.     var message = $('<p />', { text: question }),
  138.     input = $('<input />', { val: initial }),
  139.     ok = $('<button />', {
  140.         text: 'Ok',
  141.         click: function() { callback( input.val() ); }
  142.     }),
  143.     cancel = $('<button />', {
  144.         text: 'Cancel',
  145.         click: function() { callback(null); }
  146.     });
  147.  
  148.     dialogue( message.add(input).add(ok).add(cancel), 'Attention!' );
  149. }
  150.  
  151. // Our Confirm method
  152. function Confirm(question, callback) {
  153.     // Content will consist of the question and ok/cancel buttons
  154.     var message = $('<p />', { text: question }),
  155.     ok = $('<button />', {
  156.         text: 'Ok',
  157.         click: function() { callback(true); }
  158.     }),
  159.     cancel = $('<button />', {
  160.         text: 'Cancel',
  161.         click: function() { callback(false); }
  162.     });
  163.  
  164.     dialogue( message.add(ok).add(cancel), 'Do you agree?' );
  165. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement