diff --git a/_config.php b/_config.php index 326e6e8b..bb0e26f7 100644 --- a/_config.php +++ b/_config.php @@ -9,7 +9,6 @@ Director::addRules(50, array( 'processes//$Action/$ID/$Batch' => 'BatchProcess_Controller', 'admin/help//$Action/$ID' => 'CMSHelp', 'admin/bulkload//$Action/$ID/$OtherID' => 'BulkLoaderAdmin', - 'admin//ImageEditor/$Action' => 'ImageEditor', 'admin/cms//$Action/$ID/$OtherID' => 'CMSMain', 'PageComment//$Action/$ID' => 'PageComment_Controller', 'dev/buildcache/$Action' => 'RebuildStaticCacheTask', diff --git a/code/AssetTableField.php b/code/AssetTableField.php index e80d8700..3b602d8b 100755 --- a/code/AssetTableField.php +++ b/code/AssetTableField.php @@ -72,7 +72,6 @@ class AssetTableField extends ComplexTableField { $ret = parent::FieldHolder(); Requirements::javascript(CMS_DIR . '/javascript/AssetTableField.js'); - Requirements::javascript('cms/javascript/ImageEditor/Activator.js'); return $ret; } diff --git a/code/ImageEditor.php b/code/ImageEditor.php deleted file mode 100644 index 4825e6f7..00000000 --- a/code/ImageEditor.php +++ /dev/null @@ -1,265 +0,0 @@ - 'CMS_ACCESS_CMSMain' - ); - - public $fileToEdit = ""; - - public $fileToEditOnlyName = ""; - - /** - * Includes all JS required for ImageEditor. This method requires setting - * a fileToEdit URL in POST. - * - * @return String - */ - public function index() { - Requirements::clear(); - Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/prototype/prototype.js'); - Requirements::javascript(THIRDPARTY_DIR . '/scriptaculous/scriptaculous.js'); - Requirements::javascript(CMS_DIR . '/javascript/ImageEditor/Utils.js'); - //Requirements::javascript(CMS_DIR . '/javascript/ImageEditor/ImageHistory.js'); - Requirements::javascript(CMS_DIR . '/javascript/ImageEditor/Image.js'); - //Requirements::javascript(CMS_DIR . '/javascript/ImageEditor/ImageTransformation.js'); - Requirements::javascript(CMS_DIR . '/javascript/ImageEditor/Resizeable.js'); - Requirements::javascript(CMS_DIR . '/javascript/ImageEditor/Effects.js'); - Requirements::javascript(CMS_DIR . '/javascript/ImageEditor/Environment.js'); - Requirements::javascript(CMS_DIR . '/javascript/ImageEditor/Crop.js'); - Requirements::javascript(CMS_DIR . '/javascript/ImageEditor/Resize.js'); - Requirements::javascript(CMS_DIR . '/javascript/ImageEditor/ImageBox.js'); - Requirements::javascript(CMS_DIR . '/javascript/ImageEditor/ImageEditor.js'); - Requirements::javascript(CMS_DIR . '/javascript/ImageEditor/DocumentBody.js'); - - Requirements::javascript(SAPPHIRE_DIR . '/javascript/loader.js'); - Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/behaviour/behaviour.js'); - Requirements::javascript(CMS_DIR . '/javascript/LeftAndMain.js'); - Requirements::css(CMS_DIR . 'css/ImageEditor/ImageEditor.css'); - - if(!isset($this->requestParams['fileToEdit'])) $this->raiseError(); - $fileWithPath = $this->requestParams['fileToEdit']; - $this->fileToEdit = $this->file2Origin($fileWithPath); - $this->fileToEditOnlyName = $this->urlToFilename($this->fileToEdit); - return $this->renderWith(__CLASS__); - } - - /** - * Method is used for manipulating photos. - * Method requires two params set in POST - * file - file on which operation will be performed - * command - name of operation(crop|rotate|resize) - * - * Each operation requires additional parameters. - * - * @return String - JSON array with image properties (width,height,url). - */ - public function manipulate() { - $fileName = $this->requestParams['file']; - if(strpos($fileName,'?') !== false) $fileName = substr($fileName,0,strpos($fileName,'?')); - $command = $this->requestParams['command']; - $this->checkFileExists($fileName); - $fileInfo = pathinfo($fileName); - $gd = new GD($this->url2File($fileName)); - switch($command) { - case 'rotate': - $gd = $gd->rotate(90); - break; - case 'resize': - $imageNewWidth = $_POST['newImageWidth']; - $imageNewHeight = $_POST['newImageHeight']; - $gd = $gd->resize($imageNewWidth,$imageNewHeight); - break; - case 'crop': - $top = $_POST['top']; - $left = $_POST['left']; - $width = $_POST['width']; - $height = $_POST['height']; - $gd = $gd->crop($top,$left,$width,$height); - break; - case 'greyscale': - $gd = $gd->greyscale(); - break; - case 'sepia': - $gd = $gd->sepia(); - break; - case 'blur': - $gd = $gd->blur(); - break; - case 'adjust-contrast': - $value = intval($_POST['value']); - $gd = $gd->contrast($value); - break; - case 'adjust-brightness': - $value = intval($_POST['value']); - $gd = $gd->brightness($value); - break; - case 'adjust-gamma': - $value = floatval($_POST['value']); - $gd = $gd->gamma($value); - break; - } - $rand = md5(rand(1,100000)); - $gd->writeTo(ASSETS_PATH . '/_tmp/' . $rand . '.' . $fileInfo['extension']); - return $this->getImageInfoInJSON($gd,ASSETS_PATH . '/_tmp/' . $rand . '.' . $fileInfo['extension']); - } - - /** - * Method is used for saving photos. - * Method requires two params set in POST - * originalFile - this file will be replaced by second file - * editedFile - this file will replace first file. - * - * After replacing original file all thumbnails created from it are removed. - * - * @return String - Message that everything went ok. - */ - - public function save() { - if(isset($this->requestParams['originalFile']) && isset($this->requestParams['editedFile'])) { - $originalFile = $this->requestParams['originalFile']; - $editedFile = $this->requestParams['editedFile']; - if(strpos($originalFile,'?') !== false) $originalFile = substr($originalFile,0,strpos($originalFile,'?')); - if($this->checkFileExists($originalFile) && $this->checkFileExists($editedFile)) { - if($editedFile != $originalFile && copy($this->url2File($editedFile),$this->url2File($originalFile))) { - $image = DataObject::get_one('File','"Filename" = \'' . substr($this->url2File($originalFile),3) . '\''); - $image->deleteFormattedImages(); - $image->generateFormattedImage('AssetLibraryPreview'); - } else { - $this->raiseError(); - } - } else { - $this->raiseError(); - } - } else { - $this->raiseError(); - } - return 'parent.parent.parent.statusMessage(\'Image saved\',\'good\',false);'; - } - - /** - * Method is invoked when ImageEditor is closed whether image is saved or not. - * - * /assets/tmp is folder where we store temporary images created during editing so - * after closing they are no necessity to keep them. - * - * @return null - */ - - public function close() { - $tmpDir = ASSETS_PATH . '/_tmp'; - if(file_exists($tmpDir)) { - Filesystem::removeFolder($tmpDir); - mkdir($tmpDir, Filesystem::$folder_create_mask); - } - } - - /** - * Method return JSON array containing info about image. - * - * @param gd - GD object used for retrieving info about image - * @param file - * - * @return string JSON array explained in manipulate method comment - */ - - private function getImageInfoInJSON(GD $gd,$file) { - return '{"fileName":"' . $file . '","width":' . $gd->getWidth() . ',"height":' . $gd->getHeight() . '}'; - } - - /** - * Method converts thumbnail file name to file name of it's "parent" - * - * @param file - name of thumbnail file - * - * @return string name of parent file. - */ - - private function file2Origin($file) { - $file = str_replace('_resampled/','',$file); - $file = str_replace('_resampled/','',$file); - $file = str_replace('AssetLibraryPreview-','',$file); - $this->checkFileExists($file); - return $file; - } - /** - * Method converts URL of file to file path in file system. - * - * @param url - url of file - * - * @return string path of file in file system - */ - - private function url2File($url) { - return '..' . substr($url,strpos($url,'/assets')); - } - - /** - * Method checks if file exists and have proper name and extension. - * - * If any of constraints aren't fulfilled method will generate error. - * - * @param url - url of file - * - * @return boolean - */ - - private function checkFileExists($url) { - if(strpos($url,'?') !== false) $url = substr($url,0,strpos($url,'?')); - $pathInfo = pathinfo($url); - if(count($pathInfo) < 3) $this->raiseError(); - if(!in_array($pathInfo['extension'],array('jpeg','jpg','jpe','png','gif','JPEG','JPG','JPE','PNG','GIF'))) $this->raiseError(); - $path = explode('/',$pathInfo['dirname']); - if(count($path) > 1) { - $assetId = array_search('assets',$path); - if($assetId > 0) { - $realPath = '../' . implode('/',array_slice($path,$assetId,count($path) - $assetId)); - if(strpos($pathInfo['basename'],'AssetLibraryPreview') !== false) { - $realPath .= '/' . substr($pathInfo['basename'],strpos($pathInfo['basename'],'-')); - } else { - $realPath .= '/' . $pathInfo['basename']; - } - } else { - $this->raiseError(); - } - if(file_exists($realPath)) { - return true; - } else { - $this->raiseError(); - } - } else { - $this->raiseError(); - } - } - - /** - * Method raiser error. Error is showed using statusMessage function. - * - * @param message - error message - * - */ - - private function raiseError($message = "") { - echo "parent.parent.parent.statusMessage('Error: " . $message . "','bad',false);"; - exit(); - } - - /** - * Method converts retrieves filename from url - * - * @param url - * - */ - - private function urlToFilename($url) { - $path = pathinfo($url); - return $path['filename'] . "." . substr($path['extension'],0,strpos($path['extension'],'?')); - } -} - -?> \ No newline at end of file diff --git a/javascript/ImageEditor/Activator.js b/javascript/ImageEditor/Activator.js deleted file mode 100644 index c52323e9..00000000 --- a/javascript/ImageEditor/Activator.js +++ /dev/null @@ -1,43 +0,0 @@ -ImageEditor = {}; - -ImageEditor.Activator = { - initialize: function() { - this.onOpen = ImageEditor.Activator.onOpen.bind(this); - }, - - onOpen: function() { - var windowWidth = Element.getDimensions(window.top.document.body).width; - var windowHeight = Element.getDimensions(window.top.document.body).height; - var iframe = window.top.document.getElementById('imageEditorIframe'); - if(iframe != null) { - iframe.parentNode.removeChild(iframe); - } - iframe = window.top.document.createElement('iframe'); - var fileToEdit = $('ImageEditorActivator').firstChild.src; - iframe.setAttribute("src","admin/ImageEditor?fileToEdit=" + fileToEdit); - iframe.id = 'imageEditorIframe'; - iframe.style.width = windowWidth - 6 + 'px'; - iframe.style.height = windowHeight + 10 + 'px'; - iframe.style.zIndex = "1000"; - iframe.style.position = "absolute"; - iframe.style.top = "8px"; - iframe.style.left = "8px"; - window.top.document.body.appendChild(iframe); - var divLeft = window.top.document.createElement('div'); - var divRight = window.top.document.createElement('div'); - divLeft.style.width = "8px"; - divLeft.style.height = "300%"; - divLeft.style.zIndex = "1000"; - divLeft.style.top = "0"; - divLeft.style.position = "absolute"; - divRight.style.width = "10px"; - divRight.style.height = "300%"; - divRight.style.zIndex = "1000"; - divRight.style.top = "0"; - divRight.style.position = "absolute"; - divRight.style.left = Element.getDimensions(divLeft).width + Element.getDimensions(iframe).width - 4 + 'px'; - window.top.document.body.appendChild(divLeft); - window.top.document.body.appendChild(divRight); - } - -} \ No newline at end of file diff --git a/javascript/ImageEditor/Adjust.js b/javascript/ImageEditor/Adjust.js deleted file mode 100644 index e719d27a..00000000 --- a/javascript/ImageEditor/Adjust.js +++ /dev/null @@ -1,16 +0,0 @@ -ImageEditor.Adjust = { - initialize: function() { - this.perform = ImageEditor.Adjust.perform.bind(this); - this.setListener = ImageEditor.Adjust.setListener.bind(this); - this.setListener(); - }, - - setListener: function() { - Element.toggle($('AdjustMenu')); - Event.observe('AdjustButton','click',this.perform); - }, - - perform: function() { - Element.toggle($('AdjustMenu')); - } -} \ No newline at end of file diff --git a/javascript/ImageEditor/Crop.js b/javascript/ImageEditor/Crop.js deleted file mode 100644 index 7dc2de76..00000000 --- a/javascript/ImageEditor/Crop.js +++ /dev/null @@ -1,203 +0,0 @@ -/** - * @author Mateusz - */ -ImageEditor.Crop = { - - initialize: function() { - this.cropBox = $('cropBox'); - new ImageEditor.Positioning.addBehaviour(this.cropBox); - this.imageContainer = $('imageContainer'); - this.leftGreyBox = $('leftGreyBox'); - this.rightGreyBox = $('rightGreyBox'); - this.upperGreyBox = $('upperGreyBox'); - this.lowerGreyBox = $('lowerGreyBox'); - this.centerCropBox = ImageEditor.Crop.centerCropBox.bind(this); - this.placeGreyBox = ImageEditor.Crop.placeGreyBox.bind(this); - this.setListeners = ImageEditor.Crop.setListeners.bind(this); - this.onCropStart = ImageEditor.Crop.onCropStart.bind(this); - this.onCropOk = ImageEditor.Crop.onCropOk.bind(this); - this.onCropCancel = ImageEditor.Crop.onCropCancel.bind(this); - this.doCrop = ImageEditor.Crop.doCrop.bind(this); - this.setVisible = ImageEditor.Crop.setVisible.bind(this); - this.enable = ImageEditor.Crop.enable.bind(this); - this.disable = ImageEditor.Crop.disable.bind(this); - this.onImageLoadCallback = ImageEditor.Crop.onImageLoadCallback.bind(this); - Event.observe('image','load',this.centerCropBox); - var options = { - resizeStop: ImageEditor.Crop.resizeStop.bind(this), - onDrag: ImageEditor.Crop.onDrag.bind(this), - onResize: ImageEditor.Crop.onResize.bind(this), - getMousePos: ImageEditor.Crop.getMousePos.bind(this) - }; - this.resizeCropBox = new ImageEditor.Resizeable.initialize(this.cropBox,options); - Event.observe(this.cropBox,'dblclick',this.onCropOk.bind(this)); - this.setListeners(); - this.isVisible = false; - this.setVisible(this.isVisible); - this.isEnabled = true; - this.lastCrop = {}; - }, - - resizeStop: function(event) { - if(this.isVisible) { - ImageEditor.EventStack.clearStack(); - this.resizeCropBox.originalHeight = this.cropBox.getHeight(); - this.resizeCropBox.originalWidth = this.cropBox.getWidth(); - } - }, - - onDrag: function(event) { - if(this.cropBox.getLeft() <= 0 ) this.cropBox.style.left = '0px'; - if(this.cropBox.getTop() <= 0 ) this.cropBox.style.top = '0px'; - if(this.cropBox.getLeft() + this.cropBox.getWidth() > this.cropBox.getParentWidth()) this.cropBox.style.left = this.cropBox.getParentWidth()- this.cropBox.getWidth() + 'px'; - if(this.cropBox.getTop() + this.cropBox.getHeight() > this.cropBox.getParentHeight()) this.cropBox.style.top = this.cropBox.getParentHeight() - this.cropBox.getHeight() + 'px'; - this.placeGreyBox(this.cropBox.getWidth(),this.cropBox.getHeight()); - }, - - centerCropBox: function() { - this.cropBox.style.width = this.cropBox.getParentWidth()/2 + 'px'; - this.cropBox.style.height = this.cropBox.getParentHeight()/2 + 'px'; - this.cropBox.style.left = (this.cropBox.getParentWidth() - this.cropBox.getWidth())/2 + "px"; - this.cropBox.style.top = (this.cropBox.getParentHeight() - this.cropBox.getHeight())/2 + "px"; - this.placeGreyBox(this.cropBox.getWidth(),this.cropBox.getHeight()); - this.leftBoxConstraint = this.cropBox.getParentLeft(); - this.topBoxConstraint = this.cropBox.getParentTop(); - this.rightBoxConstraint = this.cropBox.getParentLeft() + this.cropBox.getParentWidth(); - this.bottomBoxConstraint = this.cropBox.getParentTop() + this.cropBox.getParentHeight()-1;//hack without 1 doesn't work; - }, - - placeGreyBox: function(width,height) { - if(this.isVisible) { - this.lowerGreyBox.style.left = this.cropBox.getLeft() + 'px'; - this.lowerGreyBox.style.width = width + 'px'; - this.lowerGreyBox.style.height = this.cropBox.getParentHeight() - this.cropBox.getTop() - height + "px"; - this.lowerGreyBox.style.top = this.cropBox.getTop() + height + "px"; - this.leftGreyBox.style.width = this.cropBox.getLeft() + "px"; - this.leftGreyBox.style.height = $('imageContainer').getHeight() + 'px'; - this.rightGreyBox.style.width = this.cropBox.getParentWidth() - this.cropBox.getLeft() - width + "px"; - this.rightGreyBox.style.height = $('imageContainer').getHeight() + 'px'; - this.rightGreyBox.style.left = this.cropBox.getLeft() + width + "px"; - this.upperGreyBox.style.width = width + 'px'; - this.upperGreyBox.style.left = this.cropBox.getLeft() + 'px'; - this.upperGreyBox.style.height = this.cropBox.getTop() + 'px'; - this.resizeCropBox.placeClickBox(); - } - }, - - onResize: function(width,height) { - if(width + parseInt(this.cropBox.style.left) > Element.getDimensions(this.imageContainer).width) { - this.cropBox.style.left = parseInt(this.cropBox.style.left) - Math.abs(Element.getDimensions(this.imageContainer).width - (width + parseInt(this.cropBox.style.left))) + "px"; - } - if(parseInt(this.cropBox.style.left) < 0) { - this.cropBox.style.left = "0px"; - } - if(width > Element.getDimensions(this.imageContainer).width) { - this.cropBox.style.width = Element.getDimensions(this.imageContainer).width + "px"; - width = Element.getDimensions(this.imageContainer).width; - } - this.placeGreyBox(width,height); - }, - - getMousePos: function(event) { - var x = Event.pointerX(event) + $('imageEditorContainer').scrollLeft; - var y = Event.pointerY(event) + $('imageEditorContainer').scrollTop; - if(x <= this.leftBoxConstraint) x = this.leftBoxConstraint; - if(y <= this.topBoxConstraint) y = this.topBoxConstraint; - if(x >= this.rightBoxConstraint) x = this.rightBoxConstraint; - if(y >= this.bottomBoxConstraint) y = this.bottomBoxConstraint; - return {x: x,y: y}; - }, - - doCrop: function() { - if(this.isEnabled) { - var newWidth = this.cropBox.getWidth() - var newHeight = this.cropBox.getHeight() ; - var startTop = this.cropBox.getTop() ; - var startLeft = this.cropBox.getLeft() ; - if(newWidth > 35 && newHeight > 35) { - this.lastCrop.top = startTop; - this.lastCrop.left = startLeft; - this.lastCrop.newWidth = newWidth; - this.lastCrop.newHeight = newHeight; - ImageEditor.transformation.crop(startTop,startLeft,newWidth,newHeight,ImageEditor.Crop.cropCallback.bind(this)); - this.disable(); - } else { - ImageEditor.statusMessageWrapper.statusMessage("Crop area too small","bad"); - return false; - } - $('image').style.visibility = 'visible';//hack for IE for not selecting image during crop - return true; - } - }, - - cropCallback: function() { - ImageEditor.history.addCrop($('image').src, - this.lastCrop.top, - this.lastCrop.left, - this.lastCrop.newWidth, - this.lastCrop.newHeight - ); - ImageEditor.resize.imageContainerResize.placeClickBox(); - ImageEditor.resize.imageContainerResize.setVisible(true); - Element.show($('CropText')); - Element.hide(this.cropBox,this.leftGreyBox,this.rightGreyBox,this.upperGreyBox,this.lowerGreyBox,$('CurrentAction')); - }, - - setListeners: function() { - Event.observe('CropButton','click',this.onCropStart); - Event.observe('CancelButton','click',this.onCropCancel); - Event.observe('ApplyButton','click',this.onCropOk); - }, - onCropStart: function() { - if(this.isEnabled) { - $('image').style.visibility = "hidden";//hack for IE for not selecting image during crop - this.setVisible(true); - Element.show($('CurrentAction')); - ImageEditor.Main.disableFunctionality(); - this.enable(); - } - }, - - onCropOk: function() { - if(this.isEnabled) { - if(this.doCrop()) Element.hide($('CurrentAction')); - } - }, - - onCropCancel: function(event) { - if(this.isEnabled) { - Element.hide($('CurrentAction')); - Element.show($('CropText')); - this.setVisible(false); - ImageEditor.Main.enableFunctionality(); - this.enable(); - } - $('image').style.visibility = 'visible';//hack for IE for not selecting image during crop - }, - - setVisible: function(setVisible) { - this.isVisible = setVisible; - if(setVisible) { - Element.show(this.cropBox,this.leftGreyBox,this.rightGreyBox,this.upperGreyBox,this.lowerGreyBox); - this.centerCropBox(); - this.placeGreyBox(this.cropBox.getWidth(),this.cropBox.getHeight()); - } else { - Element.hide(this.cropBox,this.leftGreyBox,this.rightGreyBox,this.upperGreyBox,this.lowerGreyBox,$('CurrentAction')); - } - ImageEditor.resize.imageContainerResize.setVisible(!setVisible); - this.resizeCropBox.setVisible(setVisible); - }, - - enable: function() { - this.isEnabled = true; - }, - - disable: function() { - this.isEnabled = false; - }, - - onImageLoadCallback: function() { - ImageEditor.crop.setVisible(false); - } - -} \ No newline at end of file diff --git a/javascript/ImageEditor/DocumentBody.js b/javascript/ImageEditor/DocumentBody.js deleted file mode 100644 index bcac0e09..00000000 --- a/javascript/ImageEditor/DocumentBody.js +++ /dev/null @@ -1,34 +0,0 @@ -/** - * @author Mateusz - */ -ImageEditor.DocumentBody = { - initialize: function() { - this.placeUI = ImageEditor.DocumentBody.placeUI.bind(this); - this.placeUI(); - Event.observe(window.top,'resize',ImageEditor.DocumentBody.resizeIframe.bind(this)); - }, - - resizeIframe: function(event) { - var windowWidth = Element.getDimensions(window.top.document.body).width; - var windowHeight = Element.getDimensions(window.top.document.body).height; - var iframe = window.top.document.getElementById('imageEditorIframe'); - iframe.style.width = windowWidth - 6 + 'px'; - iframe.style.height = windowHeight + 10 + 'px'; - this.placeUI(); - }, - - placeUI: function() { - var iframe = window.top.document.getElementById('imageEditorIframe'); - $('imageEditorContainer').style.height = Element.getDimensions(iframe).height - Element.getDimensions($('TopRuler')).height - Element.getDimensions($('MenuBar')).height - 32 + 'px'; - $('imageEditorContainer').style.width = Element.getDimensions(iframe).width - Element.getDimensions($('LeftRuler')).width - 14 + 'px'; - $('LeftRuler').style.height = $('imageEditorContainer').style.height; - $('TopLeft').style.width = Element.getDimensions($('MenuBar')).width - - Element.getDimensions($('TopRight')).width + 'px'; - $('TopRight').style.left = Element.getDimensions($('TopLeft')).width + 'px'; - - }, - - onImageEditorScroll: function() { - ImageEditor.imageBox.reCenterIndicator(); - } -} diff --git a/javascript/ImageEditor/Effects.js b/javascript/ImageEditor/Effects.js deleted file mode 100644 index 0aa2e45e..00000000 --- a/javascript/ImageEditor/Effects.js +++ /dev/null @@ -1,35 +0,0 @@ -/** - * @author Mateusz - */ -ImageEditor.Effects.Main = { - initialize: function() { - this.enable = ImageEditor.Effects.Main.enable.bind(this); - this.disable = ImageEditor.Effects.Main.disable.bind(this); - this.effects = Array(); - this.effects['rotate'] = new ImageEditor.Effects.Base.initialize('rotate'); - this.effects['greyscale'] = new ImageEditor.Effects.Base.initialize('greyscale'); - this.effects['sepia'] = new ImageEditor.Effects.Base.initialize('sepia'); - this.effects['blur'] = new ImageEditor.Effects.Base.initialize('blur'); - this.effects['adjust-contrast'] = new ImageEditor.Effects.AdjustBase.initialize('adjust-contrast',$R(-100, 100),0.1,62); - this.effects['adjust-brightness'] = new ImageEditor.Effects.AdjustBase.initialize('adjust-brightness',$R(-255, 255),0.1,160); - this.effects['adjust-gamma'] = new ImageEditor.Effects.AdjustBase.initialize('adjust-gamma',$R(0, 5),1.2,4); - this.getEffect = ImageEditor.Effects.Main.getEffect.bind(this); - }, - - enable: function() { - for (var name in this.effects) { - if(this.effects.hasOwnProperty(name)) this.effects[name].enable(); - } - }, - - disable: function() { - for (var name in this.effects) { - if(this.effects.hasOwnProperty(name)) this.effects[name].disable(); - } - }, - - getEffect: function(name) { - return this.effects[name]; - } - -} \ No newline at end of file diff --git a/javascript/ImageEditor/Effects/AdjustBase.js b/javascript/ImageEditor/Effects/AdjustBase.js deleted file mode 100644 index 74938e22..00000000 --- a/javascript/ImageEditor/Effects/AdjustBase.js +++ /dev/null @@ -1,120 +0,0 @@ -ImageEditor.Effects.AdjustBase = { - initialize: function(name,minMax,firstValue,maxValue) { - this.name = name; - this.minMax = minMax; - this.firstValue = firstValue; - this.maxValue = maxValue; - this.setListener = ImageEditor.Effects.AdjustBase.setListener.bind(this); - this.callback = ImageEditor.Effects.AdjustBase.callback.bind(this); - this.setValue = ImageEditor.Effects.AdjustBase.setValue.bind(this); - this.getDefaultValue = ImageEditor.Effects.AdjustBase.getDefaultValue.bind(this); - this.setListener(); - this.lastValue = this.firstValue; - this.stopListenining = false; - }, - - setListener: function() { - var upperCaseName = this.name.substring(7,8).toUpperCase() + this.name.substring(8,this.name.length); - this.slider = new Control.Slider('AdjustMenu' + upperCaseName + 'SliderTrackHandler','AdjustMenu' + upperCaseName + 'SliderTrack', { - range: this.minMax, - sliderValue: this.firstValue, - onChange: ImageEditor.Effects.AdjustBase.onChange.bind(this), - onSlide: ImageEditor.Effects.AdjustBase.onSlide.bind(this) - }); - }, - - onSlide: function(v) { - if(this.disabled || this.stopListenining) return; - if(v > this.maxValue) this.setValue(this.maxValue); - }, - - onChange: function(v) { - if(this.disabled || this.stopListenining) return; - this.lastValue = v; - file = $('image').src; - if(ImageEditor.history.hasOperation(this.name)) { - var history = ImageEditor.history.getOptimizedHistory(this.name); - if(history[1] != undefined) { - file = ImageEditor.transformation.applyHistory(history); - } else { - file = history[0].fileUrl; - } - } - ImageEditor.transformation.customRequest(this.name,this.callback,file,this.lastValue,true); - }, - - callback: function() { - ImageEditor.history.addAdjust(this.name,this.lastValue,$('image').src); - }, - - setValue: function(value) { - this.stopListenining = true; - this.slider.setValue(value); - this.stopListenining = false; - }, - - getDefaultValue: function() { - return this.firstValue; - } -} -ImageEditor.Effects.AdjustBase.initialize.prototype = new ImageEditor.Effects.Base.initialize("adjustbase"); -ImageEditor.Effects.AdjustBase = { - initialize: function(name,minMax,firstValue,maxValue) { - this.name = name; - this.minMax = minMax; - this.firstValue = firstValue; - this.maxValue = maxValue; - this.setListener = ImageEditor.Effects.AdjustBase.setListener.bind(this); - this.callback = ImageEditor.Effects.AdjustBase.callback.bind(this); - this.setValue = ImageEditor.Effects.AdjustBase.setValue.bind(this); - this.getDefaultValue = ImageEditor.Effects.AdjustBase.getDefaultValue.bind(this); - this.setListener(); - this.lastValue = this.firstValue; - this.stopListenining = false; - }, - - setListener: function() { - var upperCaseName = this.name.substring(7,8).toUpperCase() + this.name.substring(8,this.name.length); - this.slider = new Control.Slider('AdjustMenu' + upperCaseName + 'SliderTrackHandler','AdjustMenu' + upperCaseName + 'SliderTrack', { - range: this.minMax, - sliderValue: this.firstValue, - onChange: ImageEditor.Effects.AdjustBase.onChange.bind(this), - onSlide: ImageEditor.Effects.AdjustBase.onSlide.bind(this) - }); - }, - - onSlide: function(v) { - if(this.disabled || this.stopListenining) return; - if(v > this.maxValue) this.setValue(this.maxValue); - }, - - onChange: function(v) { - if(this.disabled || this.stopListenining) return; - this.lastValue = v; - file = $('image').src; - if(ImageEditor.history.hasOperation(this.name)) { - var history = ImageEditor.history.getOptimizedHistory(this.name); - if(history[1] != undefined) { - file = ImageEditor.transformation.applyHistory(history); - } else { - file = history[0].fileUrl; - } - } - ImageEditor.transformation.customRequest(this.name,this.callback,file,this.lastValue,true); - }, - - callback: function() { - ImageEditor.history.addAdjust(this.name,this.lastValue,$('image').src); - }, - - setValue: function(value) { - this.stopListenining = true; - this.slider.setValue(value); - this.stopListenining = false; - }, - - getDefaultValue: function() { - return this.firstValue; - } -} -ImageEditor.Effects.AdjustBase.initialize.prototype = new ImageEditor.Effects.Base.initialize("adjustbase"); \ No newline at end of file diff --git a/javascript/ImageEditor/Effects/Base.js b/javascript/ImageEditor/Effects/Base.js deleted file mode 100644 index be4f2aec..00000000 --- a/javascript/ImageEditor/Effects/Base.js +++ /dev/null @@ -1,76 +0,0 @@ -ImageEditor.Effects = {}; -ImageEditor.Effects.Base = { - initialize: function(effectName) { - this.disabled = false; - this.perform = ImageEditor.Effects.Base.perform.bind(this); - this.setListener = ImageEditor.Effects.Base.setListener.bind(this); - this.enable = ImageEditor.Effects.Base.enable.bind(this); - this.disable = ImageEditor.Effects.Base.disable.bind(this); - this.callback = ImageEditor.Effects.Base.callback.bind(this); - this.effectName = effectName; - this.setListener(); - }, - - perform: function() { - if(!this.disabled) { - ImageEditor.transformation.customRequest(this.effectName,this.callback,undefined,undefined,true); - } - }, - - callback: function() { - ImageEditor.history.addEffect($('image').src,this.effectName); - }, - - setListener: function(eventHandler) { - var effectName = this.effectName.substring(0,1).toUpperCase() + this.effectName.substring(1,this.effectName.length); - if($(effectName + 'Button')) { - Event.observe(effectName + 'Button','click',this.perform); - } - }, - - disable: function() { - this.disabled = true; - }, - - enable: function() { - this.disabled = false; - } -} -ImageEditor.Effects = {}; -ImageEditor.Effects.Base = { - initialize: function(effectName) { - this.disabled = false; - this.perform = ImageEditor.Effects.Base.perform.bind(this); - this.setListener = ImageEditor.Effects.Base.setListener.bind(this); - this.enable = ImageEditor.Effects.Base.enable.bind(this); - this.disable = ImageEditor.Effects.Base.disable.bind(this); - this.callback = ImageEditor.Effects.Base.callback.bind(this); - this.effectName = effectName; - this.setListener(); - }, - - perform: function() { - if(!this.disabled) { - ImageEditor.transformation.customRequest(this.effectName,this.callback,undefined,undefined,true); - } - }, - - callback: function() { - ImageEditor.history.addEffect($('image').src,this.effectName); - }, - - setListener: function(eventHandler) { - var effectName = this.effectName.substring(0,1).toUpperCase() + this.effectName.substring(1,this.effectName.length); - if($(effectName + 'Button')) { - Event.observe(effectName + 'Button','click',this.perform); - } - }, - - disable: function() { - this.disabled = true; - }, - - enable: function() { - this.disabled = false; - } -} \ No newline at end of file diff --git a/javascript/ImageEditor/Environment.js b/javascript/ImageEditor/Environment.js deleted file mode 100644 index 75748188..00000000 --- a/javascript/ImageEditor/Environment.js +++ /dev/null @@ -1,9 +0,0 @@ -/** - * @author Mateusz - */ -ImageEditor.Environment = { - initialize: function (imageFile) { - ImageEditor.imageBox = new ImageEditor.ImageBox.initialize(); - ImageEditor.imageToResize = new ImageEditor.ImageToResize.initialize(imageFile); - } -} \ No newline at end of file diff --git a/javascript/ImageEditor/History.js b/javascript/ImageEditor/History.js deleted file mode 100644 index 40d6d584..00000000 --- a/javascript/ImageEditor/History.js +++ /dev/null @@ -1,362 +0,0 @@ -/** - * @author Mateusz - */ -ImageEditor.History = { - - initialize: function() { - this.history = new Array(); - this.historyPointer = -1; - this.isEnabled = true; - this.image = ImageEditor.Positioning.addBehaviour($('image')); - this.size = new Array(); - this.fakeImage = $('fakeImg'); - this.image = $('image'); - this.adjust = new Array(); - this.undo = ImageEditor.History.undo.bind(this); - this.redo = ImageEditor.History.redo.bind(this); - this.add = ImageEditor.History.add.bind(this); - this.addListeners = ImageEditor.History.addListeners.bind(this); - this.hasOperation = ImageEditor.History.hasOperation.bind(this); - this.isInHistory = ImageEditor.History.isInHistory.bind(this); - this.onImageLoad = ImageEditor.History.onImageLoad.bind(this); - this.removeLastOperation = ImageEditor.History.removeLastOperation.bind(this); - this.getOptimizedHistory = ImageEditor.History.getOptimizedHistory.bind(this); - this.addCrop = ImageEditor.History.addCrop.bind(this); - this.addResize = ImageEditor.History.addResize.bind(this); - this.addEffect = ImageEditor.History.addEffect.bind(this); - this.addAdjust = ImageEditor.History.addAdjust.bind(this); - this.enable = ImageEditor.History.enable.bind(this); - this.disable = ImageEditor.History.disable.bind(this); - this.clear = ImageEditor.History.clear.bind(this); - this.onlyResized = ImageEditor.History.onlyResized.bind(this); - this.optimizeOtherEffects = ImageEditor.History.optimizeOtherEffects.bind(this); - this.optimizeCrop = ImageEditor.History.optimizeCrop.bind(this); - this.optimizeResize = ImageEditor.History.optimizeResize.bind(this); - this.optimizeRotate = ImageEditor.History.optimizeRotate.bind(this); - this.checkSpecialOperation = ImageEditor.History.checkSpecialOperation.bind(this); - this.addListeners(); - }, - - undo: function() { - if(this.isEnabled) { - if(this.historyPointer >= 1) { - var operation = this.history[this.historyPointer].operation; - this.checkSpecialOperation('undo',this.history[this.historyPointer]); - Event.observe('image','load',this.onImageLoad); - this.historyPointer = this.historyPointer - 1; - this.image.src = this.history[this.historyPointer].fileUrl; - } else { - ImageEditor.statusMessageWrapper.statusMessage("No more undo","bad"); - } - } - }, - - redo: function() { - if(this.isEnabled) { - if(this.historyPointer < this.history.length-1) { - var operation = this.history[this.historyPointer+1].operation; - this.checkSpecialOperation('redo',this.history[this.historyPointer+1]); - Event.observe('image','load',this.onImageLoad); - this.historyPointer = this.historyPointer + 1; - this.image.src = this.history[this.historyPointer].fileUrl; - } else { - ImageEditor.statusMessageWrapper.statusMessage("No more redo","bad"); - } - } - }, - - add: function(operation,url,additionalInfo) { - var imageWidth = isNaN(parseInt($('image').style.width)) ? Element.getDimensions($('image')).width : parseInt($('image').style.width);//IE hack - var imageHeight = isNaN(parseInt($('image').style.height)) ? Element.getDimensions($('image')).height : parseInt($('image').style.height);//IE hack - //code above should be moved to Positioning.addBehaviour - if(!this.isInHistory(operation,url)) { - this.historyPointer++; - this.size[this.historyPointer] = {'width': imageWidth,'height': imageHeight}; - this.history[this.historyPointer] = {'operation': operation,'fileUrl' : url,'additionalInfo': additionalInfo}; - this.size = this.size.slice(0,this.historyPointer+1); - this.history = this.history.slice(0,this.historyPointer+1); - } - }, - - addCrop: function(url,top,left,width,height) { - this.add('crop',url,{ - 'top':top, - 'left': left, - 'width': width, - 'height': height - }); - }, - - addResize: function(url,width,height) { - this.add('resize',url,{ - 'width': width, - 'height': height - }); - }, - - addEffect: function(url,name) { - this.add(name,url); - }, - - addAdjust: function(name,value,url) { - this.add(name,url,{'value': value}); - if(this.adjust[name] == undefined) { - this.adjust[name] = {'pointer': 0,'values': Array()} - this.adjust[name].values[0] = ImageEditor.effects.getEffect(name).getDefaultValue(); - } - this.adjust[name].values[this.adjust[name].values.length] = value; - this.adjust[name].pointer++; - }, - - addListeners: function() { - this.undoListener = Event.observe('UndoButton','click',this.undo); - this.redoListener = Event.observe('RedoButton','click',this.redo); - }, - - hasOperation: function(operation,historyPointer) { - if(historyPointer == undefined) historyPointer = this.history.length-1; - for(i=historyPointer;i>=0;i--) { - if(this.history[i].operation == operation) { - return true; - } - } - return false; - }, - - getOptimizedHistory: function(without) { - var history = this.history.slice(0,this.historyPointer+1); - var result = {}; - var historyPointer = 1; - result[0] = {fileUrl : history[0].fileUrl}; - var resize = this.optimizeResize(history,this.size); - var rotate = this.optimizeRotate(history); - var crop = this.optimizeCrop(history,this.size); - var other = this.optimizeOtherEffects(history,without); - if(rotate != undefined) { - for(var i =0;i=0;i--) { - if(this.history[i].operation != 'resize') { - return false; - } - } - return true; - }, - - optimizeResize: function(history,size) { - var scallingXFactor = 1;var scallingYFactor = 1; - var initWidth = size[0].width;var initHeight = size[0].height; - for(var i=0;i 0) this.adjust[historyEntry.operation].pointer--; - } else { - this.adjust[historyEntry.operation].pointer++; - } - ImageEditor.effects.getEffect(historyEntry.operation).setValue(this.adjust[historyEntry.operation].values[this.adjust[historyEntry.operation].pointer]); - } - } -}; \ No newline at end of file diff --git a/javascript/ImageEditor/Image.js b/javascript/ImageEditor/Image.js deleted file mode 100644 index 058afed9..00000000 --- a/javascript/ImageEditor/Image.js +++ /dev/null @@ -1,74 +0,0 @@ -/** - * @author Mateusz - */ -ImageEditor.ImageToResize = { - initialize: function(imageFile) { - Element.hide($('image')); - this.imageToResize = $('image'); - this.imageToResize.src = imageFile; - this.reportSize = ImageEditor.ImageToResize.reportSize.bind(this); - this.onImageLoad = ImageEditor.ImageToResize.onImageLoad.bind(this); - this.resizeOnFirstLoad = ImageEditor.ImageToResize.resizeOnFirstLoad.bind(this); - Event.observe(this.imageToResize,'load',this.onImageLoad); - this.firstResize = {}; - }, - - reportSize: function(width,height) { - if(width != null && height != null) { - $('ImageWidth').innerHTML = width + "px"; - $('ImageHeight').innerHTML = height + "px"; - } else { - $('ImageWidth').innerHTML = this.imageToResize.width + "px"; - $('ImageHeight').innerHTML = this.imageToResize.height + "px"; - } - }, - - onImageLoad: function(event) { - if(this.imageToResize.width != 0 && this.imageToResize.height != 0) { - $('imageContainer').style.backgroundImage = 'url("' + $('image').src + '")'; - ImageEditor.imageBox.hideIndicator(); - Element.show($('imageContainer'),$('image')); - if(ImageEditor.resize.imageContainerResize.originalHeight == 0 && ImageEditor.resize.imageContainerResize.originalWidth == 0) { - ImageEditor.history.add('initialize',$('image').src); - this.resizeOnFirstLoad(); - ImageEditor.imageBox.center(); - } - ImageEditor.resize.imageContainerResize.originalWidth = this.imageToResize.width; - ImageEditor.resize.imageContainerResize.originalHeight = this.imageToResize.height; - ImageEditor.resize.imageContainerResize.placeClickBox(); - ImageEditor.crop.onImageLoadCallback(); - } - this.reportSize(); - }, - - resizeOnFirstLoad: function() { - var windowWidth = Element.getDimensions($('Main')).width; - var windowHeight = Element.getDimensions($('Main')).height - 100; - var imageWidth = Element.getDimensions($('image')).width; - var imageHeight = Element.getDimensions($('image')).height; - if(imageWidth > windowWidth - 40 || imageHeight > windowHeight - 40) { - ImageEditor.history.clear(); - Element.hide($('imageContainer'),$('image')); - var ratio = imageWidth / imageHeight; - $('loadingIndicatorContainer2').style.left = windowWidth/2 + 'px'; - $('loadingIndicatorContainer2').style.top = windowHeight/2 + 100 + 'px'; - while(imageWidth > windowWidth - 40 || imageHeight > windowHeight - 40) { - imageWidth--; - imageHeight = imageWidth * (1/ratio); - } - this.reportSize(0,0); - ImageEditor.resize.imageContainerResize.setVisible(false); - ImageEditor.transformation.resize(imageWidth,imageHeight,ImageEditor.ImageToResize.resizeOnFirstLoadCallBack.bind(this),false); - this.firstResize.width = imageWidth; - this.firstResize.height = imageHeight; - } - }, - - resizeOnFirstLoadCallBack: function() { - ImageEditor.history.addResize($('image').src,this.firstResize.width,this.firstResize.height); - Element.hide($('loadingIndicatorContainer2')); - ImageEditor.resize.imageContainerResize.setVisible(true); - ImageEditor.resize.imageContainerResize.placeClickBox(); - ImageEditor.imageBox.center(); - } -}; diff --git a/javascript/ImageEditor/ImageBox.js b/javascript/ImageEditor/ImageBox.js deleted file mode 100644 index b9e421dc..00000000 --- a/javascript/ImageEditor/ImageBox.js +++ /dev/null @@ -1,52 +0,0 @@ -/** - * @author Mateusz - */ -ImageEditor.ImageBox = { - - initialize: function() { - this.indicatorWidth = 32; - this.indicatorHeight = 32; - this.showIndicator = ImageEditor.ImageBox.showIndicator.bind(this); - this.hideIndicator = ImageEditor.ImageBox.hideIndicator.bind(this); - this.reCenterIndicator = ImageEditor.ImageBox.reCenterIndicator.bind(this); - this.centerIndicator = ImageEditor.ImageBox.centerIndicator.bind(this); - this.center = ImageEditor.ImageBox.center.bind(this); - this.imageContainer = ImageEditor.Positioning.addBehaviour($('imageContainer')); - Element.hide(this.imageContainer); - this.indicator = ImageEditor.Positioning.addBehaviour($('loadingIndicatorContainer')); - this.indicatorImage = ImageEditor.Positioning.addBehaviour($('loadingIndicator')); - ImageEditor.Positioning.addBehaviour($('Main')); - }, - - showIndicator: function(container) { - Element.show(this.indicator,this.indicatorImage); - if(container == null) container = this.imageContainer; - this.centerIndicator(container); - }, - - hideIndicator: function() { - Element.hide(this.indicator,this.indicatorImage); - }, - - centerIndicator: function(container) { - var top = container.getTop(); - var left = container.getLeft(); - var width = container.getWidth(); - var height = container.getHeight(); - var parentTop = container.getParentTop(); - var parentLeft = container.getParentLeft(); - this.indicator.style.left = width/2 - this.indicatorWidth/2 + "px"; - this.indicator.style.top = height/2 - this.indicatorHeight/2 + "px"; - }, - - reCenterIndicator: function() { - if(Element.visible(this.indicator)) { - this.centerIndicator(this.imageContainer); - } - }, - - center: function() { - this.imageContainer.style.left = this.imageContainer.getParentWidth()/2 - this.imageContainer.getWidth()/2 + 'px'; - this.imageContainer.style.top = this.imageContainer.getParentHeight()/2 - this.imageContainer.getHeight()/2 + 'px'; - } -}; diff --git a/javascript/ImageEditor/ImageEditor.js b/javascript/ImageEditor/ImageEditor.js deleted file mode 100644 index bebb7035..00000000 --- a/javascript/ImageEditor/ImageEditor.js +++ /dev/null @@ -1,57 +0,0 @@ -/** - * @author Mateusz - */ -ImageEditor.Main = { - initialize: function(imageFile) { - imageFile += '1234'; - ImageEditor.crop = null; - ImageEditor.history = new ImageEditor.History.initialize(); - ImageEditor.environment = new ImageEditor.Environment.initialize(imageFile); - ImageEditor.transformation = new ImageEditor.Transformation.initialize(); - ImageEditor.resize = new ImageEditor.Resize.initialize($('imageContainer')); - ImageEditor.effects = new ImageEditor.Effects.Main.initialize(); - ImageEditor.crop = new ImageEditor.Crop.initialize(); - ImageEditor.documentBody = new ImageEditor.DocumentBody.initialize(); - ImageEditor.adjust = new ImageEditor.Adjust.initialize(); - this.originalImageFile = imageFile; - this.tottalyOriginalImageFile = imageFile; - this.onSaveClick = ImageEditor.Main.onSaveClick.bind(this); - this.onCloseClick = ImageEditor.Main.onCloseClick.bind(this); - this.enableFunctionality = ImageEditor.Main.enableFunctionality.bind(this); - this.disableFunctionality = ImageEditor.Main.disableFunctionality.bind(this); - Event.observe($('SaveButton'),'click',this.onSaveClick); - Event.observe($('ExitButton'),'click',this.onCloseClick); - Element.hide($('CurrentAction')); - }, - - onSaveClick: function() { - if(this.tottalyOriginalImageFile != $('image').src) { - ImageEditor.transformation.save(this.tottalyOriginalImageFile,$('image').src,this.onCloseClick); - } else { - this.onCloseClick(); - } - }, - - onCloseClick: function() { - window.parent.imageEditorClosed(); - ImageEditor.transformation.close(ImageEditor.Main.onCloseCallback.bind(this)); - }, - - onCloseCallback: function() { - Element.hide(window.frameElement); - }, - - enableFunctionality: function() { - ImageEditor.effects.enable(); - ImageEditor.crop.enable(); - ImageEditor.resize.enable(); - ImageEditor.history.enable(); - }, - - disableFunctionality: function() { - ImageEditor.effects.disable(); - ImageEditor.crop.disable(); - ImageEditor.resize.disable(); - ImageEditor.history.disable(); - } -} \ No newline at end of file diff --git a/javascript/ImageEditor/ImageHistory.js b/javascript/ImageEditor/ImageHistory.js deleted file mode 100644 index 430d9270..00000000 --- a/javascript/ImageEditor/ImageHistory.js +++ /dev/null @@ -1,264 +0,0 @@ -/** - * @author Mateusz - */ -ImageEditor.ImageHistory = { - - initialize: function() { - this.history = new Array(); - this.historyPointer = -1; - this.modifiedOriginalImage = false; - this.isEnabled = true; - this.image = ImageEditor.Positioning.addBehaviour($('image')); - this.size = new Array(); - this.fakeImage = $('fakeImg'); - this.image = $('image'); - this.undo = ImageEditor.ImageHistory.undo.bind(this); - this.redo = ImageEditor.ImageHistory.redo.bind(this); - this.add = ImageEditor.ImageHistory.add.bind(this); - this.addListeners = ImageEditor.ImageHistory.addListeners.bind(this); - this.operationMade = ImageEditor.ImageHistory.operationMade.bind(this); - this.isInHistory = ImageEditor.ImageHistory.isInHistory.bind(this); - this.onImageLoad = ImageEditor.ImageHistory.onImageLoad.bind(this); - this.removeLastOperation = ImageEditor.ImageHistory.removeLastOperation.bind(this); - - this.enable = ImageEditor.ImageHistory.enable.bind(this); - this.disable = ImageEditor.ImageHistory.disable.bind(this); - this.clear = ImageEditor.ImageHistory.clear.bind(this); - this.addListeners(); - }, - - undo: function() { - if(this.historyPointer >= 1) { - var operation = this.history[this.historyPointer].operation; - if(operation == 'rotate' || operation == 'crop') { - if(this.operationMade(this.historyPointer-1,'rotate') || this.operationMade(this.historyPointer-1,'crop')) - this.modifiedOriginalImage = true; else this.modifiedOriginalImage = false; - } - Event.observe('image','load',this.onImageLoad); - this.historyPointer = this.historyPointer - 1; - this.image.src = this.history[this.historyPointer].fileUrl; - } else { - ImageEditor.statusMessageWrapper.statusMessage("No more undo","bad"); - } - }, - - redo: function() { - if(this.historyPointer < this.history.length-1) { - var operation = this.history[this.historyPointer+1].operation; - if(operation == 'rotate' || operation == 'crop') this.modifiedOriginalImage = true; - Event.observe('image','load',this.onImageLoad); - this.historyPointer = this.historyPointer + 1; - this.image.src = this.history[this.historyPointer].fileUrl; - } else { - ImageEditor.statusMessageWrapper.statusMessage("No more redo","bad"); - } - }, - - add: function(operation,url) { - var imageWidth = isNaN(parseInt($('image').style.width)) ? Element.getDimensions($('image')).width : parseInt($('image').style.width);//IE hack - var imageHeight = isNaN(parseInt($('image').style.height)) ? Element.getDimensions($('image')).height : parseInt($('image').style.height);//IE hack - //code above should be moved to Positioning.addBehaviour - if(!this.isInHistory(operation,url)) { - this.historyPointer++; - this.size[this.historyPointer] = {'width': imageWidth,'height': imageHeight}; - this.history[this.historyPointer] = {'operation': operation,'fileUrl' : url}; - this.size = this.size.slice(0,this.historyPointer+1); - this.history = this.history.slice(0,this.historyPointer+1); - if(operation == 'rotate' || operation == 'crop') this.modifiedOriginalImage = true; - } - }, - - addListeners: function() { - this.undoListener = Event.observe('UndoButton','click',this.undo); - this.redoListener = Event.observe('RedoButton','click',this.redo); - }, - - operationMade: function(historyPointer,operation) { - for(i=historyPointer;i>=0;i--) { - if(this.history[i].operation == operation) { - return true; - } - } - return false; - }, - - enable: function() { - if(!this.isEnabled) { - this.addListeners(); - this.isEnabled = true; - } - }, - - disable: function() { - if(this.isEnabled) { - Event.stopObserving($('UndoButton'),'click', this.undo); - Event.stopObserving($('RedoButton'),'click', this.redo); - this.isEnabled = false; - } - }, - - clear: function() { - this.history = new Array(); - this.historyPointer = -1; - this.size = new Array(); - }, - - removeLastOperation: function() { - this.history.pop(); - this.size.pop(); - this.historyPointer--; - }, - - isInHistory: function(operation,url) { - if(operation == 'initialize' && this.historyPointer != -1) return true; - for(var k=0;k= 1) { - var operation = this.history[this.historyPointer].operation; - if(operation == 'rotate' || operation == 'crop') { - if(this.operationMade(this.historyPointer-1,'rotate') || this.operationMade(this.historyPointer-1,'crop')) - this.modifiedOriginalImage = true; else this.modifiedOriginalImage = false; - } - Event.observe('image','load',this.onImageLoad); - this.historyPointer = this.historyPointer - 1; - this.image.src = this.history[this.historyPointer].fileUrl; - } else { - ImageEditor.statusMessageWrapper.statusMessage("No more undo","bad"); - } - }, - - redo: function() { - if(this.historyPointer < this.history.length-1) { - var operation = this.history[this.historyPointer+1].operation; - if(operation == 'rotate' || operation == 'crop') this.modifiedOriginalImage = true; - Event.observe('image','load',this.onImageLoad); - this.historyPointer = this.historyPointer + 1; - this.image.src = this.history[this.historyPointer].fileUrl; - } else { - ImageEditor.statusMessageWrapper.statusMessage("No more redo","bad"); - } - }, - - add: function(operation,url) { - var imageWidth = isNaN(parseInt($('image').style.width)) ? Element.getDimensions($('image')).width : parseInt($('image').style.width);//IE hack - var imageHeight = isNaN(parseInt($('image').style.height)) ? Element.getDimensions($('image')).height : parseInt($('image').style.height);//IE hack - //code above should be moved to Positioning.addBehaviour - if(!this.isInHistory(operation,url)) { - this.historyPointer++; - this.size[this.historyPointer] = {'width': imageWidth,'height': imageHeight}; - this.history[this.historyPointer] = {'operation': operation,'fileUrl' : url}; - this.size = this.size.slice(0,this.historyPointer+1); - this.history = this.history.slice(0,this.historyPointer+1); - if(operation == 'rotate' || operation == 'crop') this.modifiedOriginalImage = true; - } - }, - - addListeners: function() { - this.undoListener = Event.observe('UndoButton','click',this.undo); - this.redoListener = Event.observe('RedoButton','click',this.redo); - }, - - operationMade: function(historyPointer,operation) { - for(i=historyPointer;i>=0;i--) { - if(this.history[i].operation == operation) { - return true; - } - } - return false; - }, - - enable: function() { - if(!this.isEnabled) { - this.addListeners(); - this.isEnabled = true; - } - }, - - disable: function() { - if(this.isEnabled) { - Event.stopObserving($('UndoButton'),'click', this.undo); - Event.stopObserving($('RedoButton'),'click', this.redo); - this.isEnabled = false; - } - }, - - clear: function() { - this.history = new Array(); - this.historyPointer = -1; - this.size = new Array(); - }, - - removeLastOperation: function() { - this.history.pop(); - this.size.pop(); - this.historyPointer--; - }, - - isInHistory: function(operation,url) { - if(operation == 'initialize' && this.historyPointer != -1) return true; - for(var k=0;k