From e6124dcdd53763c601f6c2f6186abae59c45237c Mon Sep 17 00:00:00 2001 From: Tobi Oetiker Date: Fri, 24 Aug 2007 12:34:49 +0000 Subject: fixed unknonwn variables --- htdocs/cropper/smokeping-cropper.js | 136 ----------------------------------- htdocs/cropper/smokeping-zoom.js | 137 ++++++++++++++++++++++++++++++++++++ 2 files changed, 137 insertions(+), 136 deletions(-) delete mode 100644 htdocs/cropper/smokeping-cropper.js create mode 100644 htdocs/cropper/smokeping-zoom.js (limited to 'htdocs/cropper') diff --git a/htdocs/cropper/smokeping-cropper.js b/htdocs/cropper/smokeping-cropper.js deleted file mode 100644 index 572357c..0000000 --- a/htdocs/cropper/smokeping-cropper.js +++ /dev/null @@ -1,136 +0,0 @@ -/*++ from bonsai.js ++ urlObj +++++++++++++++++++++++++++++++++++++++++*/ -function urlObj(url) { - var urlBaseAndParameters; - - urlBaseAndParameters = url.split("?"); - this.urlBase = urlBaseAndParameters[0]; - this.urlParameters = urlBaseAndParameters[1].split(/[;&]/); - - this.getUrlBase = urlObjGetUrlBase; - this.getUrlParameterValue = urlObjGetUrlParameterValue; -} - -/*++ from bonsai.js ++ urlObjGetUrlBase +++++++++++++++++++++++++++++++*/ - -function urlObjGetUrlBase() { - return this.urlBase; -} - -/*++ form bonsai.js ++ urlObjGetUrlParameterValue +++++++++++++++++++++*/ - -function urlObjGetUrlParameterValue(parameter) { - var i; - var fieldAndValue; - var value; - - i = 0; - while (this.urlParameters [i] != undefined) { - fieldAndValue = this.urlParameters[i].split("="); - if (fieldAndValue[0] == parameter) { - value = fieldAndValue[1]; - } - i++; - } - return value; -} - -/*++++++++++++++++++++ isoDateToJS +++++++++++++++++++++++++++++++++++++*/ -function ISODateToJS(rawisodate) { - var decode = decodeURIComponent(rawisodate); - if (decode == "now") { - return new Date(); - } - else { - var M = decode.match(/(\d\d\d\d)-(\d\d?)-(\d\d?)[+ ](\d\d?):(\d\d?)/) - var date = new Date(M[1], M[2]-1, M[3], M[4], M[5], "00") - return date; - } -} - -/*++++++++++++++++++++++ JSToisoDate ++++++++++++++++++++++++++++++++++++++*/ -function JSToISODate(mydate) { - var isodate = mydate.getFullYear() + "-"; - if ((mydate.getMonth() + 1) < 10) { isodate = isodate + "0"; } - isodate = isodate + (mydate.getMonth() + 1) + "-"; - if (mydate.getDate() < 10) { isodate = isodate + "0"; } - isodate = isodate + mydate.getDate() + " "; - if (mydate.getHours() < 10) { isodate = isodate + "0"; } - isodate = isodate + mydate.getHours() + ":"; - if (mydate.getMinutes() < 10) { isodate = isodate + "0"; } - isodate = isodate + mydate.getMinutes(); - return encodeURI(isodate); -} - -// example with minimum dimensions -var myCropper; - -// will be started by modified iSelect (StopApply Function) -var StartDateString = 0; -var EndDateString = 0; - -function changeRRDImage(coords,dimensions){ - - var RRDLeftDiff = 50; // difference between left border of RRD image and content - var RRDRightDiff = 30; // difference between right border of RRD image and content - var RRDImgWidth = 697; // Width of the Smokeping RRD Graphik - var RRDImgUsable = 596; // 598 = 697 - 68 - 33; - var mySelectLeft = coords.x1; - var mySelectRight = coords.x2; - if (mySelectLeft == mySelectRight) return; // abort if nothing is selected. - - myURLObj = new urlObj(document.URL); - - // parse start and stop parameter from URL - var myURL = myURLObj.getUrlBase(); - var myRawStartDate = (StartDateString != 0) ? StartDateString : myURLObj.getUrlParameterValue("start"); - var myRawStopDate = (EndDateString != 0) ? EndDateString : myURLObj.getUrlParameterValue("end"); - var myRawTarget = myURLObj.getUrlParameterValue("target"); - - var myParsedStartDate = ISODateToJS(myRawStartDate); - var myParsedStartEpoch = Math.floor(myParsedStartDate.getTime()/1000.0); - - var myParsedStopDate = ISODateToJS(myRawStopDate); - var myParsedStopEpoch = Math.floor(myParsedStopDate.getTime()/1000.0); - - var myParsedDivEpoch = myParsedStopEpoch - myParsedStartEpoch; - - var mySerialDate = new Date(); - var mySerial = mySerialDate.getTime(); - - // Generate Selected Range in Unix Timestamps - var genStart = myParsedStartEpoch + (((mySelectLeft - RRDLeftDiff) / RRDImgUsable ) * myParsedDivEpoch); - var genStop = myParsedStartEpoch + (((mySelectRight - RRDLeftDiff) / RRDImgUsable ) * myParsedDivEpoch); - - var floorGenStart = Math.floor(genStart); - var floorGenStop = Math.floor(genStop); - - var StartDate = new Date(floorGenStart*1000); - var StopDate = new Date(floorGenStop*1000); - - // floor to last full minute - var MinuteGenStart = ( Math.floor(floorGenStart / 60) * 60 ); - var MinuteGenStop = ( Math.floor(floorGenStop / 60) * 60 ); - - StartDateString = JSToISODate(StartDate); - EndDateString = JSToISODate(StopDate); - - // construct Image URL - $('zoom').src = myURL + "?displaymode=a;start=" + StartDateString+ ";end=" + EndDateString + ";target=" + myRawTarget + ";serial=" + mySerial; - myCropper.setParams(); -}; - -Event.observe( - window, - 'load', - function() { - myCropper = new Cropper.Img( - 'zoom', - { - minHeight: 321, - maxHeight: 321, - onEndCrop: changeRRDImage - } - ) - } - ); - diff --git a/htdocs/cropper/smokeping-zoom.js b/htdocs/cropper/smokeping-zoom.js new file mode 100644 index 0000000..8129801 --- /dev/null +++ b/htdocs/cropper/smokeping-zoom.js @@ -0,0 +1,137 @@ +/*++ from bonsai.js ++ urlObj +++++++++++++++++++++++++++++++++++++++++*/ +function urlObj(url) { + var urlBaseAndParameters; + + urlBaseAndParameters = url.split("?"); + this.urlBase = urlBaseAndParameters[0]; + this.urlParameters = urlBaseAndParameters[1].split(/[;&]/); + + this.getUrlBase = urlObjGetUrlBase; + this.getUrlParameterValue = urlObjGetUrlParameterValue; +} + +/*++ from bonsai.js ++ urlObjGetUrlBase +++++++++++++++++++++++++++++++*/ + +function urlObjGetUrlBase() { + return this.urlBase; +} + +/*++ form bonsai.js ++ urlObjGetUrlParameterValue +++++++++++++++++++++*/ + +function urlObjGetUrlParameterValue(parameter) { + var i; + var fieldAndValue; + var value; + + i = 0; + while (this.urlParameters [i] != undefined) { + fieldAndValue = this.urlParameters[i].split("="); + if (fieldAndValue[0] == parameter) { + value = fieldAndValue[1]; + } + i++; + } + return value; +} + +/*++++++++++++++++++++ isoDateToJS +++++++++++++++++++++++++++++++++++++*/ +function ISODateToJS(rawisodate) { + var decode = decodeURIComponent(rawisodate); + if (decode == "now") { + return new Date(); + } + else { + var M = decode.match(/(\d\d\d\d)-(\d\d?)-(\d\d?)[+ ](\d\d?):(\d\d?)/) + var date = new Date(M[1], M[2]-1, M[3], M[4], M[5], "00") + return date; + } +} + +/*++++++++++++++++++++++ JSToisoDate ++++++++++++++++++++++++++++++++++++++*/ +function JSToISODate(mydate) { + var isodate = mydate.getFullYear() + "-"; + if ((mydate.getMonth() + 1) < 10) { isodate = isodate + "0"; } + isodate = isodate + (mydate.getMonth() + 1) + "-"; + if (mydate.getDate() < 10) { isodate = isodate + "0"; } + isodate = isodate + mydate.getDate() + " "; + if (mydate.getHours() < 10) { isodate = isodate + "0"; } + isodate = isodate + mydate.getHours() + ":"; + if (mydate.getMinutes() < 10) { isodate = isodate + "0"; } + isodate = isodate + mydate.getMinutes(); + return encodeURI(isodate); +} + +// example with minimum dimensions +var myCropper; + + +// will be started by modified iSelect (StopApply Function) +var StartDateString = 0; +var EndDateString = 0; + +function changeRRDImage(coords,dimensions){ + + var RRDLeftDiff = 50; // difference between left border of RRD image and content + var RRDRightDiff = 30; // difference between right border of RRD image and content + var RRDImgWidth = 697; // Width of the Smokeping RRD Graphik + var RRDImgUsable = 596; // 598 = 697 - 68 - 33; + var mySelectLeft = coords.x1; + var mySelectRight = coords.x2; + if (mySelectLeft == mySelectRight) return; // abort if nothing is selected. + + myURLObj = new urlObj(document.URL); + + // parse start and stop parameter from URL + var myURL = myURLObj.getUrlBase(); + var myRawStartDate = (StartDateString != 0) ? StartDateString : myURLObj.getUrlParameterValue("start"); + var myRawStopDate = (EndDateString != 0) ? EndDateString : myURLObj.getUrlParameterValue("end"); + var myRawTarget = myURLObj.getUrlParameterValue("target"); + + var myParsedStartDate = ISODateToJS(myRawStartDate); + myParsedStartEpoch = Math.floor(myParsedStartDate.getTime()/1000.0); + + var myParsedStopDate = ISODateToJS(myRawStopDate); + myParsedStopEpoch = Math.floor(myParsedStopDate.getTime()/1000.0); + + myParsedDivEpoch = myParsedStopEpoch - myParsedStartEpoch; + + var mySerialDate = new Date(); + var mySerial = mySerialDate.getTime(); + + // Generate Selected Range in Unix Timestamps + var genStart = myParsedStartEpoch + (((mySelectLeft - RRDLeftDiff) / RRDImgUsable ) * myParsedDivEpoch); + var genStop = myParsedStartEpoch + (((mySelectRight - RRDLeftDiff) / RRDImgUsable ) * myParsedDivEpoch); + + var floorGenStart = Math.floor(genStart); + var floorGenStop = Math.floor(genStop); + + var StartDate = new Date(floorGenStart*1000); + var StopDate = new Date(floorGenStop*1000); + + // floor to last full minute + var MinuteGenStart = ( Math.floor(floorGenStart / 60) * 60 ); + var MinuteGenStop = ( Math.floor(floorGenStop / 60) * 60 ); + + StartDateString = JSToISODate(StartDate); + EndDateString = JSToISODate(StopDate); + + // construct Image URL + $('zoom').src = myURL + "?displaymode=a;start=" + StartDateString+ ";end=" + EndDateString + ";target=" + myRawTarget + ";serial=" + mySerial; + myCropper.setParams(); +}; + +Event.observe( + window, + 'load', + function() { + myCropper = new Cropper.Img( + 'zoom', + { + minHeight: 321, + maxHeight: 321, + onEndCrop: changeRRDImage + } + ) + } + ); + -- cgit v1.2.3-24-g4f1b