< extension
name ="Progressbar"
thumbnailUrl ="http://adcirobot.appspot.com/assets/gadget.png"
description ="Insert a progress bar into your waves, and click it to indicate the current progress. " >
< author name ="Fedor Indutny" />
< menuHook location ="toolbar" text ="Add Project Progress"
iconUrl ="http://adcirobot.appspot.com/assets/gadget-small.png" >
< insertGadget url ="http://adcirobot.appspot.com/assets/gadget.xml" />
</ menuHook >
</ extension >
* This source code was highlighted with Source Code Highlighter .
<? xml version ="1.0" encoding ="UTF-8" ? >
< Module >
< ModulePrefs
title ="Progressbar"
author ="Fedor Indutny"
author_email ="fedor.indutny@gmail.com"
screenshot ="http://adcirobot.appspot.com/assets/gadget.png"
thumbnail ="http://adcirobot.appspot.com/assets/gadget.png"
>
< optional feature ="shareable-prefs" />
< Require feature ="wave" />
< Require feature ="dynamic-height" />
</ ModulePrefs >
< Content type ="html" ><! [CDATA[
html-
]] ></ Content >
</ Module >
* This source code was highlighted with Source Code Highlighter .
< script type ="text/javascript" src ="url_to_jquery.js" ></ script >
<div id= "A" style= "-webkit-user-select:none;height: 10px;background:white;border:1px solid #bbb;margin:0;padding:0;" title= "click to indicate current progress " >
<div id= "B" style= "height:100%;width: 0%;background: transparent url(data:image/png;base64, base64 ) repeat-x 0 0" >
<div style= "-webkit-user-select:none;height:100%;opacity:0.33;background:transparent url(data:image/gif;base64, base64 ) repeat 0 0;border: 0;margin:0;padding:0" ></div>
</div>
</div>
<script type= "text/javascript" >
</ script >
* This source code was highlighted with Source Code Highlighter .
// ,
//
gadgets.util.registerOnLoadHandler( function () {
var
//
lock = 0,
// (A - progressbar holder, B - progressbar)
A = $( "#A" ), B = $( "#B" ), mousemove = 0, $procent = 0,
//
round = Math.round, A$offset = A.offset(),
A$outerWidth = A.outerWidth();
//
// Google Wave -
if (!wave || !wave.isInWaveContainer()) return ;
// ()
wave.setStateCallback( function () {
// wave :
// getState()
// get([attr-name]),
var procent = wave.getState().get( 'procent' ) || 0;
//
B.stop().animate({width: procent + "%" , backgroundPosition: "(0px -" + procent + "px)" }, function () {
A[(procent >= 100) ? "addClass" : "removeClass" ]( "full" );
});
});
//
// (, )
wave.setModeCallback( function () {
if ( lock = wave.getMode() == wave.Mode.EDIT ? 0 : 1) {
//
A.css({cursor: "" });
B.css({cursor: "" });
mousemove = 0;
} else {
//
A.css({cursor: "pointer" });
B.css({cursor: "pointer" });
}
});
//
A.click( function (E) {
E.preventDefault();
//
if ( lock ) return ;
// submitDelta -
// ( ,
// setStateCallback )
wave.getState().submitDelta({procent:
E.ctrlKey ?
(A.hasClass( "full" ) ? 0 : 100)
:
round((100 * ( E.pageX - A$offset.left) / A$outerWidth))
});
}).mousedown( function (E){
// Drag
E.preventDefault();
mousemove = 1;
changed = 0;
});
$(window).mousemove( function (E){
// , submitDelta
//
if (!mousemove || lock ) return ;
changed = 1;
B.css({
width: ($procent = round((100 * ( E.pageX - A$offset.left) / A$outerWidth))) + "%" ,
backgroundPosition: "0 -" + $procent + "px"
},
function () {
A[($procent >= 100) ? "addClass" : "removeClass" ]( "full" );
});
})
.mouseup( function (E) {
mousemove = 0;
if (!changed) return ;
wave.getState().submitDelta({procent: $procent});
});
//
gadgets.window.adjustHeight(13);
});
* This source code was highlighted with Source Code Highlighter .
Source: https://habr.com/ru/post/95673/
All Articles