├── README.txt ├── dialog-jquery.js └── weblocks-jquery.js /README.txt: -------------------------------------------------------------------------------- 1 | These are javascript files which allow to replace prototype-dependent functionality in weblocks with jquery-dependent functionality. 2 | To use it copy jquery files (or link if you use this repository as a submodule) to pub/scripts directory, unload prototype, load jquery and these files. 3 | Example of loading is following. 4 | 5 | (defwebapp test-app 6 | :prefix "/" 7 | :description "test-app: A new great application" 8 | :init-user-session 'test-app::init-user-session 9 | :autostart nil ;; have to start the app manually 10 | :ignore-default-dependencies t ;; accept the defaults 11 | :debug t 12 | :dependencies 13 | (list 14 | (make-instance 'script-dependency :url "/pub/scripts/jquery-1.7.2.min.js") 15 | (make-instance 'stylesheet-dependency :url "/pub/stylesheets/main.css") 16 | (make-instance 'script-dependency :url "/pub/scripts/weblocks-jquery.js") 17 | (make-instance 'script-dependency :url "/pub/scripts/dialog-jquery.js") 18 | (make-instance 'script-dependency :url "/pub/scripts/jquery-seq.js"))) 19 | 20 | Repository also contains onAvailable utility function, useful for Weblocks plugisn writing. 21 | 22 | -------------------------------------------------------------------------------- /dialog-jquery.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Dialog jQuery - dialog helper functions for Weblocks, v0.0.1 3 | */ 4 | 5 | function showDialog(title, body, cssClass){ 6 | if(jQuery('.graybox').length){ 7 | jQuery('.graybox').show(); 8 | }else{ 9 | jQuery('body').append('
'); 10 | } 11 | 12 | var dialogBody = '
' + body + '
'; 13 | var titleBar = '

' + title + '

'; 14 | var dialogHtml = '
' + titleBar + dialogBody + '
'; 15 | var dialog = jQuery(dialogHtml); 16 | 17 | jQuery('div.page-wrapper').append(dialog); 18 | var offsetTop = (jQuery(window).height() - dialog.height()) / 2; 19 | var offsetLeft = (jQuery(window).width() - dialog.width()) / 2; 20 | dialog.offset({top: offsetTop, left: offsetLeft}); 21 | } 22 | 23 | function removeDialog(){ 24 | jQuery('.dialog').remove(); 25 | jQuery('.graybox').hide(); 26 | } 27 | -------------------------------------------------------------------------------- /weblocks-jquery.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Weblocks-jQuery - javascript helper functions for Weblocks 3 | * v0.2.0 4 | * 5 | * https://github.com/html/weblocks-jquery 6 | */ 7 | 8 | // Taken from http://css-tricks.com/snippets/jquery/serialize-form-to-json/ 9 | jQuery.fn.serializeObject = function() 10 | { 11 | var o = {}; 12 | var a = this.serializeArray(); 13 | jQuery.each(a, function() { 14 | if (o[this.name]) { 15 | if (!o[this.name].push) { 16 | o[this.name] = [o[this.name]]; 17 | } 18 | o[this.name].push(this.value || ''); 19 | } else { 20 | o[this.name] = this.value || ''; 21 | } 22 | }); 23 | return o; 24 | }; 25 | 26 | /* 27 | * This prevents javascript error, but does not any effect like with usual weblocks flashes. 28 | */ 29 | window.Effect = Effect = { 30 | Pulsate: function(){ return {};}, 31 | BlindUp: function(){ return {};} 32 | }; 33 | 34 | /* 35 | * This prevents javascript error and replaces weblocks focusFirstElement form functionality 36 | */ 37 | jQuery.fn.focusFirstElement = function(){ 38 | if(jQuery(this).length){ 39 | jQuery(this).find('input:first').focus(); 40 | } 41 | }; 42 | 43 | jQuery.fn.serializeObjectWithSubmit = function(){ 44 | var ret = this.serializeObject(); 45 | var submitElement = jQuery(this).find('input[type=submit][clicked=true]'); 46 | ret[submitElement.attr('name')] = submitElement.val(); 47 | submitElement.attr('clicked', null); 48 | 49 | return ret; 50 | }; 51 | 52 | // Utilities 53 | function updateElementBody(element, newBody) { 54 | element.update(newBody); 55 | } 56 | 57 | function updateElement(element, newElement) { 58 | var $newElement = jQuery(newElement); 59 | element.replaceWith($newElement); 60 | } 61 | 62 | function applySubmitClickEvent() { 63 | jQuery("form input[type=submit]") 64 | .unbind('click.weblocks-submit-event') 65 | .bind('click.weblocks-submit-event', function() { 66 | $("input[type=submit]", $(this).parents("form")).removeAttr("clicked"); 67 | $(this).attr("clicked", "true"); 68 | }); 69 | } 70 | 71 | function selectionEmpty() { 72 | if(document.getSelection) { 73 | return document.getSelection() == ""; 74 | } else if(document.selection && document.selection.createRange) { 75 | return document.selection.createRange().text == ""; 76 | } else { 77 | return true; 78 | } 79 | } 80 | 81 | function addCss(cssCode) { 82 | var styleElement = document.createElement("style"); 83 | styleElement.type = "text/css"; 84 | if (styleElement.styleSheet) { 85 | styleElement.styleSheet.cssText = cssCode; 86 | } else { 87 | styleElement.appendChild(document.createTextNode(cssCode)); 88 | } 89 | document.getElementsByTagName("head")[0].appendChild(styleElement); 90 | } 91 | 92 | function stopPropagation(event) { 93 | if(event.preventDefault) { 94 | event.stopPropagation(); 95 | } else { 96 | event.cancelBubble = true; 97 | }; 98 | } 99 | 100 | function startProgress(){ 101 | jQuery('#ajax-progress').html(""); 102 | } 103 | 104 | function stopProgress(){ 105 | jQuery('#ajax-progress').html(""); 106 | } 107 | 108 | // Register global AJAX handlers to show progress 109 | jQuery(document).ajaxStart(function() { 110 | try{ 111 | startProgress(); 112 | }catch(e){ 113 | window.console && console.log(e, e.message); 114 | } 115 | }); 116 | 117 | jQuery(document).ajaxStop(function() { 118 | stopProgress(); 119 | }); 120 | 121 | Object.values = function (obj) { 122 | var vals = []; 123 | for( var key in obj ) { 124 | if ( obj.hasOwnProperty(key) ) { 125 | vals.push(obj[key]); 126 | } 127 | } 128 | return vals; 129 | } 130 | 131 | function dumpTree(tree, deepness){ 132 | if(!deepness){ 133 | deepness = 1; 134 | } 135 | var prefix = ''; 136 | for(var i=0;i