Code Monkey home page Code Monkey logo

pictags's Introduction

jQeury picTags

###為圖片加上標示用的標籤 (像是 Facebook 的照片)###

Demo for basic

Demo for edit

Edited from https://github.com/timseverien/taggd

Here will only show what is add, please go to taggd to see other original usages.

這裡只說明新增的功能,其餘用法請前往 taggd 檢視。

1. Add individual position for every record

Look at the position property, you can set individual position for every record. If not set, it will follow the rules of options. There are four choices : top, bottom, left, right.

看到新增的 position 屬性,現在可以為個別資料設定位置,如果沒有設定,則是依照 options 中的原始設定。有四個選項可以設定: top, bottom, left, right 。

	var options = {
        // Aligning the text popups
        align: {
            x: 'center', // left, center or right
            y: 'top' // top, center or bottom
        },
        // The (relative) offset of the popups in pixels
        offset: {
            left: 0, // horizontal offset
            top: 20 // vertical offset
        }
	};

	var data = [
		{
            x: 0.35,
            y: 0.4,
            text: '狗狗汪汪叫' 
            ,attributes: {
                id: 'dog', // id is necessary
            },
            position: 'left' // top, bottom, left, right
        },
		{
            x: 0.8,
            y: 0.2,
            text: '沒有指定 position, 則是依照 options 中的規則' 
            ,attributes: {
                id: 'nothing', // id is necessary
            },
            
            // If not set, it will follow the rules of options.
            //position: 'right' // top, bottom, left, right
        },
	];
    

2. ID attribute is necessary

It is for update data usage.

為了更新資料需求, ID 屬性一定要填寫。

3. Update data

Add a method updateInfo for update data.

新增一個更新資料的方法 updateInfo

	var options = {
    	edit: true,
     align: {},
     offset: {},
		updateInfo : function(save_data){
    		alert('id : ' + save_data.id +'\ntitle : ' + save_data.title +'\nx : ' + save_data.x +'\ny : ' + save_data.y);
    		/*
    		// here you will get id, title, x, y
    		// new record's id will be "new"
    		// you should give it a unique id like below

            var info = 'id='+ save_data.id 
                        + '&title=' + save_data.title
                        + '&x=' + save_data.x
                        + '&y=' + save_data.y;

            $.post( '/whereYouHandleIt', info, function( return_data ) {

                // update the new record's id
                $.each(picTags.data, function(i, v) {
                    if (v.attributes.id == 'new') {
                        if (save_data.title == v.text) {
                            v.attributes = {id:return_data.info.id};
                        }
                    }
                });

                // remove all records not be saved
                picTags.data = $.grep(picTags.data, function(v) {
    			    return (v.attributes.id != 'new');
				});
				picTags.addDOM();

            }, "json");
    		*/
		}
	};

4. Delete data manually

I remove the delete button and it have to delete manually.

// 刪除了 delete 按鈕,現在需要手動刪除,刪除的方式如下。

    // delete a record manually
    function delete_record(id) {
        picTags.data = $.grep(picTags.data, function(v) {
    	    return (v.attributes.id != id);
		});
		picTags.addDOM();
    }

pictags's People

Contributors

itisjoe avatar

Stargazers

Ymow Wu avatar Lira LIU avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.