]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Fixes #3914. Moved avatar cropping to ui.js.
authorBrett Profitt <brett.profitt@gmail.com>
Sun, 23 Oct 2011 18:23:58 +0000 (11:23 -0700)
committerBrett Profitt <brett.profitt@gmail.com>
Sun, 23 Oct 2011 18:23:58 +0000 (11:23 -0700)
js/lib/ui.js
views/default/css/elements/misc.php
views/default/forms/avatar/crop.php

index 57378a4d63fa37127505c2651d45f502bad30a08..8cee500d0159a173800bc523baf4404565ba99b0 100644 (file)
@@ -1,6 +1,7 @@
 elgg.provide('elgg.ui');
 
 elgg.ui.init = function () {
+       // add user hover menus
        elgg.ui.initHoverMenu();
 
        //if the user clicks a system message, make it disappear
@@ -24,6 +25,14 @@ elgg.ui.init = function () {
        if ($('.elgg-input-date').length) {
                elgg.ui.initDatePicker();
        }
+
+       // avatar cropper
+       $('#user-avatar-cropper').imgAreaSelect({
+               selectionOpacity: 0,
+               aspectRatio: '1:1',
+               onSelectEnd: elgg.ui.avatarSelectChange,
+               onSelectChange: elgg.ui.avatarPreview
+       });
 }
 
 /**
@@ -277,6 +286,34 @@ elgg.ui.initDatePicker = function() {
        });
 }
 
+// Avatar cropping
+
+// display a preview of the users cropped section
+elgg.ui.avatarPreview = function(img, selection) {
+       // catch for the first click on the image
+       if (selection.width == 0 || selection.height == 0) {
+               return;
+       }
+
+       var origWidth = $("#user-avatar-cropper").width();
+       var origHeight = $("#user-avatar-cropper").height();
+       var scaleX = 100 / selection.width;
+       var scaleY = 100 / selection.height;
+       $('#user-avatar-preview > img').css({
+               width: Math.round(scaleX * origWidth) + 'px',
+               height: Math.round(scaleY * origHeight) + 'px',
+               marginLeft: '-' + Math.round(scaleX * selection.x1) + 'px',
+               marginTop: '-' + Math.round(scaleY * selection.y1) + 'px'
+       });
+}
+
+// populate the form with the correct coordinates once a user has cropped their image
+elgg.ui.avatarSelectChange = function(img, selection) {
+       $('input[name=x1]').val(selection.x1);
+       $('input[name=x2]').val(selection.x2);
+       $('input[name=y1]').val(selection.y1);
+       $('input[name=y2]').val(selection.y2);
+}
 
 elgg.register_hook_handler('init', 'system', elgg.ui.init);
 elgg.register_hook_handler('getOptions', 'ui.popup', elgg.ui.LoginHandler);
\ No newline at end of file
index ebac2b91fbeff90e34bc02d3bf2183d1e55be7f9..d9622d34a8c4c87e037b86351b1a3fac6d8d5b9c 100644 (file)
@@ -18,7 +18,7 @@
 #avatar-croppingtool {
        border-top: 1px solid #ccc;
 }
-#user-avatar {
+#user-avatar-cropper {
        float: left;
 }
 #user-avatar-preview {
index 1f39ff73ced9db2aad7ba37a36955bb192a7ac68..dd1640b1f027bc0cebe77ca92c497a104d4bc46d 100644 (file)
@@ -12,7 +12,10 @@ $master_image = $vars['entity']->getIconUrl('master');
 
 ?>
 <div class="clearfix">
-       <img id="user-avatar" class="mrl" src="<?php echo $master_image; ?>" alt="<?php echo elgg_echo('avatar'); ?>" />
+       <img id="user-avatar-cropper" class="mrl" src="<?php echo $master_image; ?>" alt="<?php echo elgg_echo('avatar'); ?>" />
+       <div id="user-avatar-preview-title"><label><?php echo elgg_echo('avatar:preview'); ?></label></div>
+       <div id="user-avatar-preview"><img src="<?php echo $master_image; ?>" /></div>
+
 </div>
 <div class="elgg-foot">
 <?php
@@ -27,47 +30,3 @@ echo elgg_view('input/submit', array('value' => elgg_echo('avatar:create')));
 
 ?>
 </div>
-<!-- grab the required js for icon cropping -->
-<?php //@todo JS 1.8: no ?>
-<script type="text/javascript">
-
-       // display a preview of the users cropped section
-       function preview(img, selection) {
-               // catch for the first click on the image
-               if (selection.width == 0 || selection.height == 0) {
-                       return;
-               }
-
-               var origWidth = $("#user-avatar").width(); //get the width of the users master photo
-               var origHeight = $("#user-avatar").height(); //get the height of the users master photo
-               var scaleX = 100 / selection.width;
-               var scaleY = 100 / selection.height;
-               $('#user-avatar-preview > img').css({
-                       width: Math.round(scaleX * origWidth) + 'px',
-                       height: Math.round(scaleY * origHeight) + 'px',
-                       marginLeft: '-' + Math.round(scaleX * selection.x1) + 'px',
-                       marginTop: '-' + Math.round(scaleY * selection.y1) + 'px'
-               });
-       }
-
-       function selectChange(img, selection) {
-               // populate the form with the correct coordinates once a user has cropped their image
-               $('input[name=x1]').val(selection.x1);
-               $('input[name=x2]').val(selection.x2);
-               $('input[name=y1]').val(selection.y1);
-               $('input[name=y2]').val(selection.y2);
-       }
-
-       $(document).ready(function() {
-               $('<div id="user-avatar-preview"><img src="<?php echo $master_image; ?>" /></div>').insertAfter($('#user-avatar'));
-               $('<div id="user-avatar-preview-title"><label><?php echo elgg_echo('avatar:preview'); ?></label></div>').insertBefore($('#user-avatar-preview'));
-
-               // init the cropping
-               $('#user-avatar').imgAreaSelect({
-                       selectionOpacity: 0,
-                       aspectRatio: '1:1',
-                       onSelectEnd: selectChange,
-                       onSelectChange: preview
-               });
-       });
-</script>